rgeo 0.3.5 → 0.3.6

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.
Files changed (43) hide show
  1. data/History.rdoc +11 -0
  2. data/Version +1 -1
  3. data/ext/geos_c_impl/factory.c +134 -3
  4. data/ext/geos_c_impl/factory.h +5 -0
  5. data/ext/geos_c_impl/geometry_collection.c +18 -12
  6. data/lib/rgeo/cartesian/factory.rb +40 -33
  7. data/lib/rgeo/cartesian/interface.rb +6 -0
  8. data/lib/rgeo/coord_sys/cs/entities.rb +4 -4
  9. data/lib/rgeo/coord_sys/proj4.rb +5 -5
  10. data/lib/rgeo/coord_sys/srs_database/active_record_table.rb +5 -3
  11. data/lib/rgeo/feature/geometry.rb +8 -1
  12. data/lib/rgeo/geographic/factory.rb +124 -1
  13. data/lib/rgeo/geographic/interface.rb +6 -0
  14. data/lib/rgeo/geographic/proj4_projector.rb +6 -0
  15. data/lib/rgeo/geographic/simple_mercator_projector.rb +6 -0
  16. data/lib/rgeo/geos/factory.rb +119 -18
  17. data/lib/rgeo/geos/ffi_classes.rb +10 -5
  18. data/lib/rgeo/geos/ffi_factory.rb +106 -5
  19. data/lib/rgeo/geos/interface.rb +0 -2
  20. data/lib/rgeo/geos/zm_factory.rb +106 -2
  21. data/lib/rgeo/geos/zm_impl.rb +3 -2
  22. data/lib/rgeo/impl_helper.rb +1 -0
  23. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +1 -1
  24. data/lib/rgeo/impl_helper/utils.rb +67 -0
  25. data/lib/rgeo/wkrep/wkb_generator.rb +4 -4
  26. data/lib/rgeo/wkrep/wkb_parser.rb +4 -4
  27. data/lib/rgeo/wkrep/wkt_generator.rb +4 -4
  28. data/lib/rgeo/wkrep/wkt_parser.rb +5 -5
  29. data/test/common/factory_tests.rb +117 -0
  30. data/test/common/geometry_collection_tests.rb +25 -0
  31. data/test/coord_sys/tc_active_record_table.rb +4 -5
  32. data/test/coord_sys/tc_ogc_cs.rb +0 -6
  33. data/test/coord_sys/tc_proj4.rb +4 -6
  34. data/test/geos_capi/tc_factory.rb +5 -33
  35. data/test/geos_capi/tc_zmfactory.rb +6 -0
  36. data/test/geos_ffi/tc_factory.rb +5 -33
  37. data/test/geos_ffi/tc_zmfactory.rb +6 -0
  38. data/test/projected_geographic/tc_factory.rb +63 -0
  39. data/test/simple_cartesian/tc_factory.rb +66 -0
  40. data/test/simple_mercator/tc_factory.rb +63 -0
  41. data/test/spherical_geographic/tc_factory.rb +66 -0
  42. data/test/tc_types.rb +4 -0
  43. metadata +12 -2
@@ -245,6 +245,31 @@ module RGeo
245
245
  end
246
246
 
247
247
 
248
+ def test_each_block
249
+ geom1_ = @factory.collection([@point1, @line1])
250
+ i_ = 0
251
+ geom1_.each do |g_|
252
+ if i_ == 0
253
+ assert_equal(@point1, g_)
254
+ else
255
+ assert_equal(@line1, g_)
256
+ end
257
+ i_ += 1
258
+ end
259
+ end
260
+
261
+
262
+ def test_each_enumerator
263
+ geom1_ = @factory.collection([@point1, @line1])
264
+ enum_ = geom1_.each
265
+ assert_equal(@point1, enum_.next)
266
+ assert_equal(@line1, enum_.next)
267
+ assert_raise(::StopIteration) do
268
+ enum_.next
269
+ end
270
+ end
271
+
272
+
248
273
  end
249
274
 
250
275
  end
@@ -62,11 +62,10 @@ module RGeo
62
62
 
63
63
  class TestPostGIS < ::Test::Unit::TestCase # :nodoc:
64
64
 
65
- class ARBase < ::ActiveRecord::Base
66
- establish_connection(PostGIS_CONFIG)
67
- end
68
-
69
- @@db = ::RGeo::CoordSys::SRSDatabase::ActiveRecordTable.new(:ar_base_class => ARBase, :auth_name_column => 'auth_name', :auth_srid_column => 'auth_srid', :srtext_column => 'srtext', :proj4text_column => 'proj4text')
65
+ @@db = ::RGeo::CoordSys::SRSDatabase::ActiveRecordTable.new(
66
+ :database_config => PostGIS_CONFIG,
67
+ :auth_name_column => 'auth_name', :auth_srid_column => 'auth_srid',
68
+ :srtext_column => 'srtext', :proj4text_column => 'proj4text')
70
69
 
