rgeo 0.1.19 → 0.1.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. data/History.rdoc +11 -0
  2. data/README.rdoc +23 -7
  3. data/Version +1 -1
  4. data/ext/geos_c_impl/factory.c +1 -1
  5. data/{lib/rgeo/geography/simple_mercator.rb → ext/proj4_c_impl/extconf.rb} +35 -30
  6. data/ext/proj4_c_impl/main.c +256 -0
  7. data/lib/rgeo.rb +54 -42
  8. data/lib/rgeo/active_record/arel_modifications.rb +2 -2
  9. data/lib/rgeo/active_record/base_modifications.rb +1 -1
  10. data/lib/rgeo/active_record/mysql_common.rb +12 -12
  11. data/lib/rgeo/all.rb +5 -4
  12. data/lib/rgeo/cartesian.rb +3 -2
  13. data/lib/rgeo/cartesian/bounding_box.rb +9 -9
  14. data/lib/rgeo/cartesian/factory.rb +30 -13
  15. data/lib/rgeo/cartesian/feature_classes.rb +33 -33
  16. data/lib/rgeo/cartesian/interface.rb +2 -2
  17. data/lib/rgeo/{geography/all.rb → coord_sys.rb} +22 -4
  18. data/lib/rgeo/coord_sys/proj4.rb +275 -0
  19. data/lib/rgeo/{errors.rb → error.rb} +5 -6
  20. data/lib/rgeo/{features.rb → feature.rb} +22 -20
  21. data/lib/rgeo/{features → feature}/curve.rb +6 -6
  22. data/lib/rgeo/{features → feature}/factory.rb +19 -3
  23. data/lib/rgeo/{features → feature}/factory_generator.rb +1 -1
  24. data/lib/rgeo/{features → feature}/geometry.rb +34 -34
  25. data/lib/rgeo/{features → feature}/geometry_collection.rb +4 -4
  26. data/lib/rgeo/{features → feature}/line.rb +1 -1
  27. data/lib/rgeo/{features → feature}/line_string.rb +4 -4
  28. data/lib/rgeo/{features → feature}/linear_ring.rb +1 -1
  29. data/lib/rgeo/{features → feature}/multi_curve.rb +3 -3
  30. data/lib/rgeo/{features → feature}/multi_line_string.rb +1 -1
  31. data/lib/rgeo/{features → feature}/multi_point.rb +1 -1
  32. data/lib/rgeo/{features → feature}/multi_polygon.rb +1 -1
  33. data/lib/rgeo/{features → feature}/multi_surface.rb +4 -4
  34. data/lib/rgeo/{features → feature}/point.rb +5 -5
  35. data/lib/rgeo/{features → feature}/polygon.rb +5 -5
  36. data/lib/rgeo/{features → feature}/surface.rb +4 -4
  37. data/lib/rgeo/feature/types.rb +301 -0
  38. data/lib/rgeo/geo_json.rb +1 -1
  39. data/lib/rgeo/geo_json/coder.rb +13 -13
  40. data/lib/rgeo/geo_json/interface.rb +2 -2
  41. data/lib/rgeo/geography.rb +33 -6
  42. data/lib/rgeo/geography/factory.rb +82 -39
  43. data/lib/rgeo/geography/interface.rb +135 -89
  44. data/lib/rgeo/geography/proj4_projector.rb +98 -0
  45. data/lib/rgeo/geography/projected_feature_classes.rb +213 -0
  46. data/lib/rgeo/geography/projected_feature_methods.rb +228 -0
  47. data/lib/rgeo/geography/projected_window.rb +7 -7
  48. data/lib/rgeo/geography/simple_mercator_projector.rb +133 -0
  49. data/lib/rgeo/geography/spherical_feature_classes.rb +212 -0
  50. data/lib/rgeo/geography/{simple_spherical/feature_methods.rb → spherical_feature_methods.rb} +39 -43
  51. data/lib/rgeo/geography/{simple_spherical/calculations.rb → spherical_math.rb} +7 -7
  52. data/lib/rgeo/geos.rb +1 -1
  53. data/lib/rgeo/geos/factory.rb +37 -19
  54. data/lib/rgeo/geos/impl_additions.rb +10 -11
  55. data/lib/rgeo/geos/interface.rb +1 -1
  56. data/lib/rgeo/geos/zm_factory.rb +15 -15
  57. data/lib/rgeo/geos/zm_impl.rb +10 -10
  58. data/lib/rgeo/{impl_helpers.rb → impl_helper.rb} +8 -8
  59. data/lib/rgeo/{impl_helpers → impl_helper}/basic_geometry_collection_methods.rb +13 -13
  60. data/lib/rgeo/{impl_helpers → impl_helper}/basic_geometry_methods.rb +2 -2
  61. data/lib/rgeo/{impl_helpers → impl_helper}/basic_line_string_methods.rb +13 -13
  62. data/lib/rgeo/{impl_helpers → impl_helper}/basic_point_methods.rb +5 -5
  63. data/lib/rgeo/{impl_helpers → impl_helper}/basic_polygon_methods.rb +6 -6
  64. data/lib/rgeo/{impl_helpers → impl_helper}/math.rb +1 -1
  65. data/lib/rgeo/shapefile.rb +1 -1
  66. data/lib/rgeo/shapefile/reader.rb +3 -3
  67. data/lib/rgeo/wkrep.rb +1 -1
  68. data/lib/rgeo/wkrep/wkb_generator.rb +17 -17
  69. data/lib/rgeo/wkrep/wkb_parser.rb +12 -12
  70. data/lib/rgeo/wkrep/wkt_generator.rb +8 -8
  71. data/lib/rgeo/wkrep/wkt_parser.rb +10 -10
  72. data/{tests → test}/active_record/readme.txt +0 -0
  73. data/{tests → test}/active_record/tc_mysqlspatial.rb +2 -2
  74. data/{tests → test}/common/geometry_collection_tests.rb +22 -22
  75. data/{tests → test}/common/line_string_tests.rb +20 -20
  76. data/{tests → test}/common/multi_line_string_tests.rb +19 -19
  77. data/{tests → test}/common/multi_point_tests.rb +17 -17
  78. data/{tests → test}/common/multi_polygon_tests.rb +16 -16
  79. data/{tests → test}/common/point_tests.rb +9 -9
  80. data/{tests → test}/common/polygon_tests.rb +9 -9
  81. data/test/coord_sys/tc_proj4.rb +111 -0
  82. data/{tests → test}/geos/tc_factory.rb +1 -1
  83. data/{tests → test}/geos/tc_geometry_collection.rb +1 -1
  84. data/{tests → test}/geos/tc_line_string.rb +0 -0
  85. data/{tests → test}/geos/tc_misc.rb +1 -1
  86. data/{tests → test}/geos/tc_multi_line_string.rb +1 -1
  87. data/{tests → test}/geos/tc_multi_point.rb +1 -1
  88. data/{tests → test}/geos/tc_multi_polygon.rb +1 -1
  89. data/{tests → test}/geos/tc_point.rb +1 -1
  90. data/{tests → test}/geos/tc_polygon.rb +0 -0
  91. data/{tests → test}/geos/tc_zmfactory.rb +2 -2
  92. data/test/projected_geography/tc_geometry_collection.rb +62 -0
  93. data/test/projected_geography/tc_line_string.rb +62 -0
  94. data/test/projected_geography/tc_multi_line_string.rb +62 -0
  95. data/test/projected_geography/tc_multi_point.rb +62 -0
  96. data/test/projected_geography/tc_multi_polygon.rb +63 -0
  97. data/test/projected_geography/tc_point.rb +93 -0
  98. data/test/projected_geography/tc_polygon.rb +62 -0
  99. data/{tests → test}/shapefile/shapelib_testcases/readme.txt +0 -0
  100. data/{tests → test}/shapefile/shapelib_testcases/test.dbf +0 -0
  101. data/{tests → test}/shapefile/shapelib_testcases/test.shp +0 -0
  102. data/{tests → test}/shapefile/shapelib_testcases/test.shx +0 -0
  103. data/{tests → test}/shapefile/shapelib_testcases/test0.shp +0 -0
  104. data/{tests → test}/shapefile/shapelib_testcases/test0.shx +0 -0
  105. data/{tests → test}/shapefile/shapelib_testcases/test1.shp +0 -0
  106. data/{tests → test}/shapefile/shapelib_testcases/test1.shx +0 -0
  107. data/{tests → test}/shapefile/shapelib_testcases/test10.shp +0 -0
  108. data/{tests → test}/shapefile/shapelib_testcases/test10.shx +0 -0
  109. data/{tests → test}/shapefile/shapelib_testcases/test11.shp +0 -0
  110. data/{tests → test}/shapefile/shapelib_testcases/test11.shx +0 -0
  111. data/{tests → test}/shapefile/shapelib_testcases/test12.shp +0 -0
  112. data/{tests → test}/shapefile/shapelib_testcases/test12.shx +0 -0
  113. data/{tests → test}/shapefile/shapelib_testcases/test13.shp +0 -0
  114. data/{tests → test}/shapefile/shapelib_testcases/test13.shx +0 -0
  115. data/{tests → test}/shapefile/shapelib_testcases/test2.shp +0 -0
  116. data/{tests → test}/shapefile/shapelib_testcases/test2.shx +0 -0
  117. data/{tests → test}/shapefile/shapelib_testcases/test3.shp +0 -0
  118. data/{tests → test}/shapefile/shapelib_testcases/test3.shx +0 -0
  119. data/{tests → test}/shapefile/shapelib_testcases/test4.shp +0 -0
  120. data/{tests → test}/shapefile/shapelib_testcases/test4.shx +0 -0
  121. data/{tests → test}/shapefile/shapelib_testcases/test5.shp +0 -0
  122. data/{tests → test}/shapefile/shapelib_testcases/test5.shx +0 -0
  123. data/{tests → test}/shapefile/shapelib_testcases/test6.shp +0 -0
  124. data/{tests → test}/shapefile/shapelib_testcases/test6.shx +0 -0
  125. data/{tests → test}/shapefile/shapelib_testcases/test7.shp +0 -0
  126. data/{tests → test}/shapefile/shapelib_testcases/test7.shx +0 -0
  127. data/{tests → test}/shapefile/shapelib_testcases/test8.shp +0 -0
  128. data/{tests → test}/shapefile/shapelib_testcases/test8.shx +0 -0
  129. data/{tests → test}/shapefile/shapelib_testcases/test9.shp +0 -0
  130. data/{tests → test}/shapefile/shapelib_testcases/test9.shx +0 -0
  131. data/{tests → test}/shapefile/tc_shapelib_tests.rb +17 -17
  132. data/{tests → test}/simple_cartesian/tc_calculations.rb +0 -0
  133. data/{tests → test}/simple_cartesian/tc_geometry_collection.rb +0 -0
  134. data/{tests → test}/simple_cartesian/tc_line_string.rb +0 -0
  135. data/{tests → test}/simple_cartesian/tc_multi_line_string.rb +0 -0
  136. data/{tests → test}/simple_cartesian/tc_multi_point.rb +0 -0
  137. data/{tests → test}/simple_cartesian/tc_multi_polygon.rb +0 -0
  138. data/{tests → test}/simple_cartesian/tc_point.rb +0 -0
  139. data/{tests → test}/simple_cartesian/tc_polygon.rb +0 -0
  140. data/{tests → test}/simple_mercator/tc_geometry_collection.rb +1 -1
  141. data/{tests → test}/simple_mercator/tc_line_string.rb +0 -0
  142. data/{tests → test}/simple_mercator/tc_multi_line_string.rb +1 -1
  143. data/{tests → test}/simple_mercator/tc_multi_point.rb +1 -1
  144. data/{tests → test}/simple_mercator/tc_multi_polygon.rb +1 -1
  145. data/{tests → test}/simple_mercator/tc_point.rb +2 -2
  146. data/{tests → test}/simple_mercator/tc_polygon.rb +0 -0
  147. data/{tests → test}/simple_mercator/tc_window.rb +1 -1
  148. data/test/spherical_geography/tc_calculations.rb +203 -0
  149. data/{tests/simple_spherical → test/spherical_geography}/tc_geometry_collection.rb +2 -2
  150. data/{tests/simple_spherical → test/spherical_geography}/tc_line_string.rb +2 -2
  151. data/{tests/simple_spherical → test/spherical_geography}/tc_multi_line_string.rb +2 -2
  152. data/{tests/simple_spherical → test/spherical_geography}/tc_multi_point.rb +2 -2
  153. data/{tests/simple_spherical → test/spherical_geography}/tc_multi_polygon.rb +3 -3
  154. data/{tests/simple_spherical → test/spherical_geography}/tc_point.rb +7 -7
  155. data/{tests/simple_spherical → test/spherical_geography}/tc_polygon.rb +2 -2
  156. data/{tests → test}/tc_cartesian_analysis.rb +0 -0
  157. data/{tests → test}/tc_geojson.rb +0 -0
  158. data/{tests → test}/tc_oneoff.rb +2 -1
  159. data/{tests → test}/wkrep/tc_wkb_generator.rb +0 -0
  160. data/{tests → test}/wkrep/tc_wkb_parser.rb +32 -32
  161. data/{tests → test}/wkrep/tc_wkt_generator.rb +0 -0
  162. data/{tests → test}/wkrep/tc_wkt_parser.rb +46 -46
  163. metadata +183 -164
  164. data/lib/rgeo/features/types.rb +0 -272
  165. data/lib/rgeo/geography/simple_mercator/feature_classes.rb +0 -279
  166. data/lib/rgeo/geography/simple_mercator/feature_methods.rb +0 -278
  167. data/lib/rgeo/geography/simple_mercator/projector.rb +0 -112
  168. data/lib/rgeo/geography/simple_spherical.rb +0 -68
  169. data/lib/rgeo/geography/simple_spherical/feature_classes.rb +0 -216
  170. data/tests/simple_spherical/tc_calculations.rb +0 -203
