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
@@ -1,112 +0,0 @@
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
- module SimpleMercator # :nodoc:
42
-
43
-
44
- EQUATORIAL_RADIUS = 6378137.0
45
-
46
-
47
- class Projector # :nodoc:
48
-
49
- def initialize(geography_factory_, opts_={})
50
- @geography_factory = geography_factory_
51
- @projection_factory = Cartesian.preferred_factory(:srid => 3857, :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])
52
- end
53
-
54
-
55
- def projection_factory
56
- @projection_factory
57
- end
58
-
59
-
60
- def project(geometry_)
61
- geometry_.projection
62
- end
63
-
64
-
65
- def unproject(geometry_)
66
- case geometry_
67
- when Features::Point
68
- dpr_ = ::RGeo::ImplHelpers::Math::DEGREES_PER_RADIAN
69
- radius_ = EQUATORIAL_RADIUS
70
- @geography_factory.point(geometry_.x / radius_ * dpr_,
71
- (2.0 * ::Math.atan(::Math.exp(geometry_.y / radius_)) - ::Math::PI / 2.0) * dpr_)
72
- when Features::Line
73
- @geography_factory.line(unproject(geometry_.start_point), unproject(geometry_.end_point))
74
- when Features::LinearRing
75
- @geography_factory.linear_ring(geometry_.points.map{ |p_| unproject(p_) })
76
- when Features::LineString
77
- @geography_factory.line_string(geometry_.points.map{ |p_| unproject(p_) })
78
- when Features::Polygon
79
- @geography_factory.polygon(unproject(geometry_.exterior_ring),
80
- geometry_.interior_rings.map{ |p_| unproject(p_) })
81
- when Features::MultiPoint
82
- @geography_factory.multi_point(geometry_.map{ |p_| unproject(p_) })
83
- when Features::MultiLineString
84
- @geography_factory.multi_line_string(geometry_.map{ |p_| unproject(p_) })
85
- when Features::MultiPolygon
86
- @geography_factory.multi_polygon(geometry_.map{ |p_| unproject(p_) })
87
- when Features::GeometryCollection
88
- @geography_factory.collection(geometry_.map{ |p_| unproject(p_) })
89
- else
90
- nil
91
- end
92
- end
93
-
94
-
95
- def wraps?
96
- true
97
- end
98
-
99
-
100
- def limits_window
101
- @limits_window ||= ProjectedWindow.new(@geography_factory, -20037508.342789, -20037508.342789, 20037508.342789, 20037508.342789, :is_limits => true)
102
- end
103
-
104
-
105
- end
106
-
107
-
108
- end
109
-
110
- end
111
-
112
- end
@@ -1,68 +0,0 @@
1
- # -----------------------------------------------------------------------------
2
- #
3
- # Simple spherical geography implementation for RGeo
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
- require 'rgeo/geography'
38
-
39
-
40
- module RGeo
41
-
42
- module Geography
43
-
44
-
45
- # This namespace contains the simple spherical implementation.
46
-
47
- module SimpleSpherical
48
- end
49
-
50
-
51
- end
52
-
53
-
54
- end
55
-
56
-
57
- # Dependency source files.
58
- paths_ = [
59
- 'features',
60
- 'wkrep',
61
- 'impl_helpers',
62
- 'geography/simple_spherical/calculations',
63
- 'geography/simple_spherical/feature_methods',
64
- 'geography/simple_spherical/feature_classes',
65
- 'geography/factory',
66
- 'geography/projected_window',
67
- ]
68
- paths_.each{ |path_| require "rgeo/#{path_}" }
@@ -1,216 +0,0 @@
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
- module SimpleSpherical # :nodoc:
42
-
43
-
44
- class PointImpl # :nodoc:
45
-
46
-
47
- include ::RGeo::Features::Point
48
- include ::RGeo::ImplHelpers::BasicGeometryMethods
49
- include ::RGeo::ImplHelpers::BasicPointMethods
50
- include ::RGeo::Geography::SimpleSpherical::GeometryMethods
51
-
52
-
53
- def _validate_geometry
54
- @x = @x % 360.0
55
- @x -= 360.0 if @x >= 180.0
56
- @y = 90.0 if @y > 90.0
57
- @y = -90.0 if @y < -90.0
58
- super
59
- end
60
-
61
-
62
- def _xyz
63
- @xyz ||= PointXYZ.from_latlon(@y, @x)
64
- end
65
-
66
-
67
- def distance(rhs_)
68
- rhs_ = Features.cast(rhs_, @factory)
69
- case rhs_
70
- when PointImpl
71
- _xyz.dist_to_point(rhs_._xyz) * SimpleSpherical::RADIUS
72
- else
73
- super
74
- end
75
- end
76
-
77
-
78
- def equals?(rhs_)
79
- return false unless rhs_.is_a?(self.class) && rhs_.factory == self.factory
80
- case rhs_
81
- when Features::Point
82
- if @y == 90
83
- rhs_.y == 90
84
- elsif @y == -90
85
- rhs_.y == -90
86
- else
87
- rhs_.x == @x && rhs_.y == @y
88
- end
89
- when Features::LineString
90
- rhs_.num_points > 0 && rhs_.points.all?{ |elem_| equals?(elem_) }
91
- when Features::GeometryCollection
92
- rhs_.num_geometries > 0 && rhs_.all?{ |elem_| equals?(elem_) }
93
- else
94
- false
95
- end
96
- end
97
-
98
-
99
- alias_method :longitude, :x
100
- alias_method :lon, :x
101
- alias_method :latitude, :y
102
- alias_method :lat, :y
103
-
104
-
105
- end
106
-
107
-
108
- class LineStringImpl # :nodoc:
109
-
110
-
111
- include ::RGeo::Features::LineString
112
- include ::RGeo::ImplHelpers::BasicGeometryMethods
113
- include ::RGeo::ImplHelpers::BasicLineStringMethods
114
- include ::RGeo::Geography::SimpleSpherical::GeometryMethods
115
- include ::RGeo::Geography::SimpleSpherical::LineStringMethods
116
-
117
-
118
- end
119
-
120
-
121
- class LineImpl # :nodoc:
122
-
123
-
124
- include ::RGeo::Features::Line
125
- include ::RGeo::ImplHelpers::BasicGeometryMethods
126
- include ::RGeo::ImplHelpers::BasicLineStringMethods
127
- include ::RGeo::ImplHelpers::BasicLineMethods
128
- include ::RGeo::Geography::SimpleSpherical::GeometryMethods
129
- include ::RGeo::Geography::SimpleSpherical::LineStringMethods
130
-
131
-
132
- end
133
-
134
-
135
- class LinearRingImpl # :nodoc:
136
-
137
-
138
- include ::RGeo::Features::Line
139
- include ::RGeo::ImplHelpers::BasicGeometryMethods
140
- include ::RGeo::ImplHelpers::BasicLineStringMethods
141
- include ::RGeo::ImplHelpers::BasicLinearRingMethods
142
- include ::RGeo::Geography::SimpleSpherical::GeometryMethods
143
- include ::RGeo::Geography::SimpleSpherical::LineStringMethods
144
-
145
-
146
- end
147
-
148
-
149
- class PolygonImpl # :nodoc:
150
-
151
-
152
- include ::RGeo::Features::Polygon
153
- include ::RGeo::ImplHelpers::BasicGeometryMethods
154
- include ::RGeo::ImplHelpers::BasicPolygonMethods
155
- include ::RGeo::Geography::SimpleSpherical::GeometryMethods
156
-
157
-
158
- end
159
-
160
-
161
- class GeometryCollectionImpl # :nodoc:
162
-
163
-
164
- include ::RGeo::Features::GeometryCollection
165
- include ::RGeo::ImplHelpers::BasicGeometryMethods
166
- include ::RGeo::ImplHelpers::BasicGeometryCollectionMethods
167
- include ::RGeo::Geography::SimpleSpherical::GeometryMethods
168
-
169
-
170
- end
171
-
172
-
173
- class MultiPointImpl # :nodoc:
174
-
175
-
176
- include ::RGeo::Features::GeometryCollection
177
- include ::RGeo::ImplHelpers::BasicGeometryMethods
178
- include ::RGeo::ImplHelpers::BasicGeometryCollectionMethods
179
- include ::RGeo::ImplHelpers::BasicMultiPointMethods
180
- include ::RGeo::Geography::SimpleSpherical::GeometryMethods
181
-
182
-
183
- end
184
-
185
-
186
- class MultiLineStringImpl # :nodoc:
187
-
188
-
189
- include ::RGeo::Features::GeometryCollection
190
- include ::RGeo::ImplHelpers::BasicGeometryMethods
191
- include ::RGeo::ImplHelpers::BasicGeometryCollectionMethods
192
- include ::RGeo::ImplHelpers::BasicMultiLineStringMethods
193
- include ::RGeo::Geography::SimpleSpherical::GeometryMethods
194
-
195
-
196
- end
197
-
198
-
199
- class MultiPolygonImpl # :nodoc:
200
-
201
-
202
- include ::RGeo::Features::GeometryCollection
203
- include ::RGeo::ImplHelpers::BasicGeometryMethods
204
- include ::RGeo::ImplHelpers::BasicGeometryCollectionMethods
205
- include ::RGeo::ImplHelpers::BasicMultiPolygonMethods
206
- include ::RGeo::Geography::SimpleSpherical::GeometryMethods
207
-
208
-
209
- end
210
-
211
-
212
- end
213
-
214
- end
215
-
216
- end
@@ -1,203 +0,0 @@
1
- # -----------------------------------------------------------------------------
2
- #
3
- # Tests for the internal calculations for simple spherical
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
- require 'test/unit'
38
- require 'rgeo'
39
-
40
-
41
- module RGeo
42
- module Tests # :nodoc:
43
- module SimpleSpherical # :nodoc:
44
-
45
- class TestCalculations < ::Test::Unit::TestCase # :nodoc:
46
-
47
-
48
- def assert_close_enough(v1_, v2_)
49
- diff_ = (v1_ - v2_).abs
50
- # denom_ = (v1_ + v2_).abs
51
- # diff_ /= denom_ if denom_ > 0.01
52
- assert(diff_ < 0.00000001, "#{v1_} is not close to #{v2_}")
53
- end
54
-
55
-
56
- def test_point_eql
57
- point1_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(1, 0, 0)
58
- point2_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(1, 0, 0)
59
- assert_equal(point1_, point2_)
60
- end
61
-
62
-
63
- def test_point_from_latlng
64
- point1_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.from_latlon(45, -45)
65
- assert_close_enough(0.5, point1_.x)
66
- assert_close_enough(-0.5, point1_.y)
67
- assert_close_enough(::Math.sqrt(2) * 0.5, point1_.z)
68
- end
69
-
70
-
71
- def test_point_dot_one
72
- point1_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(1, 1, 1)
73
- point2_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(1, 1, 1)
74
- assert_close_enough(1.0, point1_ * point2_)
75
- end
76
-
77
-
78
- def test_point_dot_minusone
79
- point1_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(1, 1, 1)
80
- point2_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(-1, -1, -1)
81
- assert_close_enough(-1.0, point1_ * point2_)
82
- end
83
-
84
-
85
- def test_point_dot_zero
86
- point1_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(1, 1, 0)
87
- point2_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(1, -1, 0)
88
- assert_close_enough(0.0, point1_ * point2_)
89
- end
90
-
91
-
92
- def test_point_cross
93
- point1_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(1, 1, 0)
94
- point2_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(1, -1, 0)
95
- assert_close_enough(-1.0, (point1_ % point2_).z)
96
- end
97
-
98
-
99
- def test_point_cross_coincident
100
- point1_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(1, 0, 0)
101
- point2_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(1, 0, 0)
102
- assert_nil(point1_ % point2_)
103
- end
104
-
105
-
106
- def test_point_cross_opposite
107
- point1_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(1, 0, 0)
108
- point2_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(-1, 0, 0)
109
- assert_nil(point1_ % point2_)
110
- end
111
-
112
-
113
- def test_arc_axis
114
- point1_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(1, 1, 0)
115
- point2_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(1, -1, 0)
116
- arc1_ = ::RGeo::Geography::SimpleSpherical::ArcXYZ.new(point1_, point2_)
117
- assert_close_enough(-1.0, arc1_.axis.z)
118
- end
119
-
120
-
121
- def test_arc_axis2
122
- point1_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(1, 0, 0)
123
- point2_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(1, 0.000001, 0)
124
- arc1_ = ::RGeo::Geography::SimpleSpherical::ArcXYZ.new(point1_, point2_)
125
- assert_close_enough(1.0, arc1_.axis.z)
126
- end
127
-
128
-
129
- def test_arc_intersects_point_off
130
- point1_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(1, 0, 0)
131
- point2_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(1, 0.000002, 0)
132
- point3_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(1, 0.000001, 0.1)
133
- arc1_ = ::RGeo::Geography::SimpleSpherical::ArcXYZ.new(point1_, point2_)
134
- assert_equal(false, arc1_.contains_point?(point3_))
135
- end
136
-
137
-
138
- def test_arc_intersects_point_between
139
- point1_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(1, 0, 0)
140
- point2_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(1, 0.000002, 0)
141
- point3_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(1, 0.000001, 0)
142
- arc1_ = ::RGeo::Geography::SimpleSpherical::ArcXYZ.new(point1_, point2_)
143
- assert_equal(true, arc1_.contains_point?(point3_))
144
- end
145
-
146
-
147
- def test_arc_intersects_point_endpoint
148
- point1_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(1, 0, 0)
149
- point2_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(1, 0.000002, 0)
150
- arc1_ = ::RGeo::Geography::SimpleSpherical::ArcXYZ.new(point1_, point2_)
151
- assert_equal(true, arc1_.contains_point?(point1_))
152
- end
153
-
154
-
155
- def test_arc_intersects_arc_true
156
- point1_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(0, 0.1, 1)
157
- point2_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(0, -0.1, 1)
158
- point3_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(-0.1, 0, 1)
159
- point4_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(0.1, 0, 1)
160
- arc1_ = ::RGeo::Geography::SimpleSpherical::ArcXYZ.new(point1_, point2_)
161
- arc2_ = ::RGeo::Geography::SimpleSpherical::ArcXYZ.new(point3_, point4_)
162
- assert_equal(true, arc1_.intersects_arc?(arc2_))
163
- end
164
-
165
-
166
- def test_arc_intersects_arc_parallel
167
- point1_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(0, 0.1, 1)
168
- point2_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(0, -0.1, 1)
169
- point3_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(0.1, 0.1, 1)
170
- point4_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(0.1, -0.1, 1)
171
- arc1_ = ::RGeo::Geography::SimpleSpherical::ArcXYZ.new(point1_, point2_)
172
- arc2_ = ::RGeo::Geography::SimpleSpherical::ArcXYZ.new(point3_, point4_)
173
- assert_equal(false, arc1_.intersects_arc?(arc2_))
174
- end
175
-
176
-
177
- def test_arc_intersects_arc_separated_tee
178
- point1_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(0, 0.1, 1)
179
- point2_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(0, -0.1, 1)
180
- point3_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(0.1, 0, 1)
181
- point4_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(0.2, 0, 1)
182
- arc1_ = ::RGeo::Geography::SimpleSpherical::ArcXYZ.new(point1_, point2_)
183
- arc2_ = ::RGeo::Geography::SimpleSpherical::ArcXYZ.new(point3_, point4_)
184
- assert_equal(false, arc1_.intersects_arc?(arc2_))
185
- end
186
-
187
-
188
- def test_arc_intersects_arc_connected_tee
189
- point1_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(0, 0.1, 1)
190
- point2_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(0, -0.1, 1)
191
- point3_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(0, 0, 1)
192
- point4_ = ::RGeo::Geography::SimpleSpherical::PointXYZ.new(0.1, 0, 1)
193
- arc1_ = ::RGeo::Geography::SimpleSpherical::ArcXYZ.new(point1_, point2_)
194
- arc2_ = ::RGeo::Geography::SimpleSpherical::ArcXYZ.new(point3_, point4_)
195
- assert_equal(true, arc1_.intersects_arc?(arc2_))
196
- end
197
-
198
-
199
- end
200
-
201
- end
202
- end
203
- end