rgeo-dschee 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +29 -0
  3. data/ext/geos_c_impl/coordinates.c +65 -0
  4. data/ext/geos_c_impl/coordinates.h +2 -0
  5. data/ext/geos_c_impl/extconf.rb +43 -0
  6. data/ext/geos_c_impl/factory.c +995 -0
  7. data/ext/geos_c_impl/factory.h +238 -0
  8. data/ext/geos_c_impl/geometry.c +1093 -0
  9. data/ext/geos_c_impl/geometry.h +23 -0
  10. data/ext/geos_c_impl/geometry_collection.c +757 -0
  11. data/ext/geos_c_impl/geometry_collection.h +46 -0
  12. data/ext/geos_c_impl/line_string.c +675 -0
  13. data/ext/geos_c_impl/line_string.h +32 -0
  14. data/ext/geos_c_impl/main.c +40 -0
  15. data/ext/geos_c_impl/point.c +236 -0
  16. data/ext/geos_c_impl/point.h +30 -0
  17. data/ext/geos_c_impl/polygon.c +359 -0
  18. data/ext/geos_c_impl/polygon.h +43 -0
  19. data/ext/geos_c_impl/preface.h +38 -0
  20. data/ext/proj4_c_impl/extconf.rb +62 -0
  21. data/ext/proj4_c_impl/main.c +315 -0
  22. data/lib/rgeo.rb +89 -0
  23. data/lib/rgeo/cartesian.rb +25 -0
  24. data/lib/rgeo/cartesian/analysis.rb +77 -0
  25. data/lib/rgeo/cartesian/bounding_box.rb +398 -0
  26. data/lib/rgeo/cartesian/calculations.rb +113 -0
  27. data/lib/rgeo/cartesian/factory.rb +347 -0
  28. data/lib/rgeo/cartesian/feature_classes.rb +100 -0
  29. data/lib/rgeo/cartesian/feature_methods.rb +88 -0
  30. data/lib/rgeo/cartesian/interface.rb +135 -0
  31. data/lib/rgeo/coord_sys.rb +43 -0
  32. data/lib/rgeo/coord_sys/cs/entities.rb +1315 -0
  33. data/lib/rgeo/coord_sys/cs/factories.rb +148 -0
  34. data/lib/rgeo/coord_sys/cs/wkt_parser.rb +272 -0
  35. data/lib/rgeo/coord_sys/proj4.rb +293 -0
  36. data/lib/rgeo/coord_sys/srs_database/interface.rb +115 -0
  37. data/lib/rgeo/coord_sys/srs_database/proj4_data.rb +140 -0
  38. data/lib/rgeo/coord_sys/srs_database/sr_org.rb +62 -0
  39. data/lib/rgeo/coord_sys/srs_database/url_reader.rb +63 -0
  40. data/lib/rgeo/error.rb +27 -0
  41. data/lib/rgeo/feature.rb +54 -0
  42. data/lib/rgeo/feature/curve.rb +111 -0
  43. data/lib/rgeo/feature/factory.rb +278 -0
  44. data/lib/rgeo/feature/factory_generator.rb +96 -0
  45. data/lib/rgeo/feature/geometry.rb +624 -0
  46. data/lib/rgeo/feature/geometry_collection.rb +95 -0
  47. data/lib/rgeo/feature/line.rb +26 -0
  48. data/lib/rgeo/feature/line_string.rb +60 -0
  49. data/lib/rgeo/feature/linear_ring.rb +26 -0
  50. data/lib/rgeo/feature/mixins.rb +143 -0
  51. data/lib/rgeo/feature/multi_curve.rb +71 -0
  52. data/lib/rgeo/feature/multi_line_string.rb +26 -0
  53. data/lib/rgeo/feature/multi_point.rb +33 -0
  54. data/lib/rgeo/feature/multi_polygon.rb +57 -0
  55. data/lib/rgeo/feature/multi_surface.rb +73 -0
  56. data/lib/rgeo/feature/point.rb +84 -0
  57. data/lib/rgeo/feature/polygon.rb +97 -0
  58. data/lib/rgeo/feature/surface.rb +79 -0
  59. data/lib/rgeo/feature/types.rb +284 -0
  60. data/lib/rgeo/geographic.rb +40 -0
  61. data/lib/rgeo/geographic/factory.rb +450 -0
  62. data/lib/rgeo/geographic/interface.rb +489 -0
  63. data/lib/rgeo/geographic/proj4_projector.rb +58 -0
  64. data/lib/rgeo/geographic/projected_feature_classes.rb +107 -0
  65. data/lib/rgeo/geographic/projected_feature_methods.rb +212 -0
  66. data/lib/rgeo/geographic/projected_window.rb +383 -0
  67. data/lib/rgeo/geographic/simple_mercator_projector.rb +110 -0
  68. data/lib/rgeo/geographic/spherical_feature_classes.rb +100 -0
  69. data/lib/rgeo/geographic/spherical_feature_methods.rb +134 -0
  70. data/lib/rgeo/geographic/spherical_math.rb +188 -0
  71. data/lib/rgeo/geos.rb +89 -0
  72. data/lib/rgeo/geos/capi_factory.rb +470 -0
  73. data/lib/rgeo/geos/capi_feature_classes.rb +129 -0
  74. data/lib/rgeo/geos/ffi_factory.rb +592 -0
  75. data/lib/rgeo/geos/ffi_feature_classes.rb +83 -0
  76. data/lib/rgeo/geos/ffi_feature_methods.rb +574 -0
  77. data/lib/rgeo/geos/interface.rb +202 -0
  78. data/lib/rgeo/geos/utils.rb +74 -0
  79. data/lib/rgeo/geos/zm_factory.rb +405 -0
  80. data/lib/rgeo/geos/zm_feature_classes.rb +80 -0
  81. data/lib/rgeo/geos/zm_feature_methods.rb +344 -0
  82. data/lib/rgeo/impl_helper.rb +19 -0
  83. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +185 -0
  84. data/lib/rgeo/impl_helper/basic_geometry_methods.rb +61 -0
  85. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +146 -0
  86. data/lib/rgeo/impl_helper/basic_point_methods.rb +104 -0
  87. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +87 -0
  88. data/lib/rgeo/impl_helper/math.rb +14 -0
  89. data/lib/rgeo/impl_helper/utils.rb +29 -0
  90. data/lib/rgeo/version.rb +3 -0
  91. data/lib/rgeo/wkrep.rb +37 -0
  92. data/lib/rgeo/wkrep/wkb_generator.rb +201 -0
  93. data/lib/rgeo/wkrep/wkb_parser.rb +251 -0
  94. data/lib/rgeo/wkrep/wkt_generator.rb +207 -0
  95. data/lib/rgeo/wkrep/wkt_parser.rb +415 -0
  96. data/lib/rgeo/yaml.rb +23 -0
  97. data/test/cartesian_analysis_test.rb +65 -0
  98. data/test/cartesian_bbox_test.rb +123 -0
  99. data/test/common/factory_tests.rb +78 -0
  100. data/test/common/geometry_collection_tests.rb +237 -0
  101. data/test/common/line_string_tests.rb +330 -0
  102. data/test/common/multi_line_string_tests.rb +182 -0
  103. data/test/common/multi_point_tests.rb +200 -0
  104. data/test/common/multi_polygon_tests.rb +191 -0
  105. data/test/common/point_tests.rb +370 -0
  106. data/test/common/polygon_tests.rb +261 -0
  107. data/test/coord_sys/ogc_cs_test.rb +342 -0
  108. data/test/coord_sys/proj4_srs_data_test.rb +41 -0
  109. data/test/coord_sys/proj4_test.rb +150 -0
  110. data/test/coord_sys/sr_org_test.rb +32 -0
  111. data/test/coord_sys/url_reader_test.rb +42 -0
  112. data/test/geos_capi/factory_test.rb +31 -0
  113. data/test/geos_capi/geometry_collection_test.rb +24 -0
  114. data/test/geos_capi/line_string_test.rb +24 -0
  115. data/test/geos_capi/misc_test.rb +116 -0
  116. data/test/geos_capi/multi_line_string_test.rb +24 -0
  117. data/test/geos_capi/multi_point_test.rb +24 -0
  118. data/test/geos_capi/multi_polygon_test.rb +39 -0
  119. data/test/geos_capi/parsing_unparsing_test.rb +40 -0
  120. data/test/geos_capi/point_test.rb +72 -0
  121. data/test/geos_capi/polygon_test.rb +154 -0
  122. data/test/geos_capi/zmfactory_test.rb +57 -0
  123. data/test/geos_ffi/factory_test.rb +31 -0
  124. data/test/geos_ffi/geometry_collection_test.rb +24 -0
  125. data/test/geos_ffi/line_string_test.rb +24 -0
  126. data/test/geos_ffi/misc_test.rb +63 -0
  127. data/test/geos_ffi/multi_line_string_test.rb +24 -0
  128. data/test/geos_ffi/multi_point_test.rb +24 -0
  129. data/test/geos_ffi/multi_polygon_test.rb +33 -0
  130. data/test/geos_ffi/parsing_unparsing_test.rb +41 -0
  131. data/test/geos_ffi/point_test.rb +77 -0
  132. data/test/geos_ffi/polygon_test.rb +46 -0
  133. data/test/geos_ffi/zmfactory_test.rb +58 -0
  134. data/test/mixins_test.rb +141 -0
  135. data/test/oneoff_test.rb +26 -0
  136. data/test/projected_geographic/factory_test.rb +25 -0
  137. data/test/projected_geographic/geometry_collection_test.rb +24 -0
  138. data/test/projected_geographic/line_string_test.rb +24 -0
  139. data/test/projected_geographic/multi_line_string_test.rb +26 -0
  140. data/test/projected_geographic/multi_point_test.rb +30 -0
  141. data/test/projected_geographic/multi_polygon_test.rb +25 -0
  142. data/test/projected_geographic/point_test.rb +51 -0
  143. data/test/projected_geographic/polygon_test.rb +24 -0
  144. data/test/simple_cartesian/calculations_test.rb +99 -0
  145. data/test/simple_cartesian/factory_test.rb +27 -0
  146. data/test/simple_cartesian/geometry_collection_test.rb +30 -0
  147. data/test/simple_cartesian/line_string_test.rb +31 -0
  148. data/test/simple_cartesian/multi_line_string_test.rb +28 -0
  149. data/test/simple_cartesian/multi_point_test.rb +31 -0
  150. data/test/simple_cartesian/multi_polygon_test.rb +31 -0
  151. data/test/simple_cartesian/point_test.rb +50 -0
  152. data/test/simple_cartesian/polygon_test.rb +28 -0
  153. data/test/simple_mercator/factory_test.rb +25 -0
  154. data/test/simple_mercator/geometry_collection_test.rb +24 -0
  155. data/test/simple_mercator/line_string_test.rb +24 -0
  156. data/test/simple_mercator/multi_line_string_test.rb +26 -0
  157. data/test/simple_mercator/multi_point_test.rb +29 -0
  158. data/test/simple_mercator/multi_polygon_test.rb +25 -0
  159. data/test/simple_mercator/point_test.rb +55 -0
  160. data/test/simple_mercator/polygon_test.rb +24 -0
  161. data/test/simple_mercator/window_test.rb +173 -0
  162. data/test/spherical_geographic/calculations_test.rb +167 -0
  163. data/test/spherical_geographic/factory_test.rb +27 -0
  164. data/test/spherical_geographic/geometry_collection_test.rb +31 -0
  165. data/test/spherical_geographic/line_string_test.rb +31 -0
  166. data/test/spherical_geographic/multi_line_string_test.rb +29 -0
  167. data/test/spherical_geographic/multi_point_test.rb +31 -0
  168. data/test/spherical_geographic/multi_polygon_test.rb +31 -0
  169. data/test/spherical_geographic/point_test.rb +78 -0
  170. data/test/spherical_geographic/polygon_test.rb +28 -0
  171. data/test/types_test.rb +42 -0
  172. data/test/wkrep/wkb_generator_test.rb +185 -0
  173. data/test/wkrep/wkb_parser_test.rb +293 -0
  174. data/test/wkrep/wkt_generator_test.rb +294 -0
  175. data/test/wkrep/wkt_parser_test.rb +412 -0
  176. metadata +386 -0
