geekdaily-georuby 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +7 -0
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
  3. data/.github/ISSUE_TEMPLATE/code-of-conduct-issue.md +10 -0
  4. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  5. data/.gitignore +7 -0
  6. data/.rubocop.yml +8 -0
  7. data/.travis.yml +24 -0
  8. data/CODE_OF_CONDUCT.md +132 -0
  9. data/CONTRIBUTING.md +19 -0
  10. data/Gemfile +4 -0
  11. data/Guardfile +16 -0
  12. data/History.txt +4 -0
  13. data/MIT-LICENSE +7 -0
  14. data/README.md +237 -0
  15. data/Rakefile +32 -0
  16. data/bench.rb +35 -0
  17. data/georuby.gemspec +38 -0
  18. data/lib/geo_ruby.rb +11 -0
  19. data/lib/geo_ruby/ewk.rb +2 -0
  20. data/lib/geo_ruby/ewk/ewkb_parser.rb +206 -0
  21. data/lib/geo_ruby/ewk/ewkt_parser.rb +321 -0
  22. data/lib/geo_ruby/geojson.rb +139 -0
  23. data/lib/geo_ruby/georss.rb +156 -0
  24. data/lib/geo_ruby/gpx.rb +113 -0
  25. data/lib/geo_ruby/kml.rb +96 -0
  26. data/lib/geo_ruby/shp.rb +2 -0
  27. data/lib/geo_ruby/shp4r/dbf.rb +60 -0
  28. data/lib/geo_ruby/shp4r/shp.rb +726 -0
  29. data/lib/geo_ruby/simple_features.rb +21 -0
  30. data/lib/geo_ruby/simple_features/circle.rb +59 -0
  31. data/lib/geo_ruby/simple_features/envelope.rb +174 -0
  32. data/lib/geo_ruby/simple_features/geometry.rb +252 -0
  33. data/lib/geo_ruby/simple_features/geometry_collection.rb +143 -0
  34. data/lib/geo_ruby/simple_features/geometry_factory.rb +84 -0
  35. data/lib/geo_ruby/simple_features/helper.rb +18 -0
  36. data/lib/geo_ruby/simple_features/line_string.rb +224 -0
  37. data/lib/geo_ruby/simple_features/linear_ring.rb +34 -0
  38. data/lib/geo_ruby/simple_features/multi_line_string.rb +56 -0
  39. data/lib/geo_ruby/simple_features/multi_point.rb +52 -0
  40. data/lib/geo_ruby/simple_features/multi_polygon.rb +55 -0
  41. data/lib/geo_ruby/simple_features/point.rb +463 -0
  42. data/lib/geo_ruby/simple_features/polygon.rb +172 -0
  43. data/lib/geo_ruby/version.rb +3 -0
  44. data/lib/georuby.rb +2 -0
  45. data/spec/data/geojson/feature.json +9 -0
  46. data/spec/data/geojson/feature_collection.json +33 -0
  47. data/spec/data/georss/atom.xml +21 -0
  48. data/spec/data/georss/gml.xml +40 -0
  49. data/spec/data/georss/w3c.xml +22 -0
  50. data/spec/data/gpx/fells_loop.gpx +1077 -0
  51. data/spec/data/gpx/long.gpx +1642 -0
  52. data/spec/data/gpx/long.kml +31590 -0
  53. data/spec/data/gpx/long.nmea +2220 -0
  54. data/spec/data/gpx/short.gpx +13634 -0
  55. data/spec/data/gpx/short.kml +130 -0
  56. data/spec/data/gpx/tracktreks.gpx +706 -0
  57. data/spec/data/multipoint.dbf +0 -0
  58. data/spec/data/multipoint.shp +0 -0
  59. data/spec/data/multipoint.shx +0 -0
  60. data/spec/data/point.dbf +0 -0
  61. data/spec/data/point.shp +0 -0
  62. data/spec/data/point.shx +0 -0
  63. data/spec/data/polygon.dbf +0 -0
  64. data/spec/data/polygon.shp +0 -0
  65. data/spec/data/polygon.shx +0 -0
  66. data/spec/data/polyline.dbf +0 -0
  67. data/spec/data/polyline.shp +0 -0
  68. data/spec/data/polyline.shx +0 -0
  69. data/spec/geo_ruby/ewk/ewkb_parser_spec.rb +157 -0
  70. data/spec/geo_ruby/ewk/ewkt_parser_spec.rb +178 -0
  71. data/spec/geo_ruby/geojson_spec.rb +164 -0
  72. data/spec/geo_ruby/georss_spec.rb +238 -0
  73. data/spec/geo_ruby/gpx_spec.rb +103 -0
  74. data/spec/geo_ruby/kml_spec.rb +102 -0
  75. data/spec/geo_ruby/shp4r/shp_spec.rb +246 -0
  76. data/spec/geo_ruby/simple_features/circle_spec.rb +14 -0
  77. data/spec/geo_ruby/simple_features/envelope_spec.rb +47 -0
  78. data/spec/geo_ruby/simple_features/geometry_collection_spec.rb +55 -0
  79. data/spec/geo_ruby/simple_features/geometry_factory_spec.rb +11 -0
  80. data/spec/geo_ruby/simple_features/geometry_spec.rb +37 -0
  81. data/spec/geo_ruby/simple_features/line_string_spec.rb +268 -0
  82. data/spec/geo_ruby/simple_features/linear_ring_spec.rb +24 -0
  83. data/spec/geo_ruby/simple_features/multi_line_string_spec.rb +54 -0
  84. data/spec/geo_ruby/simple_features/multi_point_spec.rb +35 -0
  85. data/spec/geo_ruby/simple_features/multi_polygon_spec.rb +50 -0
  86. data/spec/geo_ruby/simple_features/point_spec.rb +547 -0
  87. data/spec/geo_ruby/simple_features/polygon_spec.rb +121 -0
  88. data/spec/geo_ruby_spec.rb +22 -0
  89. data/spec/spec_helper.rb +73 -0
  90. metadata +322 -0
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,157 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+ # rubocop:disable Metrics/LineLength
3
+ describe GeoRuby::SimpleFeatures::EWKBParser do
4
+
5
+ before(:each) do
6
+ @factory = GeoRuby::SimpleFeatures::GeometryFactory.new
7
+ @hex_ewkb_parser = GeoRuby::SimpleFeatures::HexEWKBParser.new(@factory)
8
+ end
9
+
10
+ it 'test_point2d' do
11
+ @hex_ewkb_parser.parse('01010000207B000000CDCCCCCCCCCC28406666666666A64640')
12
+ point = @factory.geometry
13
+ expect(point).to be_instance_of GeoRuby::SimpleFeatures::Point
14
+ expect(point).to eq(GeoRuby::SimpleFeatures::Point.from_x_y(12.4, 45.3, 123))
15
+ end
16
+
17
+ it 'test_point2d_BigEndian' do
18
+ @hex_ewkb_parser.parse('00000000014013A035BD512EC7404A3060C38F3669')
19
+ point = @factory.geometry
20
+ expect(point).to be_instance_of GeoRuby::SimpleFeatures::Point
21
+ expect(point).to eq(GeoRuby::SimpleFeatures::Point.from_x_y(4.906455, 52.377953))
22
+ end
23
+
24
+ it 'test_point3dz' do
25
+ @hex_ewkb_parser.parse('01010000A07B000000CDCCCCCCCCCC28406666666666A646400000000000000CC0')
26
+ point = @factory.geometry
27
+ expect(point).to be_instance_of GeoRuby::SimpleFeatures::Point
28
+ expect(point).to eq(GeoRuby::SimpleFeatures::Point.from_x_y_z(12.4, 45.3, -3.5, 123))
29
+ end
30
+
31
+ it 'test_point4d' do
32
+ @hex_ewkb_parser.parse('01010000E07B000000CDCCCCCCCCCC28406666666666A646400000000000000CC00000000000002E40')
33
+ point = @factory.geometry
34
+ expect(point).to be_instance_of GeoRuby::SimpleFeatures::Point
35
+ expect(point).to eq(GeoRuby::SimpleFeatures::Point.from_x_y_z_m(12.4, 45.3, -3.5, 15, 123))
36
+ end
37
+
38
+ it 'test_line_string' do
39
+ @hex_ewkb_parser.parse('01020000200001000002000000CDCCCCCCCCCC28406666666666A646C03333333333B34640CDCCCCCCCCCC4440')
40
+ line_string = @factory.geometry
41
+ expect(line_string).to be_instance_of GeoRuby::SimpleFeatures::LineString
42
+ expect(line_string).to eq(GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4, -45.3], [45.4, 41.6]], 256))
43
+
44
+ @hex_ewkb_parser.parse('01020000A00001000002000000CDCCCCCCCCCC28406666666666A646C06666666666A641403333333333B34640CDCCCCCCCCCC44409A99999999992840')
45
+ line_string = @factory.geometry
46
+ expect(line_string).to be_instance_of GeoRuby::SimpleFeatures::LineString
47
+ expect(line_string).to eq(GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4, -45.3, 35.3], [45.4, 41.6, 12.3]], 256, true))
48
+
49
+ @hex_ewkb_parser.parse('01020000E00001000002000000CDCCCCCCCCCC28406666666666A646C06666666666A64140CDCCCCCCCC8C46403333333333B34640CDCCCCCCCCCC44409A999999999928403D0AD7A3701D4440')
50
+ line_string = @factory.geometry
51
+ expect(line_string).to be_instance_of GeoRuby::SimpleFeatures::LineString
52
+ expect(line_string).to eq(GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4, -45.3, 35.3, 45.1], [45.4, 41.6, 12.3, 40.23]], 256, true, true))
53
+ end
54
+
55
+ it 'test_polygon' do
56
+ @hex_ewkb_parser.parse('0103000020000100000200000005000000000000000000000000000000000000000000000000001040000000000000000000000000000010400000000000001040000000000000000000000000000010400000000000000000000000000000000005000000000000000000F03F000000000000F03F0000000000000840000000000000F03F00000000000008400000000000000840000000000000F03F0000000000000840000000000000F03F000000000000F03F')
57
+ polygon = @factory.geometry
58
+ expect(polygon).to be_instance_of GeoRuby::SimpleFeatures::Polygon
59
+ expect(polygon).to eq(GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0, 0], [4, 0], [4, 4], [0, 4], [0, 0]], [[1, 1], [3, 1], [3, 3], [1, 3], [1, 1]]], 256))
60
+
61
+ @hex_ewkb_parser.parse('01030000A000010000020000000500000000000000000000000000000000000000000000000000004000000000000010400000000000000000000000000000004000000000000010400000000000001040000000000000004000000000000000000000000000001040000000000000004000000000000000000000000000000000000000000000004005000000000000000000F03F000000000000F03F00000000000000400000000000000840000000000000F03F0000000000000040000000000000084000000000000008400000000000000040000000000000F03F00000000000008400000000000000040000000000000F03F000000000000F03F0000000000000040')
62
+ polygon = @factory.geometry
63
+ expect(polygon).to be_instance_of GeoRuby::SimpleFeatures::Polygon
64
+ expect(polygon).to eq(GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0, 0, 2], [4, 0, 2], [4, 4, 2], [0, 4, 2], [0, 0, 2]], [[1, 1, 2], [3, 1, 2], [3, 3, 2], [1, 3, 2], [1, 1, 2]]], 256, true))
65
+
66
+ @hex_ewkb_parser.parse('010300006000010000020000000500000000000000000000000000000000000000000000000000004000000000000010400000000000000000000000000000004000000000000010400000000000001040000000000000004000000000000000000000000000001040000000000000004000000000000000000000000000000000000000000000004005000000000000000000F03F000000000000F03F00000000000000400000000000000840000000000000F03F0000000000000040000000000000084000000000000008400000000000000040000000000000F03F00000000000008400000000000000040000000000000F03F000000000000F03F0000000000000040')
67
+ polygon = @factory.geometry
68
+ expect(polygon).to be_instance_of GeoRuby::SimpleFeatures::Polygon
69
+ expect(polygon).to eq(GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0, 0, 2], [4, 0, 2], [4, 4, 2], [0, 4, 2], [0, 0, 2]], [[1, 1, 2], [3, 1, 2], [3, 3, 2], [1, 3, 2], [1, 1, 2]]], 256, false, true))
70
+
71
+ @hex_ewkb_parser.parse('01030000E0000100000200000005000000000000000000000000000000000000000000000000000040CDCCCCCCCC8C46C00000000000001040000000000000000000000000000000400000000000001440000000000000104000000000000010400000000000000040AE47E17A14AE1240000000000000000000000000000010400000000000000040713D0AD7A370F53F000000000000000000000000000000000000000000000040CDCCCCCCCC8C46C005000000000000000000F03F000000000000F03F00000000000000409A999999999928400000000000000840000000000000F03F00000000000000400000000000C05E400000000000000840000000000000084000000000000000406666666666662840000000000000F03F000000000000084000000000000000400000000000002840000000000000F03F000000000000F03F00000000000000409A99999999992840')
72
+ polygon = @factory.geometry
73
+ expect(polygon).to be_instance_of GeoRuby::SimpleFeatures::Polygon
74
+ expect(polygon).to eq(GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0, 0, 2, -45.1], [4, 0, 2, 5], [4, 4, 2, 4.67], [0, 4, 2, 1.34], [0, 0, 2, -45.1]], [[1, 1, 2, 12.3], [3, 1, 2, 123], [3, 3, 2, 12.2], [1, 3, 2, 12], [1, 1, 2, 12.3]]], 256, true, true))
75
+ end
76
+
77
+ it 'test_geometry_collection' do
78
+ @hex_ewkb_parser.parse('010700002000010000020000000101000000AE47E17A14AE12403333333333B34640010200000002000000CDCCCCCCCCCC16406666666666E628403333333333E350400000000000004B40')
79
+ geometry_collection = @factory.geometry
80
+ expect(geometry_collection).to be_instance_of GeoRuby::SimpleFeatures::GeometryCollection
81
+
82
+ expect(geometry_collection).to eq(GeoRuby::SimpleFeatures::GeometryCollection.from_geometries([GeoRuby::SimpleFeatures::Point.from_x_y(4.67, 45.4, 256), GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7, 12.45], [67.55, 54]], 256)], 256))
83
+ expect(geometry_collection[0].srid).to eql(256)
84
+
85
+ @hex_ewkb_parser.parse('01070000E0000100000200000001010000C0AE47E17A14AE12403333333333B34640F6285C8FC2D54640666666666666024001020000C002000000CDCCCCCCCCCC16406666666666E628403D0AD7A3703D124033333333339358403333333333E350400000000000004B4066666666666628403333333333330B40')
86
+ geometry_collection = @factory.geometry
87
+ expect(geometry_collection).to be_instance_of GeoRuby::SimpleFeatures::GeometryCollection
88
+ expect(geometry_collection).to eq(GeoRuby::SimpleFeatures::GeometryCollection.from_geometries([GeoRuby::SimpleFeatures::Point.from_x_y_z_m(4.67, 45.4, 45.67, 2.3, 256), GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7, 12.45, 4.56, 98.3], [67.55, 54, 12.2, 3.4]], 256, true, true)], 256, true, true))
89
+ expect(geometry_collection[0].srid).to eql(256)
90
+ end
91
+
92
+ it 'test_multi_point' do
93
+ @hex_ewkb_parser.parse('0104000020BC010000030000000101000000CDCCCCCCCCCC28403333333333D35EC0010100000066666666664650C09A99999999D95E4001010000001F97DD388EE35E400000000000C05E40')
94
+ multi_point = @factory.geometry
95
+ expect(multi_point).to be_instance_of GeoRuby::SimpleFeatures::MultiPoint
96
+ expect(multi_point).to eq(GeoRuby::SimpleFeatures::MultiPoint.from_coordinates([[12.4, -123.3], [-65.1, 123.4], [123.55555555, 123]], 444))
97
+ expect(multi_point.srid).to eql(444)
98
+ expect(multi_point[0].srid).to eql(444)
99
+
100
+ @hex_ewkb_parser.parse('01040000A0BC010000030000000101000080CDCCCCCCCCCC28403333333333D35EC00000000000001240010100008066666666664650C09A99999999D95E40333333333333F33F01010000801F97DD388EE35E400000000000C05E406666666666660240')
101
+ multi_point = @factory.geometry
102
+ expect(multi_point).to be_instance_of GeoRuby::SimpleFeatures::MultiPoint
103
+ expect(multi_point).to eq(GeoRuby::SimpleFeatures::MultiPoint.from_coordinates([[12.4, -123.3, 4.5], [-65.1, 123.4, 1.2], [123.55555555, 123, 2.3]], 444, true))
104
+ expect(multi_point.srid).to eql(444)
105
+ expect(multi_point[0].srid).to eql(444)
106
+ end
107
+
108
+ it 'test_multi_line_string' do
109
+ @hex_ewkb_parser.parse('01050000200001000002000000010200000002000000000000000000F83F9A99999999994640E4BD6A65C20F4BC0FA7E6ABC749388BF010200000003000000000000000000F83F9A99999999994640E4BD6A65C20F4BC0FA7E6ABC749388BF39B4C876BE8F46403333333333D35E40')
110
+ multi_line_string = @factory.geometry
111
+ expect(multi_line_string).to be_instance_of GeoRuby::SimpleFeatures::MultiLineString
112
+ expect(multi_line_string).to eq(GeoRuby::SimpleFeatures::MultiLineString.from_line_strings([GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5, 45.2], [-54.12312, -0.012]], 256), GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5, 45.2], [-54.12312, -0.012], [45.123, 123.3]], 256)], 256))
113
+ expect(multi_line_string.srid).to eql(256)
114
+ expect(multi_line_string[0].srid).to eql(256)
115
+
116
+ @hex_ewkb_parser.parse('0105000020000100000200000001020000C002000000000000000000F83F9A99999999994640CDCCCCCCCCCCF43F333333333333F33FE4BD6A65C20F4BC0FA7E6ABC749388BF333333333333F33F000000000000124001020000C003000000000000000000F83F9A99999999994640666666666666144000000000000012C0E4BD6A65C20F4BC0FA7E6ABC749388BF3333333333331BC03333333333330B4039B4C876BE8F46403333333333D35E40000000000000124033333333333315C0')
117
+ multi_line_string = @factory.geometry
118
+ expect(multi_line_string).to be_instance_of GeoRuby::SimpleFeatures::MultiLineString
119
+ expect(multi_line_string).to eq(GeoRuby::SimpleFeatures::MultiLineString.from_line_strings([GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5, 45.2, 1.3, 1.2], [-54.12312, -0.012, 1.2, 4.5]], 256, true, true), GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5, 45.2, 5.1, -4.5], [-54.12312, -0.012, -6.8, 3.4], [45.123, 123.3, 4.5, -5.3]], 256, true, true)], 256, true, true))
120
+ expect(multi_line_string.srid).to eql(256)
121
+ expect(multi_line_string[0].srid).to eql(256)
122
+ end
123
+
124
+ it 'test_multi_polygon' do
125
+ @hex_ewkb_parser.parse('0106000020000100000200000001030000000200000004000000CDCCCCCCCCCC28406666666666A646C03333333333B34640CDCCCCCCCCCC44406DE7FBA9F1D211403D2CD49AE61DF13FCDCCCCCCCCCC28406666666666A646C004000000333333333333034033333333333315409A999999999915408A8EE4F21FD2F63FEC51B81E85EB2C40F6285C8FC2F5F03F3333333333330340333333333333154001030000000200000005000000000000000000000000000000000000000000000000001040000000000000000000000000000010400000000000001040000000000000000000000000000010400000000000000000000000000000000005000000000000000000F03F000000000000F03F0000000000000840000000000000F03F00000000000008400000000000000840000000000000F03F0000000000000840000000000000F03F000000000000F03F')
126
+ multi_polygon = @factory.geometry
127
+ expect(multi_polygon).to be_instance_of GeoRuby::SimpleFeatures::MultiPolygon
128
+ expect(multi_polygon).to eq(GeoRuby::SimpleFeatures::MultiPolygon.from_polygons([GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4, -45.3], [45.4, 41.6], [4.456, 1.0698], [12.4, -45.3]], [[2.4, 5.3], [5.4, 1.4263], [14.46, 1.06], [2.4, 5.3]]], 256), GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0, 0], [4, 0], [4, 4], [0, 4], [0, 0]], [[1, 1], [3, 1], [3, 3], [1, 3], [1, 1]]], 256)], 256))
129
+ expect(multi_polygon.srid).to eql(256)
130
+ expect(multi_polygon[0].srid).to eql(256)
131
+
132
+ @hex_ewkb_parser.parse('0106000020000100000200000001030000400200000004000000CDCCCCCCCCCC28406666666666A646C0333333333333F33F3333333333B34640CDCCCCCCCCCC4440333333333333F33F6DE7FBA9F1D211403D2CD49AE61DF13F333333333333F33FCDCCCCCCCCCC28406666666666A646C0333333333333F33F0400000033333333333303403333333333331540333333333333F33F9A999999999915408A8EE4F21FD2F63F333333333333F33FEC51B81E85EB2C40F6285C8FC2F5F03F333333333333F33F33333333333303403333333333331540333333333333F33F0103000040020000000500000000000000000000000000000000000000333333333333F33F00000000000010400000000000000000333333333333F33F00000000000010400000000000001040666666666666024000000000000000000000000000001040333333333333F33F00000000000000000000000000000000333333333333F33F05000000000000000000F03F000000000000F03F9A999999999901400000000000000840000000000000F03F6666666666660A40000000000000084000000000000008409A9999999999F13F000000000000F03F00000000000008403333333333330340000000000000F03F000000000000F03F9A99999999990140')
133
+ multi_polygon = @factory.geometry
134
+ expect(multi_polygon).to be_instance_of GeoRuby::SimpleFeatures::MultiPolygon
135
+ expect(multi_polygon).to eq(GeoRuby::SimpleFeatures::MultiPolygon.from_polygons([GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4, -45.3, 1.2], [45.4, 41.6, 1.2], [4.456, 1.0698, 1.2], [12.4, -45.3, 1.2]], [[2.4, 5.3, 1.2], [5.4, 1.4263, 1.2], [14.46, 1.06, 1.2], [2.4, 5.3, 1.2]]], 256, false, true), GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0, 0, 1.2], [4, 0, 1.2], [4, 4, 2.3], [0, 4, 1.2], [0, 0, 1.2]], [[1, 1, 2.2], [3, 1, 3.3], [3, 3, 1.1], [1, 3, 2.4], [1, 1, 2.2]]], 256, false, true)], 256, false, true))
136
+ expect(multi_polygon.srid).to eql(256)
137
+ expect(multi_polygon[0].srid).to eql(256)
138
+ end
139
+
140
+ it 'test_failure_trailing_data' do
141
+ # added A345 at the end
142
+ expect { @hex_ewkb_parser.parse('01010000207B000000CDCCCCCCCCCC28406666666666A64640A345') }.to raise_error(GeoRuby::SimpleFeatures::EWKBFormatError)
143
+ end
144
+
145
+ it 'test_failure_unknown_geometry_type' do
146
+ expect { @hex_ewkb_parser.parse('01090000207B000000CDCCCCCCCCCC28406666666666A64640') }.to raise_error(GeoRuby::SimpleFeatures::EWKBFormatError)
147
+ end
148
+
149
+ it 'test_failure_m' do
150
+ expect { @hex_ewkb_parser.parse('01010000607B000000CDCCCCCCCCCC28406666666666A64640') }.to raise_error(GeoRuby::SimpleFeatures::EWKBFormatError)
151
+ end
152
+
153
+ it 'test_failure_truncated_data' do
154
+ expect { @hex_ewkb_parser.parse('01010000207B000000CDCCCCCCCCCC2840666666') }.to raise_error(GeoRuby::SimpleFeatures::EWKBFormatError)
155
+ end
156
+
157
+ end
@@ -0,0 +1,178 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe GeoRuby::SimpleFeatures::EWKTParser do
4
+
5
+ before(:each) do
6
+ @factory = GeoRuby::SimpleFeatures::GeometryFactory.new
7
+ @ewkt_parser = GeoRuby::SimpleFeatures::EWKTParser.new(@factory)
8
+ end
9
+
10
+ it 'test_point' do
11
+ ewkt = 'POINT( 3.456 0.123)'
12
+ @ewkt_parser.parse(ewkt)
13
+ point = @factory.geometry
14
+ expect(point).to be_instance_of GeoRuby::SimpleFeatures::Point
15
+ expect(point).to eq(GeoRuby::SimpleFeatures::Point.from_x_y(3.456, 0.123))
16
+ end
17
+
18
+ it 'test_point_with_srid' do
19
+ ewkt = 'SRID=245;POINT(0.0 2.0)'
20
+ @ewkt_parser.parse(ewkt)
21
+ point = @factory.geometry
22
+ expect(point).to be_instance_of GeoRuby::SimpleFeatures::Point
23
+ expect(point).to eq(GeoRuby::SimpleFeatures::Point.from_x_y(0, 2, 245))
24
+ expect(point.srid).to eql(245)
25
+ expect(ewkt).to eq(point.as_ewkt(true, false))
26
+ end
27
+
28
+ it 'test_point3dz' do
29
+ ewkt = 'POINT(3.456 0.123 123.667)'
30
+ @ewkt_parser.parse(ewkt)
31
+ point = @factory.geometry
32
+ expect(point).to be_instance_of GeoRuby::SimpleFeatures::Point
33
+ expect(point).to eq(GeoRuby::SimpleFeatures::Point.from_x_y_z(3.456, 0.123, 123.667))
34
+ expect(ewkt).to eq(point.as_ewkt(false))
35
+ end
36
+
37
+ it 'test_point3dm' do
38
+ ewkt = 'POINTM(3.456 0.123 123.667)'
39
+ @ewkt_parser.parse(ewkt)
40
+ point = @factory.geometry
41
+ expect(point).to be_instance_of GeoRuby::SimpleFeatures::Point
42
+ expect(point).to eq(GeoRuby::SimpleFeatures::Point.from_x_y_m(3.456, 0.123, 123.667))
43
+ expect(ewkt).to eq(point.as_ewkt(false))
44
+ end
45
+
46
+ it 'test_point4d' do
47
+ ewkt = 'POINT(3.456 0.123 123.667 15.0)'
48
+ @ewkt_parser.parse(ewkt)
49
+ point = @factory.geometry
50
+ expect(point).to be_instance_of GeoRuby::SimpleFeatures::Point
51
+ expect(point).to eq(GeoRuby::SimpleFeatures::Point.from_x_y_z_m(3.456, 0.123, 123.667, 15.0))
52
+ expect(ewkt).to eq(point.as_ewkt(false))
53
+ end
54
+
55
+ it 'test_linestring' do
56
+ @ewkt_parser.parse('LINESTRING(3.456 0.123,123.44 123.56,54555.22 123.3)')
57
+ line_string = @factory.geometry
58
+ expect(line_string).to be_instance_of GeoRuby::SimpleFeatures::LineString
59
+ expect(line_string).to eq(GeoRuby::SimpleFeatures::LineString.from_coordinates([[3.456, 0.123], [123.44, 123.56], [54_555.22, 123.3]]))
60
+
61
+ @ewkt_parser.parse('SRID=256;LINESTRING(12.4 -45.3,45.4 41.6)')
62
+ line_string = @factory.geometry
63
+ expect(line_string).to be_instance_of GeoRuby::SimpleFeatures::LineString
64
+ expect(line_string).to eq(GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4, -45.3], [45.4, 41.6]], 256))
65
+
66
+ @ewkt_parser.parse('SRID=256;LINESTRING(12.4 -45.3 35.3,45.4 41.6 12.3)')
67
+ line_string = @factory.geometry
68
+ expect(line_string).to be_instance_of GeoRuby::SimpleFeatures::LineString
69
+ expect(line_string).to eq(GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4, -45.3, 35.3], [45.4, 41.6, 12.3]], 256, true))
70
+
71
+ @ewkt_parser.parse('SRID=256;LINESTRINGM(12.4 -45.3 35.3,45.4 41.6 12.3)')
72
+ line_string = @factory.geometry
73
+ expect(line_string).to be_instance_of GeoRuby::SimpleFeatures::LineString
74
+ expect(line_string).to eq(GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4, -45.3, 35.3], [45.4, 41.6, 12.3]], 256, false, true))
75
+
76
+ @ewkt_parser.parse('SRID=256;LINESTRING(12.4 -45.3 35.3 25.2,45.4 41.6 12.3 13.75)')
77
+ line_string = @factory.geometry
78
+ expect(line_string).to be_instance_of GeoRuby::SimpleFeatures::LineString
79
+ expect(line_string).to eq(GeoRuby::SimpleFeatures::LineString.from_coordinates([[12.4, -45.3, 35.3, 25.2], [45.4, 41.6, 12.3, 13.75]], 256, true, true))
80
+ end
81
+
82
+ it 'test_polygon' do
83
+ @ewkt_parser.parse('POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1,3 1,3 3,1 3,1 1))')
84
+ polygon = @factory.geometry
85
+ expect(polygon).to be_instance_of GeoRuby::SimpleFeatures::Polygon
86
+ expect(polygon).to eq(GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0, 0], [4, 0], [4, 4], [0, 4], [0, 0]], [[1, 1], [3, 1], [3, 3], [1, 3], [1, 1]]], 256))
87
+
88
+ @ewkt_parser.parse('SRID=256;POLYGON( ( 0 0 2,4 0 2,4 4 2,0 4 2,0 0 2),(1 1 2,3 1 2,3 3 2,1 3 2,1 1 2))')
89
+ polygon = @factory.geometry
90
+ expect(polygon).to be_instance_of GeoRuby::SimpleFeatures::Polygon
91
+ expect(polygon).to eq(GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0, 0, 2], [4, 0, 2], [4, 4, 2], [0, 4, 2], [0, 0, 2]], [[1, 1, 2], [3, 1, 2], [3, 3, 2], [1, 3, 2], [1, 1, 2]]], 256, true))
92
+
93
+ @ewkt_parser.parse('SRID=256;POLYGONM((0 0 2,4 0 2,4 4 2,0 4 2,0 0 2),(1 1 2,3 1 2,3 3 2,1 3 2,1 1 2))')
94
+ polygon = @factory.geometry
95
+ expect(polygon).to be_instance_of GeoRuby::SimpleFeatures::Polygon
96
+ expect(polygon).to eq(GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0, 0, 2], [4, 0, 2], [4, 4, 2], [0, 4, 2], [0, 0, 2]], [[1, 1, 2], [3, 1, 2], [3, 3, 2], [1, 3, 2], [1, 1, 2]]], 256, false, true))
97
+
98
+ @ewkt_parser.parse('SRID=256;POLYGON((0 0 2 -45.1,4 0 2 5,4 4 2 4.67,0 4 2 1.34,0 0 2 -45.1),(1 1 2 12.3,3 1 2 123,3 3 2 12.2,1 3 2 12,1 1 2 12.3))')
99
+ polygon = @factory.geometry
100
+ expect(polygon).to be_instance_of GeoRuby::SimpleFeatures::Polygon
101
+ expect(polygon).to eq(GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0, 0, 2, -45.1], [4, 0, 2, 5], [4, 4, 2, 4.67], [0, 4, 2, 1.34], [0, 0, 2, -45.1]], [[1, 1, 2, 12.3], [3, 1, 2, 123], [3, 3, 2, 12.2], [1, 3, 2, 12], [1, 1, 2, 12.3]]], 256, true, true))
102
+ end
103
+
104
+ it 'test_multi_point' do
105
+ # Form output by the current version of PostGIS. Future versions will output the one in the specification
106
+ @ewkt_parser.parse('SRID=444;MULTIPOINT(12.4 -123.3,-65.1 123.4,123.55555555 123)')
107
+ multi_point = @factory.geometry
108
+ expect(multi_point).to be_instance_of GeoRuby::SimpleFeatures::MultiPoint
109
+ expect(multi_point).to eq(GeoRuby::SimpleFeatures::MultiPoint.from_coordinates([[12.4, -123.3], [-65.1, 123.4], [123.55555555, 123]], 444))
110
+ expect(multi_point.srid).to eql(444)
111
+ expect(multi_point[0].srid).to eql(444)
112
+
113
+ @ewkt_parser.parse('SRID=444;MULTIPOINT(12.4 -123.3 4.5,-65.1 123.4 6.7,123.55555555 123 7.8)')
114
+ multi_point = @factory.geometry
115
+ expect(multi_point).to be_instance_of GeoRuby::SimpleFeatures::MultiPoint
116
+ expect(multi_point).to eq(GeoRuby::SimpleFeatures::MultiPoint.from_coordinates([[12.4, -123.3, 4.5], [-65.1, 123.4, 6.7], [123.55555555, 123, 7.8]], 444, true))
117
+ expect(multi_point.srid).to eql(444)
118
+ expect(multi_point[0].srid).to eql(444)
119
+
120
+ # Form in the EWKT specification (from the OGC)
121
+ @ewkt_parser.parse('SRID=444;MULTIPOINT( ( 12.4 -123.3 4.5 ) , (-65.1 123.4 6.7),(123.55555555 123 7.8))')
122
+ multi_point = @factory.geometry
123
+ expect(multi_point).to be_instance_of GeoRuby::SimpleFeatures::MultiPoint
124
+ expect(multi_point).to eq(GeoRuby::SimpleFeatures::MultiPoint.from_coordinates([[12.4, -123.3, 4.5], [-65.1, 123.4, 6.7], [123.55555555, 123, 7.8]], 444, true))
125
+ expect(multi_point.srid).to eql(444)
126
+ expect(multi_point[0].srid).to eql(444)
127
+ end
128
+
129
+ it 'test_multi_line_string' do
130
+ @ewkt_parser.parse('SRID=256;MULTILINESTRING((1.5 45.2,-54.12312 -0.012),(1.5 45.2,-54.12312 -0.012,45.123 123.3))')
131
+ multi_line_string = @factory.geometry
132
+ expect(multi_line_string).to be_instance_of GeoRuby::SimpleFeatures::MultiLineString
133
+ expect(multi_line_string).to eq(GeoRuby::SimpleFeatures::MultiLineString.from_line_strings([GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5, 45.2], [-54.12312, -0.012]], 256), GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5, 45.2], [-54.12312, -0.012], [45.123, 123.3]], 256)], 256))
134
+ expect(multi_line_string.srid).to eql(256)
135
+ expect(multi_line_string[0].srid).to eql(256)
136
+
137
+ @ewkt_parser.parse('SRID=256;MULTILINESTRING((1.5 45.2 1.3 1.2,-54.12312 -0.012 1.2 4.5),(1.5 45.2 5.1 -4.5,-54.12312 -0.012 -6.8 3.4,45.123 123.3 4.5 -5.3))')
138
+ multi_line_string = @factory.geometry
139
+ expect(multi_line_string).to be_instance_of GeoRuby::SimpleFeatures::MultiLineString
140
+ expect(multi_line_string).to eq(GeoRuby::SimpleFeatures::MultiLineString.from_line_strings([GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5, 45.2, 1.3, 1.2], [-54.12312, -0.012, 1.2, 4.5]], 256, true, true), GeoRuby::SimpleFeatures::LineString.from_coordinates([[1.5, 45.2, 5.1, -4.5], [-54.12312, -0.012, -6.8, 3.4], [45.123, 123.3, 4.5, -5.3]], 256, true, true)], 256, true, true))
141
+ expect(multi_line_string.srid).to eql(256)
142
+ expect(multi_line_string[0].srid).to eql(256)
143
+ end
144
+
145
+ it 'test_multi_polygon' do
146
+ ewkt = 'SRID=256;MULTIPOLYGON(((12.4 -45.3,45.4 41.6,4.456 1.0698,12.4 -45.3),(2.4 5.3,5.4 1.4263,14.46 1.06,2.4 5.3)),((0.0 0.0,4.0 0.0,4.0 4.0,0.0 4.0,0.0 0.0),(1.0 1.0,3.0 1.0,3.0 3.0,1.0 3.0,1.0 1.0)))'
147
+ @ewkt_parser.parse(ewkt)
148
+ multi_polygon = @factory.geometry
149
+ expect(multi_polygon).to be_instance_of GeoRuby::SimpleFeatures::MultiPolygon
150
+ expect(multi_polygon).to eq(GeoRuby::SimpleFeatures::MultiPolygon.from_polygons([GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4, -45.3], [45.4, 41.6], [4.456, 1.0698], [12.4, -45.3]], [[2.4, 5.3], [5.4, 1.4263], [14.46, 1.06], [2.4, 5.3]]], 256), GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0, 0], [4, 0], [4, 4], [0, 4], [0, 0]], [[1, 1], [3, 1], [3, 3], [1, 3], [1, 1]]], 256)], 256))
151
+ expect(multi_polygon.srid).to eql(256)
152
+ expect(multi_polygon[0].srid).to eql(256)
153
+ expect(ewkt).to eq(multi_polygon.as_ewkt)
154
+
155
+ ewkt = 'MULTIPOLYGON(((12.4 -45.3 2,45.4 41.6 3,4.456 1.0698 4,12.4 -45.3 2),(2.4 5.3 1,5.4 1.4263 3.44,14.46 1.06 4.5,2.4 5.3 1)),((0 0 5.6,4 0 5.4,4 4 1,0 4 23,0 0 5.6),(1 1 2.3,3 1 4,3 3 5,1 3 6,1 1 2.3)))'
156
+ @ewkt_parser.parse(ewkt)
157
+ multi_polygon = @factory.geometry
158
+ expect(multi_polygon).to be_instance_of GeoRuby::SimpleFeatures::MultiPolygon
159
+ expect(multi_polygon).to eq(GeoRuby::SimpleFeatures::MultiPolygon.from_polygons([GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4, -45.3, 2], [45.4, 41.6, 3], [4.456, 1.0698, 4], [12.4, -45.3, 2]], [[2.4, 5.3, 1], [5.4, 1.4263, 3.44], [14.46, 1.06, 4.5], [2.4, 5.3, 1]]], 4326, true), GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0, 0, 5.6], [4, 0, 5.4], [4, 4, 1], [0, 4, 23], [0, 0, 5.6]], [[1, 1, 2.3], [3, 1, 4], [3, 3, 5], [1, 3, 6], [1, 1, 2.3]]], 4326, true)], 4326, true))
160
+ expect(multi_polygon.srid).to eql(4326)
161
+ expect(multi_polygon[0].srid).to eql(4326)
162
+ end
163
+
164
+ it 'test_geometry_collection' do
165
+ @ewkt_parser.parse('SRID=256;GEOMETRYCOLLECTION(POINT(4.67 45.4),LINESTRING(5.7 12.45,67.55 54),POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1,3 1,3 3,1 3,1 1)))')
166
+ geometry_collection = @factory.geometry
167
+ expect(geometry_collection).to be_instance_of GeoRuby::SimpleFeatures::GeometryCollection
168
+ expect(geometry_collection).to eq(GeoRuby::SimpleFeatures::GeometryCollection.from_geometries([GeoRuby::SimpleFeatures::Point.from_x_y(4.67, 45.4, 256), GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7, 12.45], [67.55, 54]], 256), GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0, 0], [4, 0], [4, 4], [0, 4], [0, 0]], [[1, 1], [3, 1], [3, 3], [1, 3], [1, 1]]], 256)], 256))
169
+ expect(geometry_collection[0].srid).to eql(256)
170
+
171
+ @ewkt_parser.parse('SRID=256;GEOMETRYCOLLECTIONM(POINTM(4.67 45.4 45.6),LINESTRINGM(5.7 12.45 5.6,67.55 54 6.7))')
172
+ geometry_collection = @factory.geometry
173
+ expect(geometry_collection).to be_instance_of GeoRuby::SimpleFeatures::GeometryCollection
174
+ expect(geometry_collection).to eq(GeoRuby::SimpleFeatures::GeometryCollection.from_geometries([GeoRuby::SimpleFeatures::Point.from_x_y_m(4.67, 45.4, 45.6, 256), GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7, 12.45, 5.6], [67.55, 54, 6.7]], 256, false, true)], 256, false, true))
175
+ expect(geometry_collection[0].srid).to eql(256)
176
+ end
177
+
178
+ end
@@ -0,0 +1,164 @@
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 GeoRuby::GeoJSONParser do
11
+
12
+ it 'should create a specified GeoRuby::SimpleFeatures::Point' do
13
+ point_json = %( { "type": "Point", "coordinates": [100.0, 0.0] } )
14
+ point = GeoRuby::SimpleFeatures::Geometry.from_geojson(point_json)
15
+ expect(point.class).to eql(GeoRuby::SimpleFeatures::Point)
16
+ point_hash = JSON.parse(point_json)
17
+ expect(point.to_coordinates).to eql(point_hash['coordinates'])
18
+ end
19
+
20
+ it 'should create a specified GeoRuby::SimpleFeatures::LineString' do
21
+ ls_json = %( { "type": "LineString", "coordinates": [ [100.0, 0.0], [101.0, 1.0] ]} )
22
+ line_string = GeoRuby::SimpleFeatures::Geometry.from_geojson(ls_json)
23
+ expect(line_string.class).to eql(GeoRuby::SimpleFeatures::LineString)
24
+ ls_hash = JSON.parse(ls_json)
25
+ expect(line_string.to_coordinates).to eql(ls_hash['coordinates'])
26
+ end
27
+
28
+ it 'should create a specified GeoRuby::SimpleFeatures::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 = GeoRuby::SimpleFeatures::Geometry.from_geojson(poly_json)
38
+ expect(polygon.class).to eql(GeoRuby::SimpleFeatures::Polygon)
39
+ expect(polygon.rings.size).to eql(2)
40
+ poly_hash = JSON.parse(poly_json)
41
+ expect(polygon.to_coordinates).to eql(poly_hash['coordinates'])
42
+ end
43
+
44
+ it 'should create a specified GeoRuby::SimpleFeatures::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 = GeoRuby::SimpleFeatures::Geometry.from_geojson(mp_json)
51
+ expect(multi_point.class).to eql(GeoRuby::SimpleFeatures::MultiPoint)
52
+ mp_hash = JSON.parse(mp_json)
53
+ expect(multi_point.to_coordinates).to eql(mp_hash['coordinates'])
54
+ end
55
+
56
+ it 'should create a specified GeoRuby::SimpleFeatures::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 = GeoRuby::SimpleFeatures::Geometry.from_geojson(mls_json)
66
+ expect(multi_ls.class).to eql(GeoRuby::SimpleFeatures::MultiLineString)
67
+ mls_hash = JSON.parse(mls_json)
68
+ expect(multi_ls.to_coordinates).to eql(mls_hash['coordinates'])
69
+ end
70
+
71
+ it 'should create a specifiead GeoRuby::SimpleFeatures::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 = GeoRuby::SimpleFeatures::Geometry.from_geojson(mpoly_json)
82
+ expect(mpoly.class).to eql(GeoRuby::SimpleFeatures::MultiPolygon)
83
+ mpoly_hash = JSON.parse(mpoly_json)
84
+ expect(mpoly.to_coordinates).to eql(mpoly_hash['coordinates'])
85
+ end
86
+
87
+ it 'should create a specified GeoRuby::SimpleFeatures::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 = GeoRuby::SimpleFeatures::Geometry.from_geojson(gcol_json)
101
+ expect(gcol.class).to eql(GeoRuby::SimpleFeatures::GeometryCollection)
102
+ gcol_hash = JSON.parse(gcol_json)
103
+ gcol.geometries.each_with_index do |g, i|
104
+ gh = gcol_hash['geometries'][i]
105
+ expect(g.class).to eql(GeoRuby::SimpleFeatures.const_get(gh['type']))
106
+ expect(g.to_coordinates).to 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 = GeoRuby::SimpleFeatures::Geometry.from_geojson(feature_json)
124
+ expect(f.class).to eql(GeoRuby::GeoJSONFeature)
125
+ feature_hash = JSON.parse(feature_json)
126
+ expect(f.id).to eql(feature_hash['id'])
127
+ expect(f.properties).to eql(feature_hash['properties'])
128
+ expect(f.geometry.class).to eql(GeoRuby::SimpleFeatures.const_get(feature_hash['geometry']['type']))
129
+ expect(f.geometry.to_coordinates).to 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 = GeoRuby::SimpleFeatures::Geometry.from_geojson(fcol_json)
135
+ expect(fcol.class).to eql(GeoRuby::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
+ expect(f.properties).to eql(fcol_hash['features'][i]['properties'])
141
+ expect(fg.class).to eql(GeoRuby::SimpleFeatures.const_get(fgh['type']))
142
+ expect(fg.to_coordinates).to eql(fgh['coordinates'])
143
+ end
144
+ end
145
+
146
+ it 'should export a feature as JSON' do
147
+ fcol_json = File.read(DATA_DIR + 'feature.json')
148
+ geojson = GeoRuby::SimpleFeatures::Geometry.from_geojson(fcol_json)
149
+ expect(geojson).to be_a(GeoRuby::GeoJSONFeature)
150
+
151
+ export = GeoRuby::SimpleFeatures::Geometry.from_geojson(geojson.to_json)
152
+ expect(geojson).to eq(export)
153
+ end
154
+
155
+ it 'should export a feature collection as JSON' do
156
+ fcol_json = File.read(DATA_DIR + 'feature_collection.json')
157
+ geojson = GeoRuby::SimpleFeatures::Geometry.from_geojson(fcol_json)
158
+ expect(geojson).to be_a(GeoRuby::GeoJSONFeatureCollection)
159
+
160
+ export = GeoRuby::SimpleFeatures::Geometry.from_geojson(geojson.to_json)
161
+ expect(geojson).to eq(export)
162
+ end
163
+
164
+ end