schleyfox-rgeo 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. data/History.rdoc +199 -0
  2. data/README.rdoc +172 -0
  3. data/Spatial_Programming_With_RGeo.rdoc +440 -0
  4. data/Version +1 -0
  5. data/ext/geos_c_impl/extconf.rb +84 -0
  6. data/ext/geos_c_impl/factory.c +468 -0
  7. data/ext/geos_c_impl/factory.h +224 -0
  8. data/ext/geos_c_impl/geometry.c +705 -0
  9. data/ext/geos_c_impl/geometry.h +55 -0
  10. data/ext/geos_c_impl/geometry_collection.c +482 -0
  11. data/ext/geos_c_impl/geometry_collection.h +69 -0
  12. data/ext/geos_c_impl/line_string.c +509 -0
  13. data/ext/geos_c_impl/line_string.h +64 -0
  14. data/ext/geos_c_impl/main.c +70 -0
  15. data/ext/geos_c_impl/point.c +193 -0
  16. data/ext/geos_c_impl/point.h +62 -0
  17. data/ext/geos_c_impl/polygon.c +265 -0
  18. data/ext/geos_c_impl/polygon.h +66 -0
  19. data/ext/geos_c_impl/preface.h +50 -0
  20. data/ext/proj4_c_impl/extconf.rb +88 -0
  21. data/ext/proj4_c_impl/main.c +271 -0
  22. data/lib/rgeo.rb +124 -0
  23. data/lib/rgeo/cartesian.rb +60 -0
  24. data/lib/rgeo/cartesian/analysis.rb +118 -0
  25. data/lib/rgeo/cartesian/bounding_box.rb +337 -0
  26. data/lib/rgeo/cartesian/calculations.rb +161 -0
  27. data/lib/rgeo/cartesian/factory.rb +209 -0
  28. data/lib/rgeo/cartesian/feature_classes.rb +173 -0
  29. data/lib/rgeo/cartesian/feature_methods.rb +106 -0
  30. data/lib/rgeo/cartesian/interface.rb +150 -0
  31. data/lib/rgeo/coord_sys.rb +79 -0
  32. data/lib/rgeo/coord_sys/cs/entities.rb +1524 -0
  33. data/lib/rgeo/coord_sys/cs/factories.rb +208 -0
  34. data/lib/rgeo/coord_sys/cs/wkt_parser.rb +308 -0
  35. data/lib/rgeo/coord_sys/proj4.rb +312 -0
  36. data/lib/rgeo/coord_sys/srs_database/active_record_table.rb +194 -0
  37. data/lib/rgeo/coord_sys/srs_database/interface.rb +165 -0
  38. data/lib/rgeo/coord_sys/srs_database/proj4_data.rb +188 -0
  39. data/lib/rgeo/coord_sys/srs_database/sr_org.rb +108 -0
  40. data/lib/rgeo/coord_sys/srs_database/url_reader.rb +108 -0
  41. data/lib/rgeo/error.rb +63 -0
  42. data/lib/rgeo/feature.rb +88 -0
  43. data/lib/rgeo/feature/curve.rb +156 -0
  44. data/lib/rgeo/feature/factory.rb +332 -0
  45. data/lib/rgeo/feature/factory_generator.rb +138 -0
  46. data/lib/rgeo/feature/geometry.rb +614 -0
  47. data/lib/rgeo/feature/geometry_collection.rb +129 -0
  48. data/lib/rgeo/feature/line.rb +66 -0
  49. data/lib/rgeo/feature/line_string.rb +102 -0
  50. data/lib/rgeo/feature/linear_ring.rb +66 -0
  51. data/lib/rgeo/feature/multi_curve.rb +113 -0
  52. data/lib/rgeo/feature/multi_line_string.rb +66 -0
  53. data/lib/rgeo/feature/multi_point.rb +73 -0
  54. data/lib/rgeo/feature/multi_polygon.rb +97 -0
  55. data/lib/rgeo/feature/multi_surface.rb +116 -0
  56. data/lib/rgeo/feature/point.rb +120 -0
  57. data/lib/rgeo/feature/polygon.rb +141 -0
  58. data/lib/rgeo/feature/surface.rb +122 -0
  59. data/lib/rgeo/feature/types.rb +305 -0
  60. data/lib/rgeo/geographic.rb +75 -0
  61. data/lib/rgeo/geographic/factory.rb +287 -0
  62. data/lib/rgeo/geographic/interface.rb +410 -0
  63. data/lib/rgeo/geographic/proj4_projector.rb +98 -0
  64. data/lib/rgeo/geographic/projected_feature_classes.rb +213 -0
  65. data/lib/rgeo/geographic/projected_feature_methods.rb +228 -0
  66. data/lib/rgeo/geographic/projected_window.rb +467 -0
  67. data/lib/rgeo/geographic/simple_mercator_projector.rb +157 -0
  68. data/lib/rgeo/geographic/spherical_feature_classes.rb +212 -0
  69. data/lib/rgeo/geographic/spherical_feature_methods.rb +97 -0
  70. data/lib/rgeo/geographic/spherical_math.rb +206 -0
  71. data/lib/rgeo/geos.rb +72 -0
  72. data/lib/rgeo/geos/factory.rb +301 -0
  73. data/lib/rgeo/geos/impl_additions.rb +76 -0
  74. data/lib/rgeo/geos/interface.rb +139 -0
  75. data/lib/rgeo/geos/zm_factory.rb +275 -0
  76. data/lib/rgeo/geos/zm_impl.rb +432 -0
  77. data/lib/rgeo/impl_helper.rb +53 -0
  78. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +235 -0
  79. data/lib/rgeo/impl_helper/basic_geometry_methods.rb +85 -0
  80. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +197 -0
  81. data/lib/rgeo/impl_helper/basic_point_methods.rb +138 -0
  82. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +121 -0
  83. data/lib/rgeo/impl_helper/math.rb +50 -0
  84. data/lib/rgeo/version.rb +52 -0
  85. data/lib/rgeo/wkrep.rb +72 -0
  86. data/lib/rgeo/wkrep/wkb_generator.rb +267 -0
  87. data/lib/rgeo/wkrep/wkb_parser.rb +315 -0
  88. data/lib/rgeo/wkrep/wkt_generator.rb +275 -0
  89. data/lib/rgeo/wkrep/wkt_parser.rb +496 -0
  90. data/test/common/geometry_collection_tests.rb +238 -0
  91. data/test/common/line_string_tests.rb +324 -0
  92. data/test/common/multi_line_string_tests.rb +209 -0
  93. data/test/common/multi_point_tests.rb +201 -0
  94. data/test/common/multi_polygon_tests.rb +208 -0
  95. data/test/common/point_tests.rb +331 -0
  96. data/test/common/polygon_tests.rb +232 -0
  97. data/test/coord_sys/tc_active_record_table.rb +102 -0
  98. data/test/coord_sys/tc_ogc_cs.rb +356 -0
  99. data/test/coord_sys/tc_proj4.rb +138 -0
  100. data/test/coord_sys/tc_proj4_srs_data.rb +76 -0
  101. data/test/coord_sys/tc_sr_org.rb +70 -0
  102. data/test/coord_sys/tc_url_reader.rb +82 -0
  103. data/test/geos/tc_factory.rb +91 -0
  104. data/test/geos/tc_geometry_collection.rb +62 -0
  105. data/test/geos/tc_line_string.rb +62 -0
  106. data/test/geos/tc_misc.rb +72 -0
  107. data/test/geos/tc_multi_line_string.rb +62 -0
  108. data/test/geos/tc_multi_point.rb +62 -0
  109. data/test/geos/tc_multi_polygon.rb +63 -0
  110. data/test/geos/tc_point.rb +86 -0
  111. data/test/geos/tc_polygon.rb +86 -0
  112. data/test/geos/tc_zmfactory.rb +85 -0
  113. data/test/projected_geographic/tc_geometry_collection.rb +62 -0
  114. data/test/projected_geographic/tc_line_string.rb +62 -0
  115. data/test/projected_geographic/tc_multi_line_string.rb +62 -0
  116. data/test/projected_geographic/tc_multi_point.rb +62 -0
  117. data/test/projected_geographic/tc_multi_polygon.rb +63 -0
  118. data/test/projected_geographic/tc_point.rb +93 -0
  119. data/test/projected_geographic/tc_polygon.rb +62 -0
  120. data/test/simple_cartesian/tc_calculations.rb +145 -0
  121. data/test/simple_cartesian/tc_geometry_collection.rb +69 -0
  122. data/test/simple_cartesian/tc_line_string.rb +70 -0
  123. data/test/simple_cartesian/tc_multi_line_string.rb +67 -0
  124. data/test/simple_cartesian/tc_multi_point.rb +67 -0
  125. data/test/simple_cartesian/tc_multi_polygon.rb +70 -0
  126. data/test/simple_cartesian/tc_point.rb +91 -0
  127. data/test/simple_cartesian/tc_polygon.rb +67 -0
  128. data/test/simple_mercator/tc_geometry_collection.rb +62 -0
  129. data/test/simple_mercator/tc_line_string.rb +62 -0
  130. data/test/simple_mercator/tc_multi_line_string.rb +62 -0
  131. data/test/simple_mercator/tc_multi_point.rb +62 -0
  132. data/test/simple_mercator/tc_multi_polygon.rb +63 -0
  133. data/test/simple_mercator/tc_point.rb +93 -0
  134. data/test/simple_mercator/tc_polygon.rb +62 -0
  135. data/test/simple_mercator/tc_window.rb +219 -0
  136. data/test/spherical_geographic/tc_calculations.rb +203 -0
  137. data/test/spherical_geographic/tc_geometry_collection.rb +70 -0
  138. data/test/spherical_geographic/tc_line_string.rb +70 -0
  139. data/test/spherical_geographic/tc_multi_line_string.rb +67 -0
  140. data/test/spherical_geographic/tc_multi_point.rb +67 -0
  141. data/test/spherical_geographic/tc_multi_polygon.rb +70 -0
  142. data/test/spherical_geographic/tc_point.rb +100 -0
  143. data/test/spherical_geographic/tc_polygon.rb +67 -0
  144. data/test/tc_cartesian_analysis.rb +107 -0
  145. data/test/tc_oneoff.rb +63 -0
  146. data/test/wkrep/tc_wkb_generator.rb +249 -0
  147. data/test/wkrep/tc_wkb_parser.rb +353 -0
  148. data/test/wkrep/tc_wkt_generator.rb +362 -0
  149. data/test/wkrep/tc_wkt_parser.rb +480 -0
  150. metadata +267 -0