@@ -200,7 +200,7 @@ module RGeo
200
200
 
201
201
 
202
202
  # Returns the southwest corner of the rectangle in _unprojected_
203
- # (lat/lng) space, as a Features::Point object.
203
+ # (lat/lng) space, as a Feature::Point object.
204
204
 
205
205
  def sw_point
206
206
  @sw ||= @factory.unproject(@factory.projection_factory.point(@x_min, @y_min))
@@ -208,7 +208,7 @@ module RGeo
208
208
 
209
209
 
210
210
  # Returns the southeast corner of the rectangle in _unprojected_
211
- # (lat/lng) space, as a Features::Point object.
211
+ # (lat/lng) space, as a Feature::Point object.
212
212
 
213
213
  def se_point
214
214
  @se ||= @factory.unproject(@factory.projection_factory.point(@x_max, @y_min))
@@ -216,7 +216,7 @@ module RGeo
216
216
 
217
217
 
218
218
  # Returns the northwest corner of the rectangle in _unprojected_
219
- # (lat/lng) space, as a Features::Point object.
219
+ # (lat/lng) space, as a Feature::Point object.
220
220
 
221
221
  def nw_point
222
222
  @nw ||= @factory.unproject(@factory.projection_factory.point(@x_min, @y_max))
@@ -224,7 +224,7 @@ module RGeo
224
224
 
