geos-extensions 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +3 -0
  3. data/Gemfile +17 -0
  4. data/Guardfile +17 -0
  5. data/MIT-LICENSE +1 -1
  6. data/README.rdoc +19 -91
  7. data/Rakefile +1 -12
  8. data/geos-extensions.gemspec +1 -9
  9. data/lib/geos-extensions.rb +1 -9
  10. data/lib/geos/coordinate_sequence.rb +92 -0
  11. data/lib/geos/extensions/version.rb +1 -1
  12. data/lib/geos/geometry.rb +252 -0
  13. data/lib/geos/geometry_collection.rb +60 -0
  14. data/lib/geos/geos_helper.rb +86 -72
  15. data/lib/geos/google_maps.rb +1 -0
  16. data/lib/geos/google_maps/api_2.rb +9 -23
  17. data/lib/geos/google_maps/api_3.rb +10 -24
  18. data/lib/geos/google_maps/api_common.rb +41 -0
  19. data/lib/geos/line_string.rb +15 -0
  20. data/lib/geos/multi_line_string.rb +15 -0
  21. data/lib/geos/multi_point.rb +15 -0
  22. data/lib/geos/multi_polygon.rb +27 -0
  23. data/lib/geos/point.rb +120 -0
  24. data/lib/geos/polygon.rb +158 -0
  25. data/lib/geos/yaml.rb +30 -0
  26. data/lib/geos/yaml/psych.rb +18 -0
  27. data/lib/geos/yaml/syck.rb +41 -0
  28. data/lib/geos_extensions.rb +110 -711
  29. data/test/google_maps_api_2_tests.rb +54 -32
  30. data/test/google_maps_api_3_tests.rb +58 -36
  31. data/test/google_maps_polyline_encoder_tests.rb +1 -1
  32. data/test/helper_tests.rb +28 -0
  33. data/test/misc_tests.rb +130 -10
  34. data/test/reader_tests.rb +38 -1
  35. data/test/test_helper.rb +54 -146
  36. data/test/writer_tests.rb +329 -10
  37. data/test/yaml_tests.rb +203 -0
  38. metadata +26 -102
  39. data/app/models/geos/geometry_column.rb +0 -39
  40. data/app/models/geos/spatial_ref_sys.rb +0 -12
  41. data/lib/geos/active_record_extensions.rb +0 -12
  42. data/lib/geos/active_record_extensions/connection_adapters/postgresql_adapter.rb +0 -151
  43. data/lib/geos/active_record_extensions/spatial_columns.rb +0 -367
  44. data/lib/geos/active_record_extensions/spatial_scopes.rb +0 -493
  45. data/lib/geos/rails/engine.rb +0 -6
  46. data/lib/tasks/test.rake +0 -42
  47. data/test/adapter_tests.rb +0 -38
  48. data/test/database.yml +0 -17
  49. data/test/fixtures/foo3ds.yml +0 -16
  50. data/test/fixtures/foo_geographies.yml +0 -16
  51. data/test/fixtures/foos.yml +0 -16
  52. data/test/geography_columns_tests.rb +0 -176
  53. data/test/geometry_columns_tests.rb +0 -178
  54. data/test/spatial_scopes_geographies_tests.rb +0 -107
  55. data/test/spatial_scopes_tests.rb +0 -337
@@ -2,7 +2,7 @@
2
2
  $: << File.dirname(__FILE__)
3
3
  require 'test_helper'
4
4
 
5
- class GeosReaderTests < Test::Unit::TestCase
5
+ class GeosReaderTests < MiniTest::Unit::TestCase
6
6
  include TestHelper
7
7
 
8
8
  def test_from_wkb_bin
@@ -181,4 +181,41 @@ class GeosReaderTests < Test::Unit::TestCase
181
181
 
182
182
  assert_equal('POINT (0 0)', Geos.read('BOX(0 0, 0 0)').to_wkt(:trim => true))
183
183
  end