@@ -0,0 +1,157 @@
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 Geographic
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 => 3785,
50
+ :proj4 => SimpleMercatorProjector._proj4_3785,
51
+ :coord_sys => SimpleMercatorProjector._coordsys_3785,
52
+ :buffer_resolution => opts_[:buffer_resolution],
53
+ :lenient_multi_polygon_assertions => opts_[:lenient_multi_polygon_assertions],
54
+ :has_z_coordinate => opts_[:has_z_coordinate],
55
+ :has_m_coordinate => opts_[:has_m_coordinate])
56
+ end
57
+
58
+
59
+ def projection_factory
60
+ @projection_factory
61
+ end
62
+
63
+
64
+ def project(geometry_)
65
+ case geometry_
66
+ when Feature::Point
67
+ rpd_ = ImplHelper::Math::RADIANS_PER_DEGREE
68
+ radius_ = EQUATORIAL_RADIUS
69
+ @projection_factory.point(geometry_.x * rpd_ * radius_,
70
+ ::Math.log(::Math.tan(::Math::PI / 4.0 + geometry_.y * rpd_ / 2.0)) * radius_)
71
+ when Feature::Line
72
+ @projection_factory.line(project(geometry_.start_point), project(geometry_.end_point))
73
+ when Feature::LinearRing
74
+ @projection_factory.linear_ring(geometry_.points.map{ |p_| project(p_) })
75
+ when Feature::LineString
76
+ @projection_factory.line_string(geometry_.points.map{ |p_| project(p_) })
77
+ when Feature::Polygon
78
+ @projection_factory.polygon(project(geometry_.exterior_ring),
79
+ geometry_.interior_rings.map{ |p_| project(p_) })
80
+ when Feature::MultiPoint
81
+ @projection_factory.multi_point(geometry_.map{ |p_| project(p_) })
82
+ when Feature::MultiLineString
83
+ @projection_factory.multi_line_string(geometry_.map{ |p_| project(p_) })
84
+ when Feature::MultiPolygon
85
+ @projection_factory.multi_polygon(geometry_.map{ |p_| project(p_) })
86
+ when Feature::GeometryCollection
87
+ @projection_factory.collection(geometry_.map{ |p_| project(p_) })
88
+ else
89
+ nil
90
+ end
91
+ end
92
+
93
+
94
+ def unproject(geometry_)
95
+ case geometry_
96
+ when Feature::Point
97
+ dpr_ = ImplHelper::Math::DEGREES_PER_RADIAN
98
+ radius_ = EQUATORIAL_RADIUS
99
+ @geography_factory.point(geometry_.x / radius_ * dpr_,
100
+ (2.0 * ::Math.atan(::Math.exp(geometry_.y / radius_)) - ::Math::PI / 2.0) * dpr_)
101
+ when Feature::Line
102
+ @geography_factory.line(unproject(geometry_.start_point), unproject(geometry_.end_point))
103
+ when Feature::LinearRing
104
+ @geography_factory.linear_ring(geometry_.points.map{ |p_| unproject(p_) })
105
+ when Feature::LineString
106
+ @geography_factory.line_string(geometry_.points.map{ |p_| unproject(p_) })
107
+ when Feature::Polygon
108
+ @geography_factory.polygon(unproject(geometry_.exterior_ring),
109
+ geometry_.interior_rings.map{ |p_| unproject(p_) })
110
+ when Feature::MultiPoint
111
+ @geography_factory.multi_point(geometry_.map{ |p_| unproject(p_) })
112
+ when Feature::MultiLineString
113
+ @geography_factory.multi_line_string(geometry_.map{ |p_| unproject(p_) })
114
+ when Feature::MultiPolygon
115
+ @geography_factory.multi_polygon(geometry_.map{ |p_| unproject(p_) })
116
+ when Feature::GeometryCollection
117
+ @geography_factory.collection(geometry_.map{ |p_| unproject(p_) })
118
+ else
119
+ nil
120
+ end
121
+ end
122
+
123
+
124
+ def wraps?
125
+ true
126
+ end
127
+
128
+
129
+ def limits_window
130
+ @limits_window ||= ProjectedWindow.new(@geography_factory,
131
+ -20037508.342789, -20037508.342789, 20037508.342789, 20037508.342789,
132
+ :is_limits => true)
133
+ end
134
+
135
+
136
+ def self._proj4_3785 # :nodoc:
137
+ unless defined?(@proj4_3785)
138
+ @proj4_3785 = CoordSys::Proj4.create('+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=6378137 +b=6378137 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs')
139
+ end
140
+ @proj4_3785
141
+ end
142
+
143
+
144
+ def self._coordsys_3785 # :nodoc:
145
+ unless defined?(@coordsys_3785)
146
+ @coordsys_3785 = CoordSys::CS.create_from_wkt('PROJCS["Popular Visualisation CRS / Mercator",GEOGCS["Popular Visualisation CRS",DATUM["Popular_Visualisation_Datum",SPHEROID["Popular Visualisation Sphere",6378137,0,AUTHORITY["EPSG","7059"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6055"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4055"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],PROJECTION["Mercator_1SP"],PARAMETER["central_meridian",0],PARAMETER["scale_factor",1],PARAMETER["false_easting",0],PARAMETER["false_northing",0],AUTHORITY["EPSG","3785"],AXIS["X",EAST],AXIS["Y",NORTH]]')
147
+ end
148
+ @coordsys_3785
149
+ end
150
+
151
+
152
+ end
153
+
154
+
155
+ end
156
+
157
+ end
@@ -0,0 +1,212 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Spherical geographic 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 Geographic
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
@@ -0,0 +1,97 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Spherical geographic common methods
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 Geographic
40
+
41
+
42
+ module SphericalGeometryMethods # :nodoc:
43
+
44
+
45
+ def srid
46
+ factory.srid
47
+ end
48
+
49
+
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)
60
+ end
61
+ 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
85
+ end
86
+ end
87
+ end
88
+ true
89
+ end
90
+
91
+
92
+ end
93
+
94
+
95
+ end
96
+
97
+ end