wms_getcapabilities 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/examples/test.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "wms_getcapabilities"
2
+ require "nokogiri"
3
+
4
+ geoserver = WmsGetcapabilities::Geoserver.new("http://geo.devel.dotgee.fr/geoserver")
5
+ geoserver.get_capabilities
6
+ puts geoserver.layers.inspect
@@ -1,5 +1,9 @@
1
+ require "open-uri"
1
2
  require "wms_getcapabilities/version"
3
+ require "wms_getcapabilities/layer"
4
+ require "wms_getcapabilities/parser"
5
+ require "wms_getcapabilities/geoserver"
2
6
 
3
7
  module WmsGetcapabilities
4
- # Your code goes here...
8
+
5
9
  end
@@ -0,0 +1,24 @@
1
+ module WmsGetcapabilities
2
+
3
+ class Geoserver
4
+
5
+ def initialize(url)
6
+ @root_url = url
7
+ end
8
+
9
+ def get_capabilities
10
+ service = "WMS"
11
+ request = "GetCapabilities"
12
+
13
+ response = open("#{@root_url}/wms?SERVICE=#{service}&request=#{request}")
14
+ @parser = Parser.new(response)
15
+ end
16
+
17
+ def layers
18
+ layers = @parser.get_layers
19
+ layers
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,12 @@
1
+ module WmsGetcapabilities
2
+ class Layer
3
+
4
+ def initialize(name, title, crs, bbox)
5
+ @name = name
6
+ @title = title
7
+ @crs = crs
8
+ @bbox = bbox
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,34 @@
1
+ module WmsGetcapabilities
2
+
3
+ class Parser
4
+
5
+ def initialize(xml)
6
+ @doc = ::Nokogiri::XML(xml)
7
+ end
8
+
9
+ def search(xpath)
10
+ @doc.xpath(xpath)
11
+ end
12
+
13
+ def custom_search(doc, xpath)
14
+ doc.xpath(xpath)
15
+ end
16
+
17
+ def get_layers
18
+ layers = []
19
+ nodes = self.search("//xmlns:Layer")
20
+ nodes.each do |layer|
21
+ children = layer.children
22
+ name = children.at("Name").text
23
+ title = children.at("Title").text
24
+ crs = children.at("CRS").text
25
+ box = children.search("BoundingBox").last
26
+ bbox = [box.attr("minx"), box.attr("miny"), box.attr("maxx"), box.attr("maxy")]
27
+ l = Layer.new(name, title, crs, bbox)
28
+ layers << l
29
+ end
30
+ layers
31
+ end
32
+
33
+ end
34
+ end
@@ -1,3 +1,3 @@
1
1
  module WmsGetcapabilities
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -17,4 +17,6 @@ Gem::Specification.new do |s|
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
+
21
+ s.add_dependency("nokogiri")
20
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wms_getcapabilities
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,19 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-16 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-10-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: &2168822400 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2168822400
14
25
  description: Interface between ruby and Geoserver WMS GetCapabilities
15
26
  email:
16
27
  - jchapron@dotgee.fr
@@ -22,7 +33,11 @@ files:
22
33
  - Gemfile
23
34
  - README.md
24
35
  - Rakefile
36
+ - examples/test.rb
25
37
  - lib/wms_getcapabilities.rb
38
+ - lib/wms_getcapabilities/geoserver.rb
39
+ - lib/wms_getcapabilities/layer.rb
40
+ - lib/wms_getcapabilities/parser.rb
26
41
  - lib/wms_getcapabilities/version.rb
27
42
  - wms_getcapabilities.gemspec
28
43
  homepage: https://github.com/imperYaL/wms_getcapabilities