184
+
185
+ def test_allowed
186
+ assert_raises(ArgumentError) do
187
+ Geos.read(Geos.read(POINT_WKT), :allowed => [])
188
+ end
189
+
190
+ assert_equal(
191
+ 'POINT (10 10.01)',
192
+ Geos.read(POINT_WKT, :allowed => :wkt).to_wkt(:trim => true)
193
+ )
194
+ end
195
+
196
+ def test_allowed_array
197
+ assert_equal(
198
+ 'POINT (10 10.01)',
199
+ Geos.read(POINT_WKT, :allowed => [ :wkt ]).to_wkt(:trim => true)
200
+ )
201
+ end
202
+
203
+ def test_excluded
204
+ assert_raises(ArgumentError) do
205
+ Geos.read(POINT_WKT, :excluded => :wkt)
206
+ end
207
+ end
208
+
209
+ def test_excluded_array
210
+ assert_raises(ArgumentError) do
211
+ Geos.read(POINT_WKT, :excluded => [ :wkt ])
212
+ end
213
+ end
214
+
215
+ def test_allowed_and_excluded
216
+ assert_raises(ArgumentError) do
217
+ Geos.read(POINT_WKT, :allowed => :wkt, :excluded => :wkt)
218
+ end
219
+ end
184
220
  end
221
+
@@ -1,33 +1,24 @@
1
1
 
2
- require 'rubygems'
3
- require 'test/unit'
4
-
5
- if ENV['TEST_ACTIVERECORD'] || defined?(IRB)
6
- ACTIVERECORD_GEM_VERSION = ENV['ACTIVERECORD_GEM_VERSION'] || '~> 3.2.0'
7
- gem 'activerecord', ACTIVERECORD_GEM_VERSION
8
-
9
- POSTGIS_PATHS = [
10
- ENV['POSTGIS_PATH'],
11
- '/opt/local/share/postgresql*/contrib/postgis-*',
12
- '/usr/share/postgresql*/contrib/postgis-*',
13
- '/usr/pgsql-*/share/contrib/postgis-*',
14
- ].compact
15
-
16
- puts "Testing against ActiveRecord #{Gem.loaded_specs['activerecord'].version.to_s}"
17
- require 'active_support'
18
- require 'active_support/core_ext/module/aliasing'
19
- require 'active_record'
20
- require 'active_record/fixtures'
21
- require 'logger'
22
-
23
- if ActiveRecord::VERSION::STRING < '3.0'
24
- require 'fake_arel'
2
+ if RUBY_VERSION >= '1.9'
3
+ require 'simplecov'
4
+
5
+ SimpleCov.command_name('Unit Tests')
6
+ SimpleCov.start do
7
+ add_filter '/test/'
25
8
  end
26
9
  end
27
10
 
28
- require File.join(File.dirname(__FILE__), %w{ .. lib geos_extensions })
11
+ require 'rubygems'
12
+ require 'forwardable'
13
+ require 'minitest/autorun'
14
+
15
+ if RUBY_VERSION >= '1.9'
16
+ require 'minitest/reporters'
17
+ end
18
+
19
+ require File.join(File.dirname(__FILE__), %w{ .. lib geos-extensions })
29
20
 
30
- puts "Ruby version #{RUBY_VERSION} - #{RbConfig::CONFIG['RUBY_INSTALL_NAME']}"
21
+ puts "Ruby version #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} - #{RbConfig::CONFIG['RUBY_INSTALL_NAME']}"
31
22
  puts "ffi version #{Gem.loaded_specs['ffi'].version}" if Gem.loaded_specs['ffi']
32
23
  puts "Geos library version #{Geos::VERSION}" if defined?(Geos::VERSION)
33
24
  puts "GEOS version #{Geos::GEOS_VERSION}"
@@ -36,115 +27,10 @@ if defined?(Geos::FFIGeos)
36
27
  puts "Using #{Geos::FFIGeos.geos_library_paths.join(', ')}"
37
28
  end
38
29
 
