nofxx-georuby 1.7.3 → 1.9.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/README.rdoc +184 -0
- data/Rakefile +5 -4
- data/VERSION +1 -1
- data/lib/geo_ruby.rb +1 -0
- data/lib/geo_ruby/simple_features/envelope.rb +1 -1
- data/lib/geo_ruby/simple_features/ewkb_parser.rb +16 -17
- data/lib/geo_ruby/simple_features/geojson_parser.rb +132 -0
- data/lib/geo_ruby/simple_features/geometry.rb +8 -0
- data/lib/geo_ruby/simple_features/geometry_collection.rb +8 -0
- data/lib/geo_ruby/simple_features/line_string.rb +12 -0
- data/lib/geo_ruby/simple_features/multi_line_string.rb +12 -0
- data/lib/geo_ruby/simple_features/multi_point.rb +12 -0
- data/lib/geo_ruby/simple_features/multi_polygon.rb +12 -0
- data/lib/geo_ruby/simple_features/point.rb +17 -0
- data/lib/geo_ruby/simple_features/polygon.rb +12 -0
- data/marcusmateus-georuby.gemspec +136 -0
- data/spec/data/geojson/feature_collection.json +34 -0
- data/spec/geo_ruby/gpx4r/gpx_spec.rb +10 -10
- data/spec/geo_ruby/shp4r/shp_spec.rb +4 -4
- data/spec/geo_ruby/simple_features/envelope_spec.rb +3 -1
- data/spec/geo_ruby/simple_features/geojson_parser_spec.rb +147 -0
- data/spec/geo_ruby/simple_features/geometry_spec.rb +1 -1
- data/spec/geo_ruby/simple_features/point_spec.rb +27 -27
- data/spec/spec_helper.rb +13 -6
- metadata +51 -31
- data/.gitignore +0 -6
- data/README.txt +0 -118
- data/nofxx-georuby.gemspec +0 -132
@@ -32,7 +32,19 @@ module GeoRuby
|
|
32
32
|
def to_line_string(join = true)
|
33
33
|
LineString.from_points(points)
|
34
34
|
end
|
35
|
+
|
36
|
+
def to_coordinates
|
37
|
+
geometries.map{|ls| ls.to_coordinates}
|
38
|
+
end
|
35
39
|
|
40
|
+
# simple geojson representation
|
41
|
+
# TODO add CRS / SRID support?
|
42
|
+
def to_json(options = {})
|
43
|
+
{:type => 'MultiLineString',
|
44
|
+
:coordinates => self.to_coordinates}.to_json(options)
|
45
|
+
end
|
46
|
+
alias :as_geojson :to_json
|
47
|
+
|
36
48
|
#Creates a new multi line string from an array of line strings
|
37
49
|
def self.from_line_strings(line_strings,srid=DEFAULT_SRID,with_z=false,with_m=false)
|
38
50
|
multi_line_string = new(srid,with_z,with_m)
|
@@ -27,6 +27,18 @@ module GeoRuby
|
|
27
27
|
"MULTIPOINT"
|
28
28
|
end
|
29
29
|
|
30
|
+
def to_coordinates
|
31
|
+
points.map{|p| p.to_coordinates }
|
32
|
+
end
|
33
|
+
|
34
|
+
# simple geojson representation
|
35
|
+
# TODO add CRS / SRID support?
|
36
|
+
def to_json(options = {})
|
37
|
+
{:type => 'MultiPoint',
|
38
|
+
:coordinates => self.to_coordinates}.to_json(options)
|
39
|
+
end
|
40
|
+
alias :as_geojson :to_json
|
41
|
+
|
30
42
|
#Creates a new multi point from an array of points
|
31
43
|
def self.from_points(points,srid= DEFAULT_SRID,with_z=false,with_m=false)
|
32
44
|
multi_point= new(srid,with_z,with_m)
|
@@ -31,6 +31,18 @@ module GeoRuby
|
|
31
31
|
"MULTIPOLYGON"
|
32
32
|
end
|
33
33
|
|
34
|
+
def to_coordinates
|
35
|
+
geometries.map{|polygon| polygon.to_coordinates}
|
36
|
+
end
|
37
|
+
|
38
|
+
# simple geojson representation
|
39
|
+
# TODO add CRS / SRID support?
|
40
|
+
def to_json(options = {})
|
41
|
+
{:type => 'MultiPolygon',
|
42
|
+
:coordinates => self.to_coordinates}.to_json(options)
|
43
|
+
end
|
44
|
+
alias :as_geojson :to_json
|
45
|
+
|
34
46
|
#Creates a multi polygon from an array of polygons
|
35
47
|
def self.from_polygons(polygons,srid=DEFAULT_SRID,with_z=false,with_m=false)
|
36
48
|
multi_polygon = new(srid,with_z,with_m)
|
@@ -287,6 +287,23 @@ module GeoRuby
|
|
287
287
|
set_x_y_z(-@x, -@y, -@z)
|
288
288
|
end
|
289
289
|
|
290
|
+
# TODO Perhaps should support with_m analogous to from_coordinates?
|
291
|
+
def to_coordinates
|
292
|
+
if with_z
|
293
|
+
[x,y,z]
|
294
|
+
else
|
295
|
+
[x,y]
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
# simple geojson representation
|
300
|
+
# TODO add CRS / SRID support?
|
301
|
+
def to_json(options = {})
|
302
|
+
{:type => 'Point',
|
303
|
+
:coordinates => self.to_coordinates}.to_json(options)
|
304
|
+
end
|
305
|
+
alias :as_geojson :to_json
|
306
|
+
|
290
307
|
#creates a point from an array of coordinates
|
291
308
|
def self.from_coordinates(coords,srid=DEFAULT_SRID,with_z=false,with_m=false)
|
292
309
|
if ! (with_z or with_m)
|
@@ -128,6 +128,18 @@ module GeoRuby
|
|
128
128
|
end
|
129
129
|
result += "</Polygon>\n"
|
130
130
|
end
|
131
|
+
|
132
|
+
def to_coordinates
|
133
|
+
rings.map{|lr| lr.to_coordinates}
|
134
|
+
end
|
135
|
+
|
136
|
+
# simple geojson representation
|
137
|
+
# TODO add CRS / SRID support?
|
138
|
+
def to_json(options = {})
|
139
|
+
{:type => 'Polygon',
|
140
|
+
:coordinates => self.to_coordinates}.to_json(options)
|
141
|
+
end
|
142
|
+
alias :as_geojson :to_json
|
131
143
|
|
132
144
|
#creates a new polygon. Accepts an array of linear strings as argument
|
133
145
|
def self.from_linear_rings(linear_rings,srid = DEFAULT_SRID,with_z=false,with_m=false)
|
@@ -0,0 +1,136 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{marcusmateus-georuby}
|
8
|
+
s.version = "1.8.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Guilhem Vellut", "Marcos Piccinini", "Marcus Mateus"]
|
12
|
+
s.date = %q{2010-12-19}
|
13
|
+
s.description = %q{GeoRuby provides geometric data types from the OGC 'Simple Features' specification.}
|
14
|
+
s.email = %q{georuby@simplitex.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
"History.txt",
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"lib/geo_ruby.rb",
|
26
|
+
"lib/geo_ruby/gpx.rb",
|
27
|
+
"lib/geo_ruby/gpx4r/gpx.rb",
|
28
|
+
"lib/geo_ruby/shp.rb",
|
29
|
+
"lib/geo_ruby/shp4r/dbf.rb",
|
30
|
+
"lib/geo_ruby/shp4r/shp.rb",
|
31
|
+
"lib/geo_ruby/simple_features/envelope.rb",
|
32
|
+
"lib/geo_ruby/simple_features/ewkb_parser.rb",
|
33
|
+
"lib/geo_ruby/simple_features/ewkt_parser.rb",
|
34
|
+
"lib/geo_ruby/simple_features/geojson_parser.rb",
|
35
|
+
"lib/geo_ruby/simple_features/geometry.rb",
|
36
|
+
"lib/geo_ruby/simple_features/geometry_collection.rb",
|
37
|
+
"lib/geo_ruby/simple_features/geometry_factory.rb",
|
38
|
+
"lib/geo_ruby/simple_features/georss_parser.rb",
|
39
|
+
"lib/geo_ruby/simple_features/helper.rb",
|
40
|
+
"lib/geo_ruby/simple_features/line_string.rb",
|
41
|
+
"lib/geo_ruby/simple_features/linear_ring.rb",
|
42
|
+
"lib/geo_ruby/simple_features/multi_line_string.rb",
|
43
|
+
"lib/geo_ruby/simple_features/multi_point.rb",
|
44
|
+
"lib/geo_ruby/simple_features/multi_polygon.rb",
|
45
|
+
"lib/geo_ruby/simple_features/point.rb",
|
46
|
+
"lib/geo_ruby/simple_features/polygon.rb",
|
47
|
+
"script/console",
|
48
|
+
"script/destroy",
|
49
|
+
"script/generate",
|
50
|
+
"script/txt2html",
|
51
|
+
"spec/data/geojson/feature_collection.json",
|
52
|
+
"spec/data/gpx/fells_loop.gpx",
|
53
|
+
"spec/data/gpx/long.gpx",
|
54
|
+
"spec/data/gpx/long.kml",
|
55
|
+
"spec/data/gpx/long.nmea",
|
56
|
+
"spec/data/gpx/short.gpx",
|
57
|
+
"spec/data/gpx/short.kml",
|
58
|
+
"spec/data/gpx/tracktreks.gpx",
|
59
|
+
"spec/data/multipoint.dbf",
|
60
|
+
"spec/data/multipoint.shp",
|
61
|
+
"spec/data/multipoint.shx",
|
62
|
+
"spec/data/point.dbf",
|
63
|
+
"spec/data/point.shp",
|
64
|
+
"spec/data/point.shx",
|
65
|
+
"spec/data/polygon.dbf",
|
66
|
+
"spec/data/polygon.shp",
|
67
|
+
"spec/data/polygon.shx",
|
68
|
+
"spec/data/polyline.dbf",
|
69
|
+
"spec/data/polyline.shp",
|
70
|
+
"spec/data/polyline.shx",
|
71
|
+
"spec/geo_ruby/gpx4r/gpx_spec.rb",
|
72
|
+
"spec/geo_ruby/shp4r/shp_spec.rb",
|
73
|
+
"spec/geo_ruby/simple_features/envelope_spec.rb",
|
74
|
+
"spec/geo_ruby/simple_features/ewkb_parser_spec.rb",
|
75
|
+
"spec/geo_ruby/simple_features/ewkt_parser_spec.rb",
|
76
|
+
"spec/geo_ruby/simple_features/geojson_parser_spec.rb",
|
77
|
+
"spec/geo_ruby/simple_features/geometry_collection_spec.rb",
|
78
|
+
"spec/geo_ruby/simple_features/geometry_factory_spec.rb",
|
79
|
+
"spec/geo_ruby/simple_features/geometry_spec.rb",
|
80
|
+
"spec/geo_ruby/simple_features/georss_parser_spec.rb",
|
81
|
+
"spec/geo_ruby/simple_features/line_string_spec.rb",
|
82
|
+
"spec/geo_ruby/simple_features/linear_ring_spec.rb",
|
83
|
+
"spec/geo_ruby/simple_features/multi_line_string_spec.rb",
|
84
|
+
"spec/geo_ruby/simple_features/multi_point_spec.rb",
|
85
|
+
"spec/geo_ruby/simple_features/multi_polygon_spec.rb",
|
86
|
+
"spec/geo_ruby/simple_features/point_spec.rb",
|
87
|
+
"spec/geo_ruby/simple_features/polygon_spec.rb",
|
88
|
+
"spec/geo_ruby_spec.rb",
|
89
|
+
"spec/spec_helper.rb"
|
90
|
+
]
|
91
|
+
s.homepage = %q{http://github.com/marcusmateus/georuby}
|
92
|
+
s.require_paths = ["lib"]
|
93
|
+
s.rubygems_version = %q{1.3.7}
|
94
|
+
s.summary = %q{Ruby data holder for OGC Simple Features}
|
95
|
+
s.test_files = [
|
96
|
+
"spec/geo_ruby/gpx4r/gpx_spec.rb",
|
97
|
+
"spec/geo_ruby/shp4r/shp_spec.rb",
|
98
|
+
"spec/geo_ruby/simple_features/envelope_spec.rb",
|
99
|
+
"spec/geo_ruby/simple_features/ewkb_parser_spec.rb",
|
100
|
+
"spec/geo_ruby/simple_features/ewkt_parser_spec.rb",
|
101
|
+
"spec/geo_ruby/simple_features/geojson_parser_spec.rb",
|
102
|
+
"spec/geo_ruby/simple_features/geometry_collection_spec.rb",
|
103
|
+
"spec/geo_ruby/simple_features/geometry_factory_spec.rb",
|
104
|
+
"spec/geo_ruby/simple_features/geometry_spec.rb",
|
105
|
+
"spec/geo_ruby/simple_features/georss_parser_spec.rb",
|
106
|
+
"spec/geo_ruby/simple_features/line_string_spec.rb",
|
107
|
+
"spec/geo_ruby/simple_features/linear_ring_spec.rb",
|
108
|
+
"spec/geo_ruby/simple_features/multi_line_string_spec.rb",
|
109
|
+
"spec/geo_ruby/simple_features/multi_point_spec.rb",
|
110
|
+
"spec/geo_ruby/simple_features/multi_polygon_spec.rb",
|
111
|
+
"spec/geo_ruby/simple_features/point_spec.rb",
|
112
|
+
"spec/geo_ruby/simple_features/polygon_spec.rb",
|
113
|
+
"spec/geo_ruby_spec.rb",
|
114
|
+
"spec/spec_helper.rb"
|
115
|
+
]
|
116
|
+
|
117
|
+
if s.respond_to? :specification_version then
|
118
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
119
|
+
s.specification_version = 3
|
120
|
+
|
121
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
122
|
+
s.add_runtime_dependency(%q<json_pure>, [">= 1.4.6"])
|
123
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
|
124
|
+
s.add_development_dependency(%q<dbf>, [">= 1.2.9"])
|
125
|
+
else
|
126
|
+
s.add_dependency(%q<json_pure>, [">= 1.4.6"])
|
127
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
128
|
+
s.add_dependency(%q<dbf>, [">= 1.2.9"])
|
129
|
+
end
|
130
|
+
else
|
131
|
+
s.add_dependency(%q<json_pure>, [">= 1.4.6"])
|
132
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
133
|
+
s.add_dependency(%q<dbf>, [">= 1.2.9"])
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
{ "type": "FeatureCollection",
|
2
|
+
"features": [
|
3
|
+
{ "type": "Feature",
|
4
|
+
"geometry": {"type": "Point", "coordinates": [102.0, 0.5]},
|
5
|
+
"properties": {"prop0": "value0"}
|
6
|
+
},
|
7
|
+
{ "type": "Feature",
|
8
|
+
"geometry": {
|
9
|
+
"type": "LineString",
|
10
|
+
"coordinates": [
|
11
|
+
[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]
|
12
|
+
]
|
13
|
+
},
|
14
|
+
"properties": {
|
15
|
+
"prop0": "value0",
|
16
|
+
"prop1": 0.0
|
17
|
+
}
|
18
|
+
},
|
19
|
+
{ "type": "Feature",
|
20
|
+
"geometry": {
|
21
|
+
"type": "Polygon",
|
22
|
+
"coordinates": [
|
23
|
+
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
|
24
|
+
[100.0, 1.0], [100.0, 0.0] ]
|
25
|
+
]
|
26
|
+
},
|
27
|
+
"properties": {
|
28
|
+
"prop0": "value0",
|
29
|
+
"prop1": {"this": "that"}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
]
|
33
|
+
}
|
34
|
+
|
@@ -33,8 +33,8 @@ describe Gpx4r do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should read X and Y" do
|
36
|
-
@gpxfile[0].x.should
|
37
|
-
@gpxfile[0].y.should
|
36
|
+
@gpxfile[0].x.should be_within(0.0001).of(9.093942)
|
37
|
+
@gpxfile[0].y.should be_within(0.0001).of(48.731813)
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should read Z and M" do
|
@@ -43,8 +43,8 @@ describe Gpx4r do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should read X and Y 2" do
|
46
|
-
@gpxfile2[0].x.should
|
47
|
-
@gpxfile2[0].y.should
|
46
|
+
@gpxfile2[0].x.should be_within(0.0001).of(-71.119277)
|
47
|
+
@gpxfile2[0].y.should be_within(0.0001).of(42.438878)
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should read Z and M 2" do
|
@@ -53,8 +53,8 @@ describe Gpx4r do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should read X and Y 3" do
|
56
|
-
@gpxfile3[0].x.should
|
57
|
-
@gpxfile3[0].y.should
|
56
|
+
@gpxfile3[0].x.should be_within(0.0001).of(-149.8358011)
|
57
|
+
@gpxfile3[0].y.should be_within(0.0001).of(-17.5326508)
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should read Z and M 3" do
|
@@ -74,14 +74,14 @@ describe Gpx4r do
|
|
74
74
|
|
75
75
|
it "should return a envelope" do
|
76
76
|
@gpxfile.envelope.should be_instance_of Envelope
|
77
|
-
@gpxfile.envelope.lower_corner.x.should
|
78
|
-
@gpxfile.envelope.lower_corner.y.should
|
77
|
+
@gpxfile.envelope.lower_corner.x.should be_within(0.001).of(9.08128)
|
78
|
+
@gpxfile.envelope.lower_corner.y.should be_within(0.001).of(48.7169)
|
79
79
|
end
|
80
80
|
|
81
81
|
it "should return a envelope 3" do
|
82
82
|
@gpxfile3.envelope.should be_instance_of Envelope
|
83
|
-
@gpxfile3.envelope.lower_corner.x.should
|
84
|
-
@gpxfile3.envelope.lower_corner.y.should
|
83
|
+
@gpxfile3.envelope.lower_corner.x.should be_within(0.001).of(-149.8422613)
|
84
|
+
@gpxfile3.envelope.lower_corner.y.should be_within(0.001).of(-17.547636)
|
85
85
|
end
|
86
86
|
|
87
87
|
it "should return it as a polygon" do
|
@@ -25,16 +25,16 @@ describe Shp4r do
|
|
25
25
|
it "should parse record 1" do
|
26
26
|
rec = @shpfile[0]
|
27
27
|
rec.geometry.should be_kind_of Point
|
28
|
-
rec.geometry.x.should
|
29
|
-
rec.geometry.y.should
|
28
|
+
rec.geometry.x.should be_within(0.00001).of(-90.08375)
|
29
|
+
rec.geometry.y.should be_within(0.00001).of(34.39996)
|
30
30
|
rec.data["Hoyoyo"].should eql(6)
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should parse record 2" do
|
34
34
|
rec = @shpfile[1]
|
35
35
|
rec.geometry.should be_kind_of Point
|
36
|
-
rec.geometry.x.should
|
37
|
-
rec.geometry.y.should
|
36
|
+
rec.geometry.x.should be_within(0.00001).of(-87.82580)
|
37
|
+
rec.geometry.y.should be_within(0.00001).of(33.36416)
|
38
38
|
rec.data["Hoyoyo"].should eql(9)
|
39
39
|
end
|
40
40
|
|
@@ -2,7 +2,8 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|
2
2
|
|
3
3
|
describe Envelope do
|
4
4
|
before(:each) do
|
5
|
-
@
|
5
|
+
@srid = 4269
|
6
|
+
@env = Envelope.from_points([Point.from_x_y(10,20, @srid),Point.from_x_y(20,30, @srid)], @srid)
|
6
7
|
end
|
7
8
|
|
8
9
|
it "should initialize" do
|
@@ -36,6 +37,7 @@ describe Envelope do
|
|
36
37
|
it "should have a center" do
|
37
38
|
@env.center.x.should eql(15)
|
38
39
|
@env.center.y.should eql(25)
|
40
|
+
@env.center.srid.should eql(@env.srid)
|
39
41
|
end
|
40
42
|
|
41
43
|
it "should print a kml_representation" do
|
@@ -0,0 +1,147 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
DATA_DIR = File.dirname(__FILE__) + '/../../data/geojson/'
|
4
|
+
|
5
|
+
# All geojson test examples are from the GeoJSON spec unless otherwise
|
6
|
+
# specified
|
7
|
+
#
|
8
|
+
# TODO Refactor comon test approaches into methods
|
9
|
+
# TODO Add use of contexts?
|
10
|
+
describe GeojsonParser do
|
11
|
+
|
12
|
+
it "should create a specified Point" do
|
13
|
+
point_json = %{ { "type": "Point", "coordinates": [100.0, 0.0] } }
|
14
|
+
point = Geometry.from_geojson(point_json)
|
15
|
+
point.class.should eql(Point)
|
16
|
+
point_hash = JSON.parse(point_json)
|
17
|
+
point.to_coordinates.should eql(point_hash['coordinates'])
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should create a specified LineString" do
|
21
|
+
ls_json = %{ { "type": "LineString", "coordinates": [ [100.0, 0.0], [101.0, 1.0] ]} }
|
22
|
+
line_string = Geometry.from_geojson(ls_json)
|
23
|
+
line_string.class.should eql(LineString)
|
24
|
+
ls_hash = JSON.parse(ls_json)
|
25
|
+
line_string.to_coordinates.should eql(ls_hash['coordinates'])
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should create a specified Polygon" do
|
29
|
+
poly_json = <<-EOJ
|
30
|
+
{ "type": "Polygon",
|
31
|
+
"coordinates": [
|
32
|
+
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ],
|
33
|
+
[ [100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2] ]
|
34
|
+
]
|
35
|
+
}
|
36
|
+
EOJ
|
37
|
+
polygon = Geometry.from_geojson(poly_json)
|
38
|
+
polygon.class.should eql(Polygon)
|
39
|
+
polygon.rings.size.should eql(2)
|
40
|
+
poly_hash = JSON.parse(poly_json)
|
41
|
+
polygon.to_coordinates.should eql(poly_hash['coordinates'])
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should create a specified MultiPoint" do
|
45
|
+
mp_json = <<-EOJ
|
46
|
+
{ "type": "MultiPoint",
|
47
|
+
"coordinates": [ [100.0, 0.0], [101.0, 1.0] ]
|
48
|
+
}
|
49
|
+
EOJ
|
50
|
+
multi_point = Geometry.from_geojson(mp_json)
|
51
|
+
multi_point.class.should eql(MultiPoint)
|
52
|
+
mp_hash = JSON.parse(mp_json)
|
53
|
+
multi_point.to_coordinates.should eql(mp_hash['coordinates'])
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should create a specified MultiLineString" do
|
57
|
+
mls_json = <<-EOJ
|
58
|
+
{ "type": "MultiLineString",
|
59
|
+
"coordinates": [
|
60
|
+
[ [100.0, 0.0], [101.0, 1.0] ],
|
61
|
+
[ [102.0, 2.0], [103.0, 3.0] ]
|
62
|
+
]
|
63
|
+
}
|
64
|
+
EOJ
|
65
|
+
multi_ls = Geometry.from_geojson(mls_json)
|
66
|
+
multi_ls.class.should eql(MultiLineString)
|
67
|
+
mls_hash = JSON.parse(mls_json)
|
68
|
+
multi_ls.to_coordinates.should eql(mls_hash['coordinates'])
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should create a specifiead MultiPolygon" do
|
72
|
+
mpoly_json = <<-EOJ
|
73
|
+
{ "type": "MultiPolygon",
|
74
|
+
"coordinates": [
|
75
|
+
[[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]],
|
76
|
+
[[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]],
|
77
|
+
[[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]]
|
78
|
+
]
|
79
|
+
}
|
80
|
+
EOJ
|
81
|
+
mpoly = Geometry.from_geojson(mpoly_json)
|
82
|
+
mpoly.class.should eql(MultiPolygon)
|
83
|
+
mpoly_hash = JSON.parse(mpoly_json)
|
84
|
+
mpoly.to_coordinates.should eql(mpoly_hash['coordinates'])
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should create a specified GeometryCollection" do
|
88
|
+
gcol_json = <<-EOJ
|
89
|
+
{ "type": "GeometryCollection",
|
90
|
+
"geometries": [
|
91
|
+
{ "type": "Point",
|
92
|
+
"coordinates": [100.0, 0.0]
|
93
|
+
},
|
94
|
+
{ "type": "LineString",
|
95
|
+
"coordinates": [ [101.0, 0.0], [102.0, 1.0] ]
|
96
|
+
}
|
97
|
+
]
|
98
|
+
}
|
99
|
+
EOJ
|
100
|
+
gcol = Geometry.from_geojson(gcol_json)
|
101
|
+
gcol.class.should eql(GeometryCollection)
|
102
|
+
gcol_hash = JSON.parse(gcol_json)
|
103
|
+
gcol.geometries.each_with_index do |g,i|
|
104
|
+
gh = gcol_hash['geometries'][i]
|
105
|
+
g.class.should eql(GeoRuby::SimpleFeatures.const_get(gh['type']))
|
106
|
+
g.to_coordinates.should eql(gh['coordinates'])
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# Feature GeoJSON test example from wikipedia entry
|
111
|
+
it "should create a specified Feature" do
|
112
|
+
feature_json = <<-EOJ
|
113
|
+
{
|
114
|
+
"type":"Feature",
|
115
|
+
"id":"OpenLayers.Feature.Vector_314",
|
116
|
+
"properties":{"prop0": "value0"},
|
117
|
+
"geometry":{
|
118
|
+
"type":"Point",
|
119
|
+
"coordinates":[97.03125, 39.7265625]
|
120
|
+
}
|
121
|
+
}
|
122
|
+
EOJ
|
123
|
+
f = Geometry.from_geojson(feature_json)
|
124
|
+
f.class.should eql(GeojsonFeature)
|
125
|
+
feature_hash = JSON.parse(feature_json)
|
126
|
+
f.id.should eql(feature_hash['id'])
|
127
|
+
f.properties.should eql(feature_hash['properties'])
|
128
|
+
f.geometry.class.should eql(GeoRuby::SimpleFeatures.const_get(feature_hash['geometry']['type']))
|
129
|
+
f.geometry.to_coordinates.should eql(feature_hash['geometry']['coordinates'])
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should create a specified FeatureCollection" do
|
133
|
+
fcol_json = File.read(DATA_DIR + 'feature_collection.json')
|
134
|
+
fcol = Geometry.from_geojson(fcol_json)
|
135
|
+
fcol.class.should eql(GeojsonFeatureCollection)
|
136
|
+
fcol_hash = JSON.parse(fcol_json)
|
137
|
+
fcol.features.each_with_index do |f,i|
|
138
|
+
fgh = fcol_hash['features'][i]['geometry']
|
139
|
+
fg = f.geometry
|
140
|
+
f.properties.should eql(fcol_hash['features'][i]['properties'])
|
141
|
+
fg.class.should eql(GeoRuby::SimpleFeatures.const_get(fgh['type']))
|
142
|
+
fg.to_coordinates.should eql(fgh['coordinates'])
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|