data/lib/rgeo/yaml.rb ADDED
@@ -0,0 +1,23 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # RGeo yaml support
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+
7
+ begin
8
+ require "psych"
9
+ rescue ::LoadError
10
+ end
11
+
12
+ module RGeo
13
+ # :stopdoc:
14
+ PSYCH_AVAILABLE = defined?(::Psych)
15
+ # :startdoc:
16
+
17
+ # Returns true if YAML serialization and deserialization is supported.
18
+ # YAML support requires the Psych library/gem.
19
+
20
+ def self.yaml_supported?
21
+ PSYCH_AVAILABLE
22
+ end
23
+ end
@@ -0,0 +1,65 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Tests for basic GeoJSON usage
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+
7
+ require "test/unit"
8
+ require "rgeo"
9
+
10
+ module RGeo
11
+ module Tests # :nodoc:
12
+ class TestCartesianAnalysis < ::Test::Unit::TestCase # :nodoc:
13
+ def setup
14
+ @factory = ::RGeo::Cartesian.simple_factory
15
+ end
16
+
17
+ def test_ring_direction_clockwise_triangle
18
+ p1_ = @factory.point(1, 1)
19
+ p2_ = @factory.point(2, 4)
20
+ p3_ = @factory.point(5, 2)
21
+ ring_ = @factory.line_string([p1_, p2_, p3_, p1_])
22
+ assert_equal(-1, ::RGeo::Cartesian::Analysis.ring_direction(ring_))
23
+ end
24
+
25
+ def test_ring_direction_counterclockwise_triangle
26
+ p1_ = @factory.point(1, 1)
27
+ p2_ = @factory.point(2, 4)
28
+ p3_ = @factory.point(5, 2)
29
+ ring_ = @factory.line_string([p1_, p3_, p2_, p1_])
30
+ assert_equal(1, ::RGeo::Cartesian::Analysis.ring_direction(ring_))
31
+ end
32
+
33
+ def test_ring_direction_clockwise_puckered_quad
34
+ p1_ = @factory.point(1, 1)
35
+ p2_ = @factory.point(2, 6)
36
+ p3_ = @factory.point(3, 3)
37
+ p4_ = @factory.point(5, 2)
38
+ ring_ = @factory.line_string([p1_, p2_, p3_, p4_, p1_])
39
+ assert_equal(-1, ::RGeo::Cartesian::Analysis.ring_direction(ring_))
40
+ end
41
+
42
+ def test_ring_direction_counterclockwise_puckered_quad
43
+ p1_ = @factory.point(1, 1)
44
+ p2_ = @factory.point(2, 6)
45
+ p3_ = @factory.point(3, 3)
46
+ p4_ = @factory.point(5, 2)
47
+ ring_ = @factory.line_string([p1_, p4_, p3_, p2_, p1_])
48
+ assert_equal(1, ::RGeo::Cartesian::Analysis.ring_direction(ring_))
49
+ end
50
+
51
+ def test_ring_direction_counterclockwise_near_circle
52
+ p1_ = @factory.point(0, -3)
53
+ p2_ = @factory.point(2, -2)
54
+ p3_ = @factory.point(3, 0)
55
+ p4_ = @factory.point(2, 2)
56
+ p5_ = @factory.point(0, 3)
57
+ p6_ = @factory.point(-2, 2)
58
+ p7_ = @factory.point(-3, 0)
59
+ p8_ = @factory.point(-2, -2)
60
+ ring_ = @factory.line_string([p1_, p2_, p3_, p4_, p5_, p6_, p7_, p8_, p1_])
61
+ assert_equal(1, ::RGeo::Cartesian::Analysis.ring_direction(ring_))
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,123 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Tests for basic GeoJSON usage
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+
7
+ require "test/unit"
8
+ require "rgeo"
9
+
10
+ module RGeo
11
+ module Tests # :nodoc:
12
+ class TestCartesianBBox < ::Test::Unit::TestCase # :nodoc:
13
+ def setup
14
+ @factory = ::RGeo::Cartesian.factory
15
+ end
16
+
17
+ def test_empty_bbox
18
+ bbox_ = ::RGeo::Cartesian::BoundingBox.new(@factory)
19
+ assert_equal(true, bbox_.empty?)
20
+ assert_equal(false, bbox_.has_z)
21
+ assert_nil(bbox_.min_x)
22
+ assert_equal(@factory, bbox_.factory)
23
+ assert_nil(bbox_.min_point)
24
+ assert_equal(true, bbox_.to_geometry.is_empty?)
25
+ assert_equal(true, bbox_.contains?(bbox_))
26
+ assert_equal(false, bbox_.contains?(@factory.point(1, 1)))
27
+ assert_nil(bbox_.center_x)
28
+ assert_equal(0, bbox_.x_span)
29
+ assert_equal(0, bbox_.subdivide.size)
30
+ end
31
+
32
+ def test_point_bbox
33
+ empty_bbox_ = ::RGeo::Cartesian::BoundingBox.new(@factory)
34
+ bbox_ = ::RGeo::Cartesian::BoundingBox.new(@factory)
35
+ bbox_.add(@factory.point(1, 2))
36
+ assert_equal(false, bbox_.empty?)
37
+ assert_equal(false, bbox_.has_z)
38
+ assert_equal(1.0, bbox_.min_x)
39
+ assert_equal(2.0, bbox_.min_y)
40
+ assert_equal(1.0, bbox_.max_x)
41
+ assert_equal(2.0, bbox_.max_y)
42
+ assert_equal(@factory, bbox_.factory)
43
+ assert_equal(@factory.point(1, 2), bbox_.min_point)
44
+ assert_equal(@factory.point(1, 2), bbox_.max_point)
45
+ assert_equal(@factory.point(1, 2), bbox_.to_geometry)
46
+ assert_equal(true, bbox_.contains?(empty_bbox_))
47
+ assert_equal(false, empty_bbox_.contains?(bbox_))
48
+ assert_equal(true, bbox_.contains?(@factory.point(1, 2)))
49
+ assert_equal(false, bbox_.contains?(@factory.point(2, 1)))
50
+ assert_equal(1, bbox_.center_x)
51
+ assert_equal(0, bbox_.x_span)
52
+ assert_equal(2, bbox_.center_y)
53
+ assert_equal(0, bbox_.y_span)
54
+ assert_equal([bbox_], bbox_.subdivide)
55
+ end
56
+
57
+ def test_rect_bbox
58
+ empty_bbox_ = ::RGeo::Cartesian::BoundingBox.new(@factory)
59
+ bbox_ = ::RGeo::Cartesian::BoundingBox.new(@factory)
60
+ bbox_.add(@factory.point(1, 4))
61
+ bbox_.add(@factory.point(2, 3))
62
+ assert_equal(false, bbox_.empty?)
63
+ assert_equal(false, bbox_.has_z)
64
+ assert_equal(1.0, bbox_.min_x)
65
+ assert_equal(3.0, bbox_.min_y)
66
+ assert_equal(2.0, bbox_.max_x)
67
+ assert_equal(4.0, bbox_.max_y)
68
+ assert_equal(@factory, bbox_.factory)
69
+ assert_equal(@factory.point(1, 3), bbox_.min_point)
70
+ assert_equal(@factory.point(2, 4), bbox_.max_point)
71
+ assert_equal(1.0, bbox_.to_geometry.area)
72
+ assert_equal(true, bbox_.contains?(empty_bbox_))
73
+ assert_equal(false, empty_bbox_.contains?(bbox_))
74
+ assert_equal(true, bbox_.contains?(@factory.point(1, 3)))
75
+ assert_equal(false, bbox_.contains?(@factory.point(2, 1)))
76
+ assert_equal(1.5, bbox_.center_x)
77
+ assert_equal(1, bbox_.x_span)
78
+ assert_equal(3.5, bbox_.center_y)
79
+ assert_equal(1, bbox_.y_span)
80
+ end
81
+
82
+ def test_bbox_from_points
83
+ bbox_ = ::RGeo::Cartesian::BoundingBox.new(@factory)
84
+ bbox_.add(@factory.point(1, 4))
85
+ bbox_.add(@factory.point(2, 3))
86
+ bbox2_ = ::RGeo::Cartesian::BoundingBox.create_from_points(
87
+ @factory.point(2, 3), @factory.point(1, 4))
88
+ assert_equal(bbox_, bbox2_)
89
+ end
90
+
91
+ def test_basic_rect_subdivide
92
+ bbox_ = ::RGeo::Cartesian::BoundingBox.new(@factory)
93
+ bbox_.add(@factory.point(1, 2))
94
+ bbox_.add(@factory.point(5, 4))
95
+ quads_ = bbox_.subdivide
96
+ quads_.each { |q_| assert_equal(2.0, q_.to_geometry.area) }
97
+ quadsum_ = quads_[0].to_geometry + quads_[1].to_geometry +
98
+ quads_[2].to_geometry + quads_[3].to_geometry
99
+ assert_equal(bbox_.to_geometry, quadsum_)
100
+ end
101
+
102
+ def test_horiz_line_subdivide
103
+ bbox_ = ::RGeo::Cartesian::BoundingBox.new(@factory)
104
+ bbox_.add(@factory.point(1, 2))
105
+ bbox_.add(@factory.point(5, 2))
106
+ lines_ = bbox_.subdivide
107
+ lines_.each { |line_| assert_equal(2.0, line_.to_geometry.length) }
108
+ linesum_ = lines_[0].to_geometry + lines_[1].to_geometry
109
+ assert_equal(bbox_.to_geometry, linesum_)
110
+ end
111
+
112
+ def test_vert_line_subdivide
113
+ bbox_ = ::RGeo::Cartesian::BoundingBox.new(@factory)
114
+ bbox_.add(@factory.point(1, 2))
115
+ bbox_.add(@factory.point(1, 6))
116
+ lines_ = bbox_.subdivide
117
+ lines_.each { |line_| assert_equal(2.0, line_.to_geometry.length) }
118
+ linesum_ = lines_[0].to_geometry + lines_[1].to_geometry
119
+ assert_equal(bbox_.to_geometry, linesum_)
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,78 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Common tests for geometry collection implementations
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+
7
+ require "rgeo"
8
+
9
+ module RGeo
10
+ module Tests # :nodoc:
11
+ module Common # :nodoc:
12
+ module FactoryTests # :nodoc:
13
+ def _srid
14
+ defined?(@srid) ? @srid : 0
15
+ end
16
+
17
+ def test_srid_preserved_through_factory
18
+ geom_ = @factory.point(-10, 20)
19
+ assert_equal(_srid, geom_.srid)
20
+ factory_ = geom_.factory
21
+ assert_equal(_srid, factory_.srid)
22
+ geom2_ = factory_.point(-20, 25)
23
+ assert_equal(_srid, geom2_.srid)
24
+ end
25
+
26
+ def test_srid_preserved_through_geom_operations
27
+ geom1_ = @factory.point(-10, 20)
28
+ geom2_ = @factory.point(-20, 25)
29
+ geom3_ = geom1_.union(geom2_)
30
+ assert_equal(_srid, geom3_.srid)
31
+ assert_equal(_srid, geom3_.geometry_n(0).srid)
32
+ assert_equal(_srid, geom3_.geometry_n(1).srid)
33
+ end
34
+
35
+ def test_srid_preserved_through_geom_functions
36
+ geom1_ = @factory.point(-10, 20)
37
+ geom2_ = geom1_.boundary
38
+ assert_equal(_srid, geom2_.srid)
39
+ end
40
+
41
+ def test_srid_preserved_through_geometry_dup
42
+ geom1_ = @factory.point(-10, 20)
43
+ geom2_ = geom1_.clone
44
+ assert_equal(_srid, geom2_.srid)
45
+ end
46
+
47
+ def test_dup_factory_results_in_equal_factories
48
+ dup_factory_ = @factory.dup
49
+ assert_equal(@factory, dup_factory_)
50
+ assert_equal(_srid, dup_factory_.srid)
51
+ end
52
+
53
+ def test_dup_factory_results_in_equal_hashes
54
+ dup_factory_ = @factory.dup
55
+ assert_equal(@factory.hash, dup_factory_.hash)
56
+ end
57
+
58
+ def test_marshal_dump_load_factory
59
+ data_ = ::Marshal.dump(@factory)
60
+ factory2_ = ::Marshal.load(data_)
61
+ assert_equal(@factory, factory2_)
62
+ assert_equal(_srid, factory2_.srid)
63
+ end
64
+
65
+ if ::RGeo.yaml_supported?
66
+
67
+ def test_psych_dump_load_factory
68
+ data_ = ::Psych.dump(@factory)
69
+ factory2_ = ::Psych.load(data_)
70
+ assert_equal(@factory, factory2_)
71
+ assert_equal(_srid, factory2_.srid)
72
+ end
73
+
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,237 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Common tests for geometry collection implementations
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+
7
+ require "rgeo"
8
+
9
+ module RGeo
10
+ module Tests # :nodoc:
11
+ module Common # :nodoc:
12
+ module GeometryCollectionTests # :nodoc:
13
+ def setup
14
+ @factory = create_factory
15
+ @point1 = @factory.point(0, 0)
16
+ @point2 = @factory.point(1, 0)
17
+ @point3 = @factory.point(-4, 2)
18
+ @point4 = @factory.point(-5, 3)
19
+ @line1 = @factory.line_string([@point3, @point4])
20
+ @line2 = @factory.line_string([@point3, @point4, @point1])
21
+ @line3 = @factory.line(@point3, @point4)
22
+ end
23
+
24
+ def test_creation_simple
25
+ geom_ = @factory.collection([@point1, @line1])
26
+ assert_not_nil(geom_)
27
+ assert(::RGeo::Feature::GeometryCollection === geom_)
28
+ assert_equal(::RGeo::Feature::GeometryCollection, geom_.geometry_type)
29
+ assert_equal(2, geom_.num_geometries)
30
+ assert(@point1.eql?(geom_[0]))
31
+ assert(@line1.eql?(geom_[1]))
32
+ end
33
+
34
+ def test_creation_empty
35
+ geom_ = @factory.collection([])
36
+ assert_not_nil(geom_)
37
+ assert(::RGeo::Feature::GeometryCollection === geom_)
38
+ assert_equal(::RGeo::Feature::GeometryCollection, geom_.geometry_type)
39
+ assert_equal(0, geom_.num_geometries)
40
+ assert_equal([], geom_.to_a)
41
+ end
42
+
43
+ def test_bounds_check
44
+ geom_ = @factory.collection([@point1, @line1])
45
+ assert_nil(geom_.geometry_n(200))
46
+ assert_nil(geom_.geometry_n(-1))
47
+ assert(@line1.eql?(geom_[-1]))
48
+ end
49
+
50
+ def test_creation_save_klass
51
+ geom_ = @factory.collection([@point1, @line3])
52
+ assert_not_nil(geom_)
53
+ assert(::RGeo::Feature::GeometryCollection === geom_)
54
+ assert_equal(::RGeo::Feature::GeometryCollection, geom_.geometry_type)
55
+ assert_equal(2, geom_.num_geometries)
56
+ assert(geom_[1].eql?(@line3))
57
+ end
58
+
59
+ def test_creation_compound
60
+ geom1_ = @factory.collection([@point1, @line1])
61
+ geom2_ = @factory.collection([@point2, geom1_])
62
+ assert_not_nil(geom2_)
63
+ assert(::RGeo::Feature::GeometryCollection === geom2_)
64
+ assert_equal(::RGeo::Feature::GeometryCollection, geom2_.geometry_type)
65
+ assert_equal(2, geom2_.num_geometries)
66
+ assert(geom2_[1].eql?(geom1_))
67
+ end
68
+
69
+ def test_creation_compound_save_klass
70
+ geom1_ = @factory.collection([@point1, @line3])
71
+ geom2_ = @factory.collection([@point2, geom1_])
72
+ ::GC.start
73
+ assert_not_nil(geom2_)
74
+ assert(::RGeo::Feature::GeometryCollection === geom2_)
75
+ assert_equal(::RGeo::Feature::GeometryCollection, geom2_.geometry_type)
76
+ assert_equal(2, geom2_.num_geometries)
77
+ assert_equal(::RGeo::Feature::Line, geom2_[1][1].geometry_type)
78
+ end
79
+
80
+ def test_required_equivalences
81
+ geom1_ = @factory.collection([@point1, @line1])
82
+ geom2_ = @factory.collection([@point1, @line1])
83
+ assert(geom1_.eql?(geom2_))
84
+ assert(geom1_ == geom2_)
85
+ end
86
+
87
+ def test_fully_equal
88
+ geom1_ = @factory.collection([@point1, @line1])
89
+ geom2_ = @factory.collection([@point1, @line1])
90
+ assert(geom1_.rep_equals?(geom2_))
91
+ assert(geom1_.equals?(geom2_))
92
+ end
93
+
94
+ def test_geometrically_equal
95
+ geom1_ = @factory.collection([@point2, @line2])
96
+ geom2_ = @factory.collection([@point2, @line1, @line2])
97
+ assert(!geom1_.rep_equals?(geom2_))
98
+ assert(geom1_.equals?(geom2_))
99
+ end
100
+
101
+ def test_empty_equal
102
+ geom1_ = @factory.collection([])
103
+ geom2_ = @factory.collection([])
104
+ assert(geom1_.rep_equals?(geom2_))
105
+ assert(geom1_.equals?(geom2_))
106
+ end
107
+
108
+ def test_not_equal
109
+ geom1_ = @factory.collection([@point1, @line1])
110
+ geom2_ = @factory.collection([@point2, @line1])
111
+ assert(!geom1_.rep_equals?(geom2_))
112
+ assert(!geom1_.equals?(geom2_))
113
+ end
114
+
115
+ def test_hashes_equal_for_representationally_equivalent_objects
116
+ geom1_ = @factory.collection([@point1, @line1])
117
+ geom2_ = @factory.collection([@point1, @line1])
118
+ assert_equal(geom1_.hash, geom2_.hash)
119
+ end
120
+
121
+ def test_nested_equality
122
+ geom1_ = @factory.collection([@line1, @factory.collection([@point1, @point2])])
123
+ geom2_ = @factory.collection([@line1, @factory.collection([@point1, @point2])])
124
+ assert(geom1_.rep_equals?(geom2_))
125
+ assert_equal(geom1_.hash, geom2_.hash)
126
+ end
127
+
128
+ def test_out_of_order_is_not_equal
129
+ geom1_ = @factory.collection([@line1, @point2])
130
+ geom2_ = @factory.collection([@point2, @line1])
131
+ assert(!geom1_.rep_equals?(geom2_))
132
+ assert_not_equal(geom1_.hash, geom2_.hash)
133
+ end
134
+
135
+ def test_wkt_creation_simple
136
+ parsed_geom_ = @factory.parse_wkt("GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(-4 2, -5 3))")
137
+ built_geom_ = @factory.collection([@point1, @line1])
138
+ assert(built_geom_.eql?(parsed_geom_))
139
+ end
140
+
141
+ def test_wkt_creation_empty
142
+ parsed_geom_ = @factory.parse_wkt("GEOMETRYCOLLECTION EMPTY")
143
+ assert_equal(0, parsed_geom_.num_geometries)
144
+ assert_equal([], parsed_geom_.to_a)
145
+ end
146
+
147
+ def test_clone
148
+ geom1_ = @factory.collection([@point1, @line1])
149
+ geom2_ = geom1_.clone
150
+ assert(geom1_.eql?(geom2_))
151
+ assert_equal(::RGeo::Feature::GeometryCollection, geom2_.geometry_type)
152
+ assert_equal(2, geom2_.num_geometries)
153
+ assert(@point1.eql?(geom2_[0]))
154
+ assert(@line1.eql?(geom2_[1]))
155
+ end
156
+
157
+ def test_type_check
158
+ geom1_ = @factory.collection([@point1, @line1])
159
+ assert(::RGeo::Feature::Geometry.check_type(geom1_))
160
+ assert(!::RGeo::Feature::Point.check_type(geom1_))
161
+ assert(::RGeo::Feature::GeometryCollection.check_type(geom1_))
162
+ assert(!::RGeo::Feature::MultiPoint.check_type(geom1_))
163
+ geom2_ = @factory.collection([@point1, @point2])
164
+ assert(::RGeo::Feature::Geometry.check_type(geom2_))
165
+ assert(!::RGeo::Feature::Point.check_type(geom2_))
166
+ assert(::RGeo::Feature::GeometryCollection.check_type(geom2_))
167
+ assert(!::RGeo::Feature::MultiPoint.check_type(geom2_))
168
+ end
169
+
170
+ def test_as_text_wkt_round_trip
171
+ geom1_ = @factory.collection([@point1, @line1])
172
+ text_ = geom1_.as_text
173
+ geom2_ = @factory.parse_wkt(text_)
174
+ assert(geom1_.eql?(geom2_))
175
+ end
176
+
177
+ def test_as_binary_wkb_round_trip
178
+ geom1_ = @factory.collection([@point1, @line1])
179
+ binary_ = geom1_.as_binary
180
+ geom2_ = @factory.parse_wkb(binary_)
181
+ assert(geom1_.eql?(geom2_))
182
+ end
183
+
184
+ def test_dimension
185
+ geom1_ = @factory.collection([@point1, @line1])
186
+ assert_equal(1, geom1_.dimension)
187
+ geom2_ = @factory.collection([@point1, @point2])
188
+ assert_equal(0, geom2_.dimension)
189
+ geom3_ = @factory.collection([])
190
+ assert_equal(-1, geom3_.dimension)
191
+ end
192
+
193
+ def test_is_empty
194
+ geom1_ = @factory.collection([@point1, @line1])
195
+ assert(!geom1_.is_empty?)
196
+ geom2_ = @factory.collection([])
197
+ assert(geom2_.is_empty?)
198
+ end
199
+
200
+ def test_empty_collection_envelope
201
+ empty_ = @factory.collection([])
202
+ envelope_ = empty_.envelope
203
+ assert_equal(Feature::GeometryCollection, envelope_.geometry_type)
204
+ assert_equal(0, envelope_.num_geometries)
205
+ end
206
+
207
+ def test_empty_collection_boundary
208
+ empty_ = @factory.collection([])
209
+ assert_nil(empty_.boundary)
210
+ end
211
+
212
+ def test_each_block
213
+ geom1_ = @factory.collection([@point1, @line1])
214
+ i_ = 0
215
+ geom1_.each do |g_|
216
+ if i_ == 0
217
+ assert_equal(@point1, g_)
218
+ else
219
+ assert_equal(@line1, g_)
220
+ end
221
+ i_ += 1
222
+ end
223
+ end
224
+
225
+ def test_each_enumerator
226
+ geom1_ = @factory.collection([@point1, @line1])
227
+ enum_ = geom1_.each
228
+ assert_equal(@point1, enum_.next)
229
+ assert_equal(@line1, enum_.next)
230
+ assert_raise(::StopIteration) do
231
+ enum_.next
232
+ end
233
+ end
234
+ end
235
+ end
236
+ end
237
+ end