71
70
 
72
71
  def test_4326
@@ -371,7 +371,6 @@ module RGeo
371
371
 
372
372
  if ::RGeo.yaml_supported?
373
373
 
374
-
375
374
  def test_yaml_roundtrip
376
375
  input_ = 'COMPD_CS["OSGB36 / British National Grid + ODN",PROJCS["OSGB 1936 / British National Grid",GEOGCS["OSGB 1936",DATUM["OSGB 1936",SPHEROID["Airy 1830",6377563.396,299.3249646,AUTHORITY["EPSG","7001"]],TOWGS84[446.448,-125.157,542.06,0.15,0.247,0.842,-4.2261596151967575],AUTHORITY["EPSG","6277"]],PRIMEM["Greenwich",0.0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.017453292519943295],AXIS["Geodetic latitude",NORTH],AXIS["Geodetic longitude",EAST],AUTHORITY["EPSG","4277"]],PROJECTION["Transverse Mercator",AUTHORITY["EPSG","9807"]],PARAMETER["central_meridian",-2.0],PARAMETER["latitude_of_origin",49.0],PARAMETER["scale_factor",0.9996012717],PARAMETER["false_easting",400000.0],PARAMETER["false_northing",-100000.0],UNIT["m",1.0],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","27700"]],VERT_CS["Newlyn",VERT_DATUM["Ordnance Datum Newlyn",2005,AUTHORITY["EPSG","5101"]],UNIT["m",1.0],AXIS["Gravity-related height",UP],AUTHORITY["EPSG","5701"]],AUTHORITY["EPSG","7405"]]'
377
376
  obj1_ = ::RGeo::CoordSys::CS.create_from_wkt(input_)
@@ -380,11 +379,6 @@ module RGeo
380
379
  assert_equal(obj1_, obj2_)
381
380
  end
382
381
 
383
-
384
- else
385
-
386
- puts "WARNING: Psych not installed. Skipping YAML tests."
387
-
388
382
  end
389
383
 
390
384
 
@@ -170,7 +170,6 @@ module RGeo
170
170
 
171
171
  if ::RGeo.yaml_supported?
172
172
 
173
-
174
173
  def test_yaml_roundtrip
175
174
  obj1_ = ::RGeo::CoordSys::Proj4.create('+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')
176
175
  dump_ = ::Psych.dump(obj1_)
@@ -178,11 +177,6 @@ module RGeo
178
177
  assert_equal(obj1_, obj2_)
179
178
  end
180
179
 
181
-
182
- else
183
-
184
- puts "WARNING: Psych not installed. Skipping YAML tests."
185
-
186
180
  end
187
181
 
188
182
 
@@ -191,3 +185,7 @@ module RGeo
191
185
  end
192
186
  end
193
187
  end if ::RGeo::CoordSys::Proj4.supported?
188
+
189
+ unless ::RGeo::CoordSys::Proj4.supported?
190
+ puts "WARNING: Proj4 support not available. Related tests skipped."
191
+ end
@@ -37,6 +37,8 @@
37
37
  require 'test/unit'
38
38
  require 'rgeo'
39
39
 
40
+ require ::File.expand_path('../common/factory_tests.rb', ::File.dirname(__FILE__))
41
+
40
42
 
41
43
  module RGeo
42
44
  module Tests # :nodoc:
@@ -46,42 +48,12 @@ module RGeo
46
48
 
47
49
 
48
50
  def setup
49
- @factory = ::RGeo::Geos.factory(:srid => 4326)
50
- end
51
-
52
-
53
- def test_srid_preserved_through_factory
54
- geom_ = @factory.point(-10, 20)
55
- assert_equal(4326, geom_.srid)
56
- factory_ = geom_.factory
57
- assert_equal(4326, factory_.srid)
58
- geom2_ = factory_.point(-20, 25)
59
- assert_equal(4326, geom2_.srid)
51
+ @factory = ::RGeo::Geos.factory(:srid => 1000)
52
+ @srid = 1000
60
53
  end
61
54
 
62
55
 
63
- def test_srid_preserved_through_geom_operations
64
- geom1_ = @factory.point(-10, 20)
65
- geom2_ = @factory.point(-20, 25)
66
- geom3_ = geom1_.union(geom2_)
67
- assert_equal(4326, geom3_.srid)
68
- assert_equal(4326, geom3_.geometry_n(0).srid)
69
- assert_equal(4326, geom3_.geometry_n(1).srid)
70
- end
71
-
72
-
73
- def test_srid_preserved_through_geom_functions
74
- geom1_ = @factory.point(-10, 20)
75
- geom2_ = geom1_.boundary
76
- assert_equal(4326, geom2_.srid)
77
- end
78
-
79
-
80
- def test_srid_preserved_through_dup
81
- geom1_ = @factory.point(-10, 20)
82
- geom2_ = geom1_.clone
83
- assert_equal(4326, geom2_.srid)
84
- end
56
+ include ::RGeo::Tests::Common::FactoryTests
85
57
 