39
- if ENV['TEST_ACTIVERECORD'] || defined?(IRB)
40
- ActiveRecord::Base.logger = Logger.new("debug.log") if ENV['ENABLE_LOGGER']
41
- ActiveRecord::Base.configurations = {
42
- 'arunit' => {}
43
- }
44
-
45
- %w{
46
- database.yml
47
- local_database.yml
48
- }.each do |file|
49
- file = File.join('test', file)
50
-
51
- next unless File.exists?(file)
52
-
53
- configuration = YAML.load(File.read(file))
54
-
55
- if configuration['arunit']
56
- ActiveRecord::Base.configurations['arunit'].merge!(configuration['arunit'])
57
- end
58
-
59
- if defined?(JRUBY_VERSION) && configuration['jdbc']
60
- ActiveRecord::Base.configurations['arunit'].merge!(configuration['jdbc'])
61
- end
62
- end
63
-
64
- ActiveRecord::Base.establish_connection 'arunit'
65
- ARBC = ActiveRecord::Base.connection
66
-
67
- if postgresql_version = ARBC.select_rows('SELECT version()').first.first
68
- puts "PostgreSQL info from version(): #{postgresql_version}"
69
- end
70
-
71
- puts "Checking for PostGIS install"
72
- 2.times do
73
- begin
74
- if postgis_version = Geos::ActiveRecord.POSTGIS[:lib]
75
- puts "PostGIS info from postgis_full_version(): #{postgis_version}"
76
- break
77
- end
78
- rescue ActiveRecord::StatementInvalid
79
- puts "Trying to install PostGIS. If this doesn't work, you'll have to do this manually!"
80
-
81
- plpgsql = ARBC.select_rows(%{SELECT count(*) FROM pg_language WHERE lanname = 'plpgsql'}).first.first.to_i
82
- if plpgsql == 0
83
- ARBC.execute(%{CREATE LANGUAGE plpgsql})
84
- end
85
-
86
- %w{
87
- postgis.sql
88
- spatial_ref_sys.sql
89
- }.each do |file|
90
- if !(found = Dir.glob(POSTGIS_PATHS).collect { |path|
91
- File.join(path, file)
92
- }.first)
93
- puts "ERROR: Couldn't find #{file}. Try setting the POSTGIS_PATH to give us a hint!"
94
- exit
95
- else
96
- ARBC.execute(File.read(found))
97
- end
98
- end
99
- end
100
- end
101
-
102
- if !ARBC.table_exists?('foos')
103
- ActiveRecord::Migration.create_table(:foos) do |t|
104
- t.text :name
105
- end
106
-
107
- ARBC.execute(%{SELECT AddGeometryColumn('public', 'foos', 'the_geom', #{Geos::ActiveRecord.UNKNOWN_SRID}, 'GEOMETRY', 2)})
108
- ARBC.execute(%{SELECT AddGeometryColumn('public', 'foos', 'the_other_geom', 4326, 'GEOMETRY', 2)})
109
- end
110
-
111
- if !ARBC.table_exists?('foo3ds')
112
- ActiveRecord::Migration.create_table(:foo3ds) do |t|
113
- t.text :name
114
- end
115
-
116
- ARBC.execute(%{SELECT AddGeometryColumn('public', 'foo3ds', 'the_geom', #{Geos::ActiveRecord.UNKNOWN_SRID}, 'GEOMETRY', 3)})
117
- ARBC.execute(%{SELECT AddGeometryColumn('public', 'foo3ds', 'the_other_geom', 4326, 'GEOMETRY', 3)})
118
- end
119
-
120
- if !ARBC.table_exists?('foo_geographies')
121
- ActiveRecord::Migration.create_table(:foo_geographies) do |t|
122
- t.text :name
123
- t.column :the_geom, :geography
124
- t.column :the_other_geom, 'geography(Geometry, 4326)'
125
- end
126
- end
127
-
128
- class Foo < ActiveRecord::Base
129
- include Geos::ActiveRecord::SpatialColumns
130
- create_spatial_column_accessors!
131
- end
132
-
133
- class Foo3d < ActiveRecord::Base
134
- include Geos::ActiveRecord::SpatialColumns
135
- create_spatial_column_accessors!
136
- end
137
-
138
- class FooGeography < ActiveRecord::Base
139
- include Geos::ActiveRecord::SpatialColumns
140
- create_spatial_column_accessors!
141
- end
142
- end
143
-
144
30
  module TestHelper
31
+ DELTA_TOLERANCE = 1e-8
145
32
  POINT_WKT = 'POINT(10 10.01)'
146
33
  POINT_EWKT = 'SRID=4326; POINT(10 10.01)'
147
- POINT_EWKT_WITH_DEFAULT = 'SRID=default; POINT(10 10.01)'
148
34
  POINT_WKB = "0101000000000000000000244085EB51B81E052440"
149
35
  POINT_WKB_BIN = "\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x24\x40\x85\xEB\x51\xB8\x1E\x05\x24\x40"
150
36
  POINT_EWKB = "0101000020E6100000000000000000244085EB51B81E052440"
@@ -152,31 +38,31 @@ module TestHelper
152
38
  POINT_G_LAT_LNG = "(10.01, 10)"
153
39
  POINT_G_LAT_LNG_URL_VALUE = "10.01,10"
154
40
 
155
- POLYGON_WKT = 'POLYGON((0 0, 1 1, 2.5 2.5, 5 5, 0 0))'
156
- POLYGON_EWKT = 'SRID=4326; POLYGON((0 0, 1 1, 2.5 2.5, 5 5, 0 0))'
41
+ POLYGON_WKT = 'POLYGON((0 0, 0 1, 2.5 2.5, 5 2.5, 0 0))'
42
+ POLYGON_EWKT = 'SRID=4326; POLYGON((0 0, 0 1, 2.5 2.5, 5 2.5, 0 0))'
157
43
  POLYGON_WKB = "
158
- 0103000000010000000500000000000000000000000000000000000000000000000000F
159
- 03F000000000000F03F0000000000000440000000000000044000000000000014400000
160
- 00000000144000000000000000000000000000000000
44
+ 01030000000100000005000000000000000000000000000000000000000000000000000
45
+ 000000000000000F03F0000000000000440000000000000044000000000000014400000
46
+ 00000000044000000000000000000000000000000000
161
47
  ".gsub(/\s/, '')
162
48
  POLYGON_WKB_BIN = [
163
49
  "\x01\x03\x00\x00\x00\x01\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00",
164
- "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xF0\x3F\x00",
50
+ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
165
51
  "\x00\x00\x00\x00\x00\xF0\x3F\x00\x00\x00\x00\x00\x00\x04\x40\x00\x00\x00\x00",
166
- "\x00\x00\x04\x40\x00\x00\x00\x00\x00\x00\x14\x40\x00\x00\x00\x00\x00\x00\x14",
52
+ "\x00\x00\x04\x40\x00\x00\x00\x00\x00\x00\x14\x40\x00\x00\x00\x00\x00\x00\x04",
167
53
  "\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
168
54
  ].join
169
55
  POLYGON_EWKB = "
170
56
  0103000020E610000001000000050000000000000000000000000000000000000000000
171
- 0000000F03F000000000000F03F00000000000004400000000000000440000000000000
172
- 1440000000000000144000000000000000000000000000000000
57
+ 00000000000000000000000F03F00000000000004400000000000000440000000000000
58
+ 1440000000000000044000000000000000000000000000000000
173
59
  ".gsub(/\s/, '')
174
60
  POLYGON_EWKB_BIN = [
175
61
  "\x01\x03\x00\x00\x20\xE6\x10\x00\x00\x01\x00\x00\x00\x05\x00\x00\x00",
176
62
  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
177
- "\x00\x00\x00\x00\x00\xF0\x3F\x00\x00\x00\x00\x00\x00\xF0\x3F\x00\x00",
63
+ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xF0\x3F\x00\x00",
178
64
  "\x00\x00\x00\x00\x04\x40\x00\x00\x00\x00\x00\x00\x04\x40\x00\x00\x00",
179
- "\x00\x00\x00\x14\x40\x00\x00\x00\x00\x00\x00\x14\x40\x00\x00\x00\x00",
65
+ "\x00\x00\x00\x14\x40\x00\x00\x00\x00\x00\x00\x04\x40\x00\x00\x00\x00",
180
66
  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
181
67
  ].join
182
68
 
@@ -200,9 +86,26 @@ module TestHelper
200
86
  POINT (9 0)
201
87
  )'
202
88
 
89
+ MULTIPOINT_WKT = "MULTIPOINT((0 0), (10 10))"
90
+
91
+ MULTIPOLYGON_WKT = "MULTIPOLYGON(
92
+ ((0 0, 5 0, 5 5, 0 5, 0 0),(4 4, 4 1, 1 1, 1 4, 4 4)),
93
+ ((10 10, 15 10, 15 15, 10 15, 10 10),(14 14, 14 11, 11 11, 11 14, 14 14))
94
+ )"
95
+
96
+ MULTILINESTRING_WKT = "MULTILINESTRING((-20 -20, 10 10), (0 0, 30 30))"
97
+
203
98
  BOUNDS_G_LAT_LNG = "((0.1, 0.1), (5.2, 5.2))"
204
99
  BOUNDS_G_LAT_LNG_URL_VALUE = '0.1,0.1,5.2,5.2'
205
100
 
101
+ if String.method_defined?(:force_encoding)
102
+ POINT_WKB_BIN.force_encoding('BINARY')
103
+ POINT_EWKB_BIN.force_encoding('BINARY')
104
+
105
+ POLYGON_WKB_BIN.force_encoding('BINARY')
106
+ POLYGON_EWKB_BIN.force_encoding('BINARY')
107
+ end
108
+
206
109
  def assert_saneness_of_point(point)
207
110
  assert_kind_of(Geos::Point, point)
208
111
  assert_equal(10.01, point.lat)
@@ -213,11 +116,16 @@ module TestHelper
213
116
  assert_kind_of(Geos::Polygon, polygon)
214
117
  cs = polygon.exterior_ring.coord_seq
215
118
  assert_equal([
216
- [ 0, 0 ],
217
- [ 1, 1 ],
119
+ [ 0.0, 0.0 ],
120
+ [ 0.0, 1.0 ],
218
121
  [ 2.5, 2.5 ],
219
- [ 5, 5 ],
220
- [ 0, 0 ]
122
+ [ 5.0, 2.5 ],
123
+ [ 0.0, 0.0 ]
221
124
  ], cs.to_a)
222
125
  end
223
126
  end
127
+
128
+ if RUBY_VERSION >= '1.9'
129
+ MiniTest::Reporters.use!(MiniTest::Reporters::SpecReporter.new)
130
+ end
131
+
@@ -9,12 +9,23 @@ rescue LoadError
9
9
  # do nothing
10
10
  end
11
11
 
12
- class GeosWriterTests < Test::Unit::TestCase
12
+ begin
13
+ require 'json'
14
+ rescue LoadError
15
+ # do nothing
16
+ end
17
+
18
+ class GeosWriterTests < MiniTest::Unit::TestCase
13
19
  include TestHelper
14
20
 
15
21
  def initialize(*args)
16
22
  @point = Geos.read(POINT_EWKB)
17
23
  @polygon = Geos.read(POLYGON_EWKB)
24
+ @linestring = Geos.read(LINESTRING_WKT)
25
+ @multipoint = Geos.read(MULTIPOINT_WKT)
26
+ @multipolygon = Geos.read(MULTIPOLYGON_WKT)
27
+ @multilinestring = Geos.read(MULTILINESTRING_WKT)
28
+ @geometrycollection = Geos.read(GEOMETRYCOLLECTION_WKT)
18
29
  super(*args)
19
30
  end
20
31
 
@@ -77,7 +88,7 @@ class GeosWriterTests < Test::Unit::TestCase
77
88
  end
78
89
 
79
90
  def test_to_flickr_bbox
80
- assert_equal('0.0,0.0,5.0,5.0', @polygon.to_flickr_bbox)
91
+ assert_equal('0.0,0.0,5.0,2.5', @polygon.to_flickr_bbox)
81
92
  end
82
93
 
83
94
  if defined?(Builder::XmlMarkup)
@@ -102,7 +113,7 @@ class GeosWriterTests < Test::Unit::TestCase
102
113
  })
103
114
  out.rewind
104
115
 
105
- assert_equal("<Polygon id=\"\"><extrude>true</extrude><altitudeMode>relativeToGround</altitudeMode><outerBoundaryIs><LinearRing><coordinates>0.0,0.0 1.0,1.0 2.5,2.5 5.0,5.0 0.0,0.0</coordinates></LinearRing></outerBoundaryIs></Polygon>",
116
+ assert_equal("<Polygon id=\"\"><extrude>true</extrude><altitudeMode>relativeToGround</altitudeMode><outerBoundaryIs><LinearRing><coordinates>0.0,0.0 0.0,1.0 2.5,2.5 5.0,2.5 0.0,0.0</coordinates></LinearRing></outerBoundaryIs></Polygon>",
106
117
  out.read
107
118
  )
108
119
  end
@@ -156,11 +167,11 @@ class GeosWriterTests < Test::Unit::TestCase
156
167
  assert_equal({
157
168
  "type" => "LineString",
158
169
  "coordinates" => [
159
- [0.0, 0.0],
160
- [1.0, 1.0],
161
- [2.5, 2.5],
162
- [5.0, 5.0],
163
- [0.0, 0.0]
170
+ [ 0.0, 0.0 ],
171
+ [ 0.0, 1.0 ],
172
+ [ 2.5, 2.5 ],
173
+ [ 5.0, 2.5 ],
174
+ [ 0.0, 0.0 ]
164
175
  ]
165
176
  }, JSON.load(json))
166
177
  end
@@ -174,9 +185,9 @@ class GeosWriterTests < Test::Unit::TestCase
174
185
  "coordinates" => [
175
186
  [
176
187
  [0.0, 0.0],
177
- [1.0, 1.0],
188
+ [0.0, 1.0],
178
189
  [2.5, 2.5],
179
- [5.0, 5.0],
190
+ [5.0, 2.5],
180
191
  [0.0, 0.0]
181
192
  ]
182
193
  ]
@@ -358,4 +369,312 @@ class GeosWriterTests < Test::Unit::TestCase
358
369
  }, JSON.load(collection.to_geojson(:interior_rings => false)))
359
370
  end
360
371
  end
372
+
373
+ def test_to_box2d
374
+ assert_equal("BOX(10.0 10.01, 10.0 10.01)", @point.to_box2d)
375
+ assert_equal("BOX(0.0 0.0, 5.0 2.5)", @polygon.to_box2d)
376
+ assert_equal("BOX(0.0 0.0, 10.0 10.0)", @linestring.to_box2d)
377
+ assert_equal("BOX(0.0 0.0, 10.0 10.0)", @multipoint.to_box2d)
378
+ assert_equal("BOX(0.0 0.0, 15.0 15.0)", @multipolygon.to_box2d)
379
+ assert_equal("BOX(-20.0 -20.0, 30.0 30.0)", @multilinestring.to_box2d)
380
+ assert_equal("BOX(0.0 0.0, 14.0 14.0)", @geometrycollection.to_box2d)
381
+ end
382
+
383
+ def test_as_json
384
+ assert_equal({
385
+ :type => "point",
386
+ :lat => 10.01,
387
+ :lng => 10.0
388
+ }, @point.as_json)
389
+
390
+ assert_equal({
391
+ :type => "polygon",
392
+ :encoded => true,
393
+ :polylines => [ {
394
+ :points => "??_ibE?_~cH_hgN?_hgN~ggN~po]",
395
+ :levels => "BBBBB",
396
+ :bounds => {
397
+ :sw => [ 0.0, 0.0 ],
398
+ :ne => [ 5.0, 2.5 ]
399
+ }
400
+ } ],
401
+ :options => {}
402
+ }, @polygon.as_json)
403
+
404
+ assert_equal({
405
+ :type => "polygon",
406
+ :encoded => false,
407
+ :polylines => [ {
408
+ :points => [ [ 0.0, 0.0 ], [ 0.0, 1.0 ], [ 2.5, 2.5 ], [ 5.0, 2.5 ], [ 0.0, 0.0 ] ],
409
+ :bounds => {
410
+ :sw => [ 0.0, 0.0 ],
411
+ :ne => [ 5.0, 2.5 ]
412
+ }
413
+ } ]
414
+ }, @polygon.as_json(:encoded => false))
415
+
416
+ assert_equal({
417
+ :type => "lineString",
418
+ :encoded => true,
419
+ :points => "??_qo]_qo]_qo]??_qo]",
420
+ :levels => "BBBB"
421
+ }, @linestring.as_json)
422
+
423
+ assert_equal({
424
+ :type => "lineString",
425
+ :encoded => false,
426
+ :points => [ [ 0.0, 0.0 ], [ 5.0, 5.0 ], [ 5.0, 10.0 ], [ 10.0, 10.0 ] ]
427
+ }, @linestring.as_json(:encoded => false))
428
+
429
+ assert_equal([ {
430
+ :type => "point",
431
+ :lat => 0.0,
432
+ :lng => 0.0
433
+ }, {
434
+ :type => "point",
435
+ :lat => 10.0,
436
+ :lng => 10.0
437
+ } ], @multipoint.as_json)
438
+
439
+ assert_equal([ {
440
+ :type => "polygon",
441
+ :encoded => true,
442
+ :polylines => [ {
443
+ :points => "???_qo]_qo]??~po]~po]?",
444
+ :levels => "BBBBB",
445
+ :bounds => {
446
+ :sw => [ 0.0, 0.0 ],
447
+ :ne => [ 5.0, 5.0 ]
448
+ }
449
+ } ],
450
+ :options => {}
451
+ }, {
452
+ :type => "polygon",
453
+ :encoded => true,
454
+ :polylines => [ {
455
+ :points => "_c`|@_c`|@?_qo]_qo]??~po]~po]?",
456
+ :levels => "BBBBB",
457
+ :bounds => {
458
+ :sw => [ 10.0, 10.0 ],
459
+ :ne => [ 15.0, 15.0 ]
460
+ }
461
+ } ],
462
+ :options => {}
463
+ } ], @multipolygon.as_json)
464
+
465
+ assert_equal([ {
466
+ :type => "polygon",
467
+ :encoded => false,
468
+ :polylines => [ {
469
+ :points => [ [ 0.0, 0.0 ], [ 5.0, 0.0 ], [ 5.0, 5.0 ], [ 0.0, 5.0 ], [ 0.0, 0.0 ] ],
470
+ :bounds => {
471
+ :sw => [ 0.0, 0.0 ],
472
+ :ne => [ 5.0, 5.0 ]
473
+ }
474
+ } ]
475
+ }, {
476
+ :type => "polygon",
477
+ :encoded => false,
478
+ :polylines => [ {
479
+ :points => [ [ 10.0, 10.0 ], [ 15.0, 10.0 ], [ 15.0, 15.0 ], [ 10.0, 15.0 ], [ 10.0, 10.0 ] ],
480
+ :bounds => {
481
+ :sw => [ 10.0, 10.0 ],
482
+ :ne => [ 15.0, 15.0 ]
483
+ }
484
+ } ]
485
+ } ], @multipolygon.as_json(:encoded => false))
486
+
487
+ assert_equal([ {
488
+ :type => "lineString",
489
+ :encoded => true,
490
+ :points => "~fayB~fayB_kbvD_kbvD",
491
+ :levels => "BB"
492
+ }, {
493
+ :type => "lineString",
494
+ :encoded => true,
495
+ :points => "??_kbvD_kbvD",
496
+ :levels => "BB"
497
+ } ], @multilinestring.as_json)
498
+
499
+ assert_equal([{
500
+ :type => "lineString",
501
+ :encoded => false,
502
+ :points => [ [ -20.0, -20.0 ], [ 10.0, 10.0 ] ]
503
+ }, {
504
+ :type => "lineString",
505
+ :encoded => false,
506
+ :points => [ [ 0.0, 0.0 ], [ 30.0, 30.0 ] ]
507
+ } ], @multilinestring.as_json(:encoded => false))
508
+
509
+ assert_equal([
510
+ [ {
511
+ :type => "polygon",
512
+ :encoded => true,
513
+ :polylines => [ {
514
+ :points => "???_ibE_ibE??~hbE~hbE?",
515
+ :levels => "BBBBB",
516
+ :bounds => {
517
+ :sw => [ 0.0, 0.0 ],
518
+ :ne => [ 1.0, 1.0 ]
519
+ }
520
+ } ],
521
+ :options => {}
522
+ }, {
523
+ :type => "polygon",
524
+ :encoded => true,
525
+ :polylines => [ {
526
+ :points => "_c`|@_c`|@_glW??_glW~flW??~flW",
527
+ :levels => "BBBBB",
528
+ :bounds => {
529
+ :sw => [ 10.0, 10.0 ],
530
+ :ne => [ 14.0, 14.0 ]
531
+ }
532
+ } ],
533
+ :options => {}
534
+ } ],
535
+
536
+ {
537
+ :type => "polygon",
538
+ :encoded => true,
539
+ :polylines => [ {
540
+ :points => "???_ibE_ibE??~hbE~hbE?",
541
+ :levels => "BBBBB",
542
+ :bounds => {
543
+ :sw => [ 0.0, 0.0 ],
544
+ :ne => [ 1.0, 1.0 ]
545
+ }
546
+ } ],
547
+ :options => {}
548
+ }, {
549
+ :type => "polygon",
550
+ :encoded => true,
551
+ :polylines => [ {
552
+ :points => "???_qo]_qo]??~po]~po]?",
553
+ :levels => "BBBBB",
554
+ :bounds => {
555
+ :sw => [ 0.0, 0.0 ],
556
+ :ne => [ 5.0, 5.0 ]
557
+ }
558
+ } ],
559
+ :options => {}
560
+ },
561
+
562
+ [ {
563
+ :type => "lineString",
564
+ :encoded => true,
565
+ :points => "??_}hQ_seK",
566
+ :levels => "BB"
567
+ }, {
568
+ :type => "lineString",
569
+ :encoded => true,
570
+ :points => "_c`|@_c`|@~zrc@~dvi@",
571
+ :levels => "BB"
572
+ } ],
573
+
574
+ {
575
+ :type => "lineString",
576
+ :encoded => true,
577
+ :points => "??_}hQ_seK",
578
+ :levels => "BB"
579
+ },
580
+
581
+ [ {
582
+ :type => "point",
583
+ :lat => 0.0,
584
+ :lng => 0.0
585
+ }, {
586
+ :type => "point",
587
+ :lat => 3.0,
588
+ :lng => 2.0
589
+ } ],
590
+
591
+ {
592
+ :type => "point",
593
+ :lat => 0.0,
594
+ :lng => 9.0
595
+ }
596
+ ], @geometrycollection.as_json)
597
+
598
+ assert_equal([
599
+ [ {
600
+ :type => "polygon",
601
+ :encoded => false,
602
+ :polylines => [ {
603
+ :points => [ [ 0.0, 0.0], [ 1.0, 0.0], [ 1.0, 1.0], [ 0.0, 1.0], [ 0.0, 0.0 ] ],
604
+ :bounds => {
605
+ :sw => [ 0.0, 0.0 ],
606
+ :ne => [ 1.0, 1.0 ]
607
+ }
608
+ } ]
609
+ },
610
+
611
+ {
612
+ :type => "polygon",
613
+ :encoded => false,
614
+ :polylines => [ {
615
+ :points => [ [ 10.0, 10.0 ], [ 10.0, 14.0 ], [ 14.0, 14.0 ], [ 14.0, 10.0 ], [ 10.0, 10.0 ] ],
616
+ :bounds => {
617
+ :sw => [ 10.0, 10.0 ],
618
+ :ne => [ 14.0, 14.0 ]
619
+ }
620
+ } ]
621
+ } ],
622
+
623
+ {
624
+ :type => "polygon",
625
+ :encoded => false,
626
+ :polylines => [ {
627
+ :points => [ [ 0.0, 0.0 ], [ 1.0, 0.0 ], [ 1.0, 1.0 ], [ 0.0, 1.0 ], [ 0.0, 0.0 ] ],
628
+ :bounds => {
629
+ :sw => [ 0.0, 0.0 ],
630
+ :ne => [ 1.0, 1.0 ]
631
+ }
632
+ } ]
633
+ },
634
+
635
+ {
636
+ :type => "polygon",
637
+ :encoded => false,
638
+ :polylines => [ {
639
+ :points => [ [ 0.0, 0.0 ], [ 5.0, 0.0 ], [ 5.0, 5.0 ], [ 0.0, 5.0 ], [ 0.0, 0.0 ] ],
640
+ :bounds => {
641
+ :sw => [ 0.0, 0.0 ],
642
+ :ne => [ 5.0, 5.0 ]
643
+ }
644
+ } ]
645
+ },
646
+
647
+ [ {
648
+ :type => "lineString",
649
+ :encoded => false,
650
+ :points => [ [ 0.0, 0.0 ], [ 2.0, 3.0 ] ]
651
+ }, {
652
+ :type => "lineString",
653
+ :encoded => false,
654
+ :points => [ [ 10.0, 10.0 ], [ 3.0, 4.0 ] ]
655
+ } ],
656
+
657
+ {
658
+ :type => "lineString",
659
+ :encoded => false,
660
+ :points => [ [ 0.0, 0.0 ], [ 2.0, 3.0 ] ]
661
+ },
662
+
663
+ [ {
664
+ :type => "point",
665
+ :lat => 0.0,
666
+ :lng => 0.0
667
+ }, {
668
+ :type => "point",
669
+ :lat => 3.0,
670
+ :lng => 2.0
671
+ } ],
672
+
673
+ {
674
+ :type => "point",
675
+ :lat => 0.0,
676
+ :lng => 9.0
677
+ }
678
+ ], @geometrycollection.as_json(:encoded => false))
679
+ end
361
680
  end