225
225
 
226
226
  # Returns the northeast corner of the rectangle in _unprojected_
227
- # (lat/lng) space, as a Features::Point object.
227
+ # (lat/lng) space, as a Feature::Point object.
228
228
 
229
229
  def ne_point
230
230
  @ne ||= @factory.unproject(@factory.projection_factory.point(@x_max, @y_max))
@@ -232,7 +232,7 @@ module RGeo
232
232
 
233
233
 
234
234
  # Returns the center of the rectangle in _unprojected_
235
- # (lat/lng) space, as a Features::Point object.
235
+ # (lat/lng) space, as a Feature::Point object.
236
236
 
237
237
  def center_point
238
238
  @center ||= @factory.unproject(@factory.projection_factory.point(*center_xy))
@@ -240,7 +240,7 @@ module RGeo
240
240
 
241
241
 
242
242
  # Returns a random point the rectangle in _unprojected_
243
- # (lat/lng) space, as a Features::Point object.
243
+ # (lat/lng) space, as a Feature::Point object.
244
244
 
245
245
  def random_point
246
246
  y_ = @y_min + (@y_max - @y_min) * rand
@@ -256,7 +256,7 @@ module RGeo
256
256
 
257
257
 
258
258
  # Returns true if the rectangle contains the given point, which