86
58
 
87
59
  end
@@ -37,6 +37,8 @@
37
37
  require 'test/unit'
38
38
  require 'rgeo'
39
39
 
40
+ require ::File.expand_path('../common/factory_tests.rb', ::File.dirname(__FILE__))
41
+
40
42
 
41
43
  module RGeo
42
44
  module Tests # :nodoc:
@@ -47,9 +49,13 @@ module RGeo
47
49
 
48
50
  def setup
49
51
  @factory = ::RGeo::Geos.factory(:has_z_coordinate => true, :has_m_coordinate => true, :srid => 1000, :buffer_resolution => 2)
52
+ @srid = 1000
50
53
  end
51
54
 
52
55
 
56
+ include ::RGeo::Tests::Common::FactoryTests
57
+
58
+
53
59
  def test_factory_parts
54
60
  assert_equal(1000, @factory.srid)
55
61
  assert_equal(1000, @factory.z_factory.srid)
@@ -37,6 +37,8 @@
37
37
  require 'test/unit'
38
38
  require 'rgeo'
39
39
 
40
+ require ::File.expand_path('../common/factory_tests.rb', ::File.dirname(__FILE__))
41
+
40
42
 
41
43
  module RGeo
42
44
  module Tests # :nodoc:
@@ -46,42 +48,12 @@ module RGeo
46
48
 
47
49
 
48
50
  def setup
49
- @factory = ::RGeo::Geos.factory(:srid => 4326, :native_interface => :ffi)
50
- end
51
-
52
-
53
- def test_srid_preserved_through_factory
54
- geom_ = @factory.point(-10, 20)
55
- assert_equal(4326, geom_.srid)
56
- factory_ = geom_.factory
57
- assert_equal(4326, factory_.srid)
58
- geom2_ = factory_.point(-20, 25)
59
- assert_equal(4326, geom2_.srid)
51
+ @factory = ::RGeo::Geos.factory(:srid => 1000, :native_interface => :ffi)
52
+ @srid = 1000
60
53
  end
61
54
 
62
55
 
63
- def test_srid_preserved_through_geom_operations
64
- geom1_ = @factory.point(-10, 20)
65
- geom2_ = @factory.point(-20, 25)
66
- geom3_ = geom1_.union(geom2_)
67
- assert_equal(4326, geom3_.srid)
68
- assert_equal(4326, geom3_.geometry_n(0).srid)
69
- assert_equal(4326, geom3_.geometry_n(1).srid)
70
- end
71
-
72
-
73
- def test_srid_preserved_through_geom_functions
74
- geom1_ = @factory.point(-10, 20)
75
- geom2_ = geom1_.boundary
76
- assert_equal(4326, geom2_.srid)
77
- end
78
-
79
-
80
- def test_srid_preserved_through_dup
81
- geom1_ = @factory.point(-10, 20)
82
- geom2_ = geom1_.clone
83
- assert_equal(4326, geom2_.srid)
84
- end
56
+ include ::RGeo::Tests::Common::FactoryTests
85
57
 
86
58
 
87
59
  end
@@ -37,6 +37,8 @@
37
37
  require 'test/unit'
38
38
  require 'rgeo'
39
39
 
40
+ require ::File.expand_path('../common/factory_tests.rb', ::File.dirname(__FILE__))
41
+
40
42
 
41
43
  module RGeo
42
44
  module Tests # :nodoc:
@@ -48,9 +50,13 @@ module RGeo
48
50
  def setup
49
51
  @factory = ::RGeo::Geos.factory(:has_z_coordinate => true, :has_m_coordinate => true,
50
52
  :srid => 1000, :buffer_resolution => 2, :native_interface => :ffi)
53
+ @srid = 1000
51
54
  end
52
55
 
53
56
 
57
+ include ::RGeo::Tests::Common::FactoryTests
58
+
59
+
54
60
  def test_factory_parts
55
61
  assert_equal(1000, @factory.srid)
56
62
  assert_equal(1000, @factory.z_factory.srid)
