geospatial-kml 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a8acf89241d682ea66f5490e33b62d55573cdb82
4
- data.tar.gz: 4dbfca3ded430a6cd00d23b0395321e7e86a76ba
2
+ SHA256:
3
+ metadata.gz: aa1bf3132bd9b7cf265e59c85e2d26e6efad07f238a5d3396627d91eb09b2e43
4
+ data.tar.gz: 59afaf2f3e3105be1b7ed5abc75167328a2d06f48ed16c9145054e93348ccf8c
5
5
  SHA512:
6
- metadata.gz: 76e4edd14008f44a5654e9fa6dab4d110bf5f27c397c7dc29012ce4f8c64f5ea6f09ef156a45e6ebc7f8477afe4fd1e28f194990fe672e97c9eee0fbfaad2f59
7
- data.tar.gz: 90599a422b5dcfe6f23f38450c3070626640dc80c3be64d9ad6f8835d48101b64b555293e3212d888bb147770555b858b35b486a06f8201ad94c662fcc133b87
6
+ metadata.gz: b4035d21afe6ad6223b951aa5f2f3d057c458ddb71dd8b78765ece25aa5b31952ed84088773799a296aa91557fc428d60864a87938253e903be43a1d6ed49da4
7
+ data.tar.gz: 0b23e4bb964f04af39831c617cf310cb07f9173af9e2571ae80decfacdc227a4ce4310d17ff9d3346b6e4fadcb07a7a4523f61933be9fde38601b749928141be
@@ -0,0 +1,51 @@
1
+ # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'nokogiri'
22
+ require 'geospatial/polygon'
23
+
24
+ module Geospatial
25
+ module KML
26
+ class Placemark
27
+ def initialize(node)
28
+ @node = node
29
+ end
30
+
31
+ def name
32
+ @node.css("name").text.strip
33
+ end
34
+
35
+ def polygons
36
+ return to_enum(:polygons) unless block_given?
37
+
38
+ @node.css("Polygon").collect do |polygon_node|
39
+ coordinates_node = polygon_node.css("coordinates").first
40
+
41
+ text = coordinates_node.text.strip
42
+ coordinates = text.split(/\s+/).collect do |coordinate|
43
+ Vector.elements(coordinate.split(',').collect(&:to_f).first(2))
44
+ end
45
+
46
+ yield Polygon.new(coordinates)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -21,6 +21,8 @@
21
21
  require 'nokogiri'
22
22
  require 'geospatial/polygon'
23
23
 
24
+ require_relative 'placemark'
25
+
24
26
  module Geospatial
25
27
  module KML
26
28
  class Reader
@@ -36,7 +38,17 @@ module Geospatial
36
38
 
37
39
  attr :doc
38
40
 
41
+ def placemarks
42
+ return to_enum(:placemarks) unless block_given?
43
+
44
+ @doc.css("Placemark").collect do |node|
45
+ yield Placemark.new(node)
46
+ end
47
+ end
48
+
39
49
  def polygons
50
+ return to_enum(:polygons) unless block_given?
51
+
40
52
  @doc.css("Polygon").collect do |polygon_node|
41
53
  coordinates_node = polygon_node.css("coordinates").first
42
54
 
@@ -45,7 +57,7 @@ module Geospatial
45
57
  Vector.elements(coordinate.split(',').collect(&:to_f).first(2))
46
58
  end
47
59
 
48
- Polygon.new(coordinates)
60
+ yield Polygon.new(coordinates)
49
61
  end
50
62
  end
51
63
  end
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Geospatial
22
22
  module KML
23
- VERSION = "0.2.0"
23
+ VERSION = "0.3.0"
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geospatial-kml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-04 00:00:00.000000000 Z
11
+ date: 2018-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: geospatial
@@ -96,6 +96,7 @@ files:
96
96
  - Rakefile
97
97
  - geospatial-kml.gemspec
98
98
  - lib/geospatial/kml.rb
99
+ - lib/geospatial/kml/placemark.rb
99
100
  - lib/geospatial/kml/reader.rb
100
101
  - lib/geospatial/kml/version.rb
101
102
  homepage: https://github.com/ioquatix/geospatial-kml
@@ -117,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
118
  version: '0'
118
119
  requirements: []
119
120
  rubyforge_project:
120
- rubygems_version: 2.6.10
121
+ rubygems_version: 2.7.7
121
122
  signing_key:
122
123
  specification_version: 4
123
124
  summary: Read geo data from keyhole markup language files.