259
- # must be a Features::Point in _unprojected_ (lat/lng) space.
259
+ # must be a Feature::Point in _unprojected_ (lat/lng) space.
260
260
 
261
261
  def contains_point?(point_)
262
262
  projection_ = @factory.project(point_)
@@ -0,0 +1,133 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Simple mercator projection
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+ # Copyright 2010 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
+ module RGeo
38
+
39
+ module Geography
40
+
41
+
42
+ class SimpleMercatorProjector # :nodoc:
43
+
44
+ EQUATORIAL_RADIUS = 6378137.0
45
+
46
+
47
+ def initialize(geography_factory_, opts_={})
48
+ @geography_factory = geography_factory_
49
+ @projection_factory = Cartesian.preferred_factory(:srid => 3857, :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', :buffer_resolution => opts_[:buffer_resolution], :lenient_multi_polygon_assertions => opts_[:lenient_multi_polygon_assertions], :support_z_coordinate => opts_[:support_z_coordinate], :support_m_coordinate => opts_[:support_m_coordinate])
50
+ end
51
+
52
+
53
+ def projection_factory
54
+ @projection_factory
55
+ end
56
+
57
+
58
+ def project(geometry_)
59
+ case geometry_
60
+ when Feature::Point
61
+ rpd_ = ImplHelper::Math::RADIANS_PER_DEGREE
62
+ radius_ = EQUATORIAL_RADIUS
63
+ @projection_factory.point(geometry_.x * rpd_ * radius_,
64
+ ::Math.log(::Math.tan(::Math::PI / 4.0 + geometry_.y * rpd_ / 2.0)) * radius_)
65
+ when Feature::Line
66
+ @projection_factory.line(project(geometry_.start_point), project(geometry_.end_point))
67
+ when Feature::LinearRing
68
+ @projection_factory.linear_ring(geometry_.points.map{ |p_| project(p_) })
69
+ when Feature::LineString
70
+ @projection_factory.line_string(geometry_.points.map{ |p_| project(p_) })
71
+ when Feature::Polygon
72
+ @projection_factory.polygon(project(geometry_.exterior_ring),
73
+ geometry_.interior_rings.map{ |p_| project(p_) })
74
+ when Feature::MultiPoint
75
+ @projection_factory.multi_point(geometry_.map{ |p_| project(p_) })
76
+ when Feature::MultiLineString
77
+ @projection_factory.multi_line_string(geometry_.map{ |p_| project(p_) })
78
+ when Feature::MultiPolygon
79
+ @projection_factory.multi_polygon(geometry_.map{ |p_| project(p_) })
80
+ when Feature::GeometryCollection
81
+ @projection_factory.collection(geometry_.map{ |p_| project(p_) })
82
+ else
83
+ nil
84
+ end
85
+ end
86
+
87
+
88
+ def unproject(geometry_)
89
+ case geometry_
90
+ when Feature::Point
91
+ dpr_ = ImplHelper::Math::DEGREES_PER_RADIAN
92
+ radius_ = EQUATORIAL_RADIUS
93
+ @geography_factory.point(geometry_.x / radius_ * dpr_,
94
+ (2.0 * ::Math.atan(::Math.exp(geometry_.y / radius_)) - ::Math::PI / 2.0) * dpr_)
95
+ when Feature::Line
96
+ @geography_factory.line(unproject(geometry_.start_point), unproject(geometry_.end_point))
97
+ when Feature::LinearRing
98
+ @geography_factory.linear_ring(geometry_.points.map{ |p_| unproject(p_) })
99
+ when Feature::LineString
100
+ @geography_factory.line_string(geometry_.points.map{ |p_| unproject(p_) })
101
+ when Feature::Polygon
102
+ @geography_factory.polygon(unproject(geometry_.exterior_ring),
103
+ geometry_.interior_rings.map{ |p_| unproject(p_) })
104
+ when Feature::MultiPoint
105
+ @geography_factory.multi_point(geometry_.map{ |p_| unproject(p_) })
106
+ when Feature::MultiLineString
107
+ @geography_factory.multi_line_string(geometry_.map{ |p_| unproject(p_) })
108
+ when Feature::MultiPolygon
109
+ @geography_factory.multi_polygon(geometry_.map{ |p_| unproject(p_) })
110
+ when Feature::GeometryCollection
111
+ @geography_factory.collection(geometry_.map{ |p_| unproject(p_) })
112
+ else
113
+ nil
114
+ end
115
+ end
116
+
117
+
118
+ def wraps?
119
+ true
120
+ end
121
+
122
+
123
+ def limits_window
124
+ @limits_window ||= ProjectedWindow.new(@geography_factory, -20037508.342789, -20037508.342789, 20037508.342789, 20037508.342789, :is_limits => true)
125
+ end
126
+
127
+
128
+ end
129
+
130
+
131
+ end
132
+
133
+ end
@@ -0,0 +1,212 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Spherical geography feature classes
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+ # Copyright 2010 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
+ module RGeo
38
+
39
+ module Geography
40
+
41
+
42
+ class SphericalPointImpl # :nodoc:
43
+
44
+
45
+ include Feature::Point
46
+ include ImplHelper::BasicGeometryMethods
47
+ include ImplHelper::BasicPointMethods
48
+ include SphericalGeometryMethods
49
+
50
+
51
+ def _validate_geometry
52
+ @x = @x % 360.0
53
+ @x -= 360.0 if @x >= 180.0
54
+ @y = 90.0 if @y > 90.0
55
+ @y = -90.0 if @y < -90.0
56
+ super
57
+ end
58
+
59
+
60
+ def _xyz
61
+ @xyz ||= SphericalMath::PointXYZ.from_latlon(@y, @x)
62
+ end
63
+
64
+
65
+ def distance(rhs_)
66
+ rhs_ = Feature.cast(rhs_, @factory)
67
+ case rhs_
68
+ when SphericalPointImpl
69
+ _xyz.dist_to_point(rhs_._xyz) * SphericalMath::RADIUS
70
+ else
71
+ super
72
+ end
73
+ end
74
+
75
+
76
+ def equals?(rhs_)
77
+ return false unless rhs_.is_a?(self.class) && rhs_.factory == self.factory
78
+ case rhs_
79
+ when Feature::Point
80
+ if @y == 90
81
+ rhs_.y == 90
82
+ elsif @y == -90
83
+ rhs_.y == -90
84
+ else
85
+ rhs_.x == @x && rhs_.y == @y
86
+ end
87
+ when Feature::LineString
88
+ rhs_.num_points > 0 && rhs_.points.all?{ |elem_| equals?(elem_) }
89
+ when Feature::GeometryCollection
90
+ rhs_.num_geometries > 0 && rhs_.all?{ |elem_| equals?(elem_) }
91
+ else
92
+ false
93
+ end
94
+ end
95
+
96
+
97
+ alias_method :longitude, :x
98
+ alias_method :lon, :x
99
+ alias_method :latitude, :y
100
+ alias_method :lat, :y
101
+
102
+
103
+ end
104
+
105
+
106
+ class SphericalLineStringImpl # :nodoc:
107
+
108
+
109
+ include Feature::LineString
110
+ include ImplHelper::BasicGeometryMethods
111
+ include ImplHelper::BasicLineStringMethods
112
+ include SphericalGeometryMethods
113
+ include SphericalLineStringMethods
114
+
115
+
116
+ end
117
+
118
+
119
+ class SphericalLineImpl # :nodoc:
120
+
121
+
122
+ include Feature::Line
123
+ include ImplHelper::BasicGeometryMethods
124
+ include ImplHelper::BasicLineStringMethods
125
+ include ImplHelper::BasicLineMethods
126
+ include SphericalGeometryMethods
127
+ include SphericalLineStringMethods
128
+
129
+
130
+ end
131
+
132
+
133
+ class SphericalLinearRingImpl # :nodoc:
134
+
135
+
136
+ include Feature::LinearRing
137
+ include ImplHelper::BasicGeometryMethods
138
+ include ImplHelper::BasicLineStringMethods
139
+ include ImplHelper::BasicLinearRingMethods
140
+ include SphericalGeometryMethods
141
+ include SphericalLineStringMethods
142
+
143
+
144
+ end
145
+
146
+
147
+ class SphericalPolygonImpl # :nodoc:
148
+
149
+
150
+ include Feature::Polygon
151
+ include ImplHelper::BasicGeometryMethods
152
+ include ImplHelper::BasicPolygonMethods
153
+ include SphericalGeometryMethods
154
+
155
+
156
+ end
157
+
158
+
159
+ class SphericalGeometryCollectionImpl # :nodoc:
160
+
161
+
162
+ include Feature::GeometryCollection
163
+ include ImplHelper::BasicGeometryMethods
164
+ include ImplHelper::BasicGeometryCollectionMethods
165
+ include SphericalGeometryMethods
166
+
167
+
168
+ end
169
+
170
+
171
+ class SphericalMultiPointImpl # :nodoc:
172
+
173
+
174
+ include Feature::GeometryCollection
175
+ include ImplHelper::BasicGeometryMethods
176
+ include ImplHelper::BasicGeometryCollectionMethods
177
+ include ImplHelper::BasicMultiPointMethods
178
+ include SphericalGeometryMethods
179
+
180
+
181
+ end
182
+
183
+
184
+ class SphericalMultiLineStringImpl # :nodoc:
185
+
186
+
187
+ include Feature::GeometryCollection
188
+ include ImplHelper::BasicGeometryMethods
189
+ include ImplHelper::BasicGeometryCollectionMethods
190
+ include ImplHelper::BasicMultiLineStringMethods
191
+ include SphericalGeometryMethods
192
+
193
+
194
+ end
195
+
196
+
197
+ class SphericalMultiPolygonImpl # :nodoc:
198
+
199
+
200
+ include Feature::GeometryCollection
201
+ include ImplHelper::BasicGeometryMethods
202
+ include ImplHelper::BasicGeometryCollectionMethods
203
+ include ImplHelper::BasicMultiPolygonMethods
204
+ include SphericalGeometryMethods
205
+
206
+
207
+ end
208
+
209
+
210
+ end
211
+
212
+ end
@@ -38,64 +38,60 @@ module RGeo
38
38
 
39
39
  module Geography
40
40
 
41
- module SimpleSpherical # :nodoc:
41
+
42
+ module SphericalGeometryMethods # :nodoc:
42
43
 
43
44
 
44
- module GeometryMethods # :nodoc:
45
-
46
-
47
- def srid
48
- 4326
49
- end
50
-
51
-
45
+ def srid
46
+ factory.srid
52
47
  end
53
48
 
54
49
 
55
- module LineStringMethods # :nodoc:
56
-
57
-
58
- def _arcs
59
- unless @arcs
60
- @arcs = (0..num_points-2).map do |i_|
61
- ArcXYZ.new(point_n(i_)._xyz, point_n(i_+1)._xyz)
62
- end
50
+ end
51
+
52
+
53
+ module SphericalLineStringMethods # :nodoc:
54
+
55
+
56
+ def _arcs
57
+ unless @arcs
58
+ @arcs = (0..num_points-2).map do |i_|
59
+ SphericalMath::ArcXYZ.new(point_n(i_)._xyz, point_n(i_+1)._xyz)
63
60
  end
64
- @arcs
65
61
  end
66
-
67
-
68
- def is_simple?
69
- arcs_ = _arcs
70
- len_ = arcs_.length
71
- return false if arcs_.any?{ |a_| a_.degenerate? }
72
- return true if len_ == 1
73
- return arcs_[0].s != arcs_[1].e if len_ == 2
74
- arcs_.each_with_index do |arc_, index_|
75
- nindex_ = index_ + 1
76
- nindex_ = nil if nindex_ == len_
77
- return false if nindex_ && arc_.contains_point?(arcs_[nindex_].e)
78
- pindex_ = index_ - 1
79
- pindex_ = nil if pindex_ < 0
80
- return false if pindex_ && arc_.contains_point?(arcs_[pindex_].s)
81
- if nindex_
82
- oindex_ = nindex_ + 1
83
- while oindex_ < len_
84
- oarc_ = arcs_[oindex_]
85
- return false if !(index_ == 0 && oindex_ == len_-1 && arc_.s == oarc_.e) && arc_.intersects_arc?(oarc_)
86
- oindex_ += 1
87
- end
62
+ @arcs
63
+ end
64
+
65
+
66
+ def is_simple?
67
+ arcs_ = _arcs
68
+ len_ = arcs_.length
69
+ return false if arcs_.any?{ |a_| a_.degenerate? }
70
+ return true if len_ == 1
71
+ return arcs_[0].s != arcs_[1].e if len_ == 2
72
+ arcs_.each_with_index do |arc_, index_|
73
+ nindex_ = index_ + 1
74
+ nindex_ = nil if nindex_ == len_
75
+ return false if nindex_ && arc_.contains_point?(arcs_[nindex_].e)
76
+ pindex_ = index_ - 1
77
+ pindex_ = nil if pindex_ < 0
78
+ return false if pindex_ && arc_.contains_point?(arcs_[pindex_].s)
79
+ if nindex_
80
+ oindex_ = nindex_ + 1
81
+ while oindex_ < len_
82
+ oarc_ = arcs_[oindex_]
83
+ return false if !(index_ == 0 && oindex_ == len_-1 && arc_.s == oarc_.e) && arc_.intersects_arc?(oarc_)
84
+ oindex_ += 1
88
85
  end
89
86
  end
90
- true
91
87
  end
92
-
93
-
88
+ true
94
89
  end
95
90
 
96
91
 
97
92
  end
98
93
 
94
+
99
95
  end
100
96
 
101
97
  end