@@ -0,0 +1,63 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Tests for the GEOS factory
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+ # Copyright 2010-2012 Daniel Azuma
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Redistribution and use in source and binary forms, with or without
11
+ # modification, are permitted provided that the following conditions are met:
12
+ #
13
+ # * Redistributions of source code must retain the above copyright notice,
14
+ # this list of conditions and the following disclaimer.
15
+ # * Redistributions in binary form must reproduce the above copyright notice,
16
+ # this list of conditions and the following disclaimer in the documentation
17
+ # and/or other materials provided with the distribution.
18
+ # * Neither the name of the copyright holder, nor the names of any other
19
+ # contributors to this software, may be used to endorse or promote products
20
+ # derived from this software without specific prior written permission.
21
+ #
22
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ # POSSIBILITY OF SUCH DAMAGE.
33
+ # -----------------------------------------------------------------------------
34
+ ;
35
+
36
+
37
+ require 'test/unit'
38
+ require 'rgeo'
39
+
40
+ require ::File.expand_path('../common/factory_tests.rb', ::File.dirname(__FILE__))
41
+
42
+
43
+ module RGeo
44
+ module Tests # :nodoc:
45
+ module ProjectedGeographic # :nodoc:
46
+
47
+ class TestFactory < ::Test::Unit::TestCase # :nodoc:
48
+
49
+
50
+ def setup
51
+ @factory = ::RGeo::Geographic.projected_factory(:projection_proj4 => '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs', :projection_srid => 3857)
52
+ @srid = 4326
53
+ end
54
+
55
+
56
+ include ::RGeo::Tests::Common::FactoryTests
57
+
58
+
59
+ end
60
+
61
+ end
62
+ end
63
+ end if ::RGeo::CoordSys::Proj4.supported?
@@ -0,0 +1,66 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Tests for the GEOS factory
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+ # Copyright 2010-2012 Daniel Azuma
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Redistribution and use in source and binary forms, with or without
11
+ # modification, are permitted provided that the following conditions are met:
12
+ #
13
+ # * Redistributions of source code must retain the above copyright notice,
14
+ # this list of conditions and the following disclaimer.
15
+ # * Redistributions in binary form must reproduce the above copyright notice,
16
+ # this list of conditions and the following disclaimer in the documentation
17
+ # and/or other materials provided with the distribution.
18
+ # * Neither the name of the copyright holder, nor the names of any other
19
+ # contributors to this software, may be used to endorse or promote products
20
+ # derived from this software without specific prior written permission.
21
+ #
22
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ # POSSIBILITY OF SUCH DAMAGE.
33
+ # -----------------------------------------------------------------------------
34
+ ;
35
+
36
+
37
+ require 'test/unit'
38
+ require 'rgeo'
39
+
40
+ require ::File.expand_path('../common/factory_tests.rb', ::File.dirname(__FILE__))
41
+
42
+
43
+ module RGeo
44
+ module Tests # :nodoc:
45
+ module SimpleCartesian # :nodoc:
46
+
47
+ class TestFactory < ::Test::Unit::TestCase # :nodoc:
48
+
49
+
50
+ def setup
51
+ @factory = ::RGeo::Cartesian.simple_factory(:srid => 1000)
52
+ @srid = 1000
53
+ end
54
+
55
+
56
+ include ::RGeo::Tests::Common::FactoryTests
57
+
58
+
59
+ undef_method :test_srid_preserved_through_geom_operations
60
+
61
+
62
+ end
63
+
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,63 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Tests for the GEOS factory
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+ # Copyright 2010-2012 Daniel Azuma
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Redistribution and use in source and binary forms, with or without
11
+ # modification, are permitted provided that the following conditions are met:
12
+ #
13
+ # * Redistributions of source code must retain the above copyright notice,
14
+ # this list of conditions and the following disclaimer.
15
+ # * Redistributions in binary form must reproduce the above copyright notice,
16
+ # this list of conditions and the following disclaimer in the documentation
17
+ # and/or other materials provided with the distribution.
18
+ # * Neither the name of the copyright holder, nor the names of any other
19
+ # contributors to this software, may be used to endorse or promote products
20
+ # derived from this software without specific prior written permission.
21
+ #
22
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ # POSSIBILITY OF SUCH DAMAGE.
33
+ # -----------------------------------------------------------------------------
34
+ ;
35
+
36
+
37
+ require 'test/unit'
38
+ require 'rgeo'
39
+
40
+ require ::File.expand_path('../common/factory_tests.rb', ::File.dirname(__FILE__))
41
+
42
+
43
+ module RGeo
44
+ module Tests # :nodoc:
45
+ module SimpleMercator # :nodoc:
46
+
47
+ class TestFactory < ::Test::Unit::TestCase # :nodoc:
48
+
49
+
50
+ def setup
51
+ @factory = ::RGeo::Geographic.simple_mercator_factory
52
+ @srid = 4326
53
+ end
54
+
55
+
56
+ include ::RGeo::Tests::Common::FactoryTests
57
+
58
+
59
+ end
60
+
61
+ end
62
+ end
63
+ end