rgeo 2.3.1 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +6 -0
  3. data/README.md +23 -14
  4. data/ext/geos_c_impl/analysis.c +30 -25
  5. data/ext/geos_c_impl/analysis.h +8 -7
  6. data/ext/geos_c_impl/coordinates.c +27 -21
  7. data/ext/geos_c_impl/coordinates.h +5 -2
  8. data/ext/geos_c_impl/errors.c +19 -10
  9. data/ext/geos_c_impl/errors.h +11 -4
  10. data/ext/geos_c_impl/extconf.rb +42 -28
  11. data/ext/geos_c_impl/factory.c +540 -451
  12. data/ext/geos_c_impl/factory.h +105 -95
  13. data/ext/geos_c_impl/geometry.c +593 -387
  14. data/ext/geos_c_impl/geometry.h +10 -5
  15. data/ext/geos_c_impl/geometry_collection.c +306 -339
  16. data/ext/geos_c_impl/geometry_collection.h +6 -20
  17. data/ext/geos_c_impl/globals.c +169 -0
  18. data/ext/geos_c_impl/globals.h +46 -0
  19. data/ext/geos_c_impl/line_string.c +271 -231
  20. data/ext/geos_c_impl/line_string.h +5 -8
  21. data/ext/geos_c_impl/main.c +16 -16
  22. data/ext/geos_c_impl/point.c +65 -67
  23. data/ext/geos_c_impl/point.h +4 -7
  24. data/ext/geos_c_impl/polygon.c +137 -135
  25. data/ext/geos_c_impl/polygon.h +11 -11
  26. data/ext/geos_c_impl/preface.h +16 -10
  27. data/ext/geos_c_impl/ruby_more.c +67 -0
  28. data/ext/geos_c_impl/ruby_more.h +25 -0
  29. data/lib/rgeo/cartesian/analysis.rb +5 -3
  30. data/lib/rgeo/cartesian/bounding_box.rb +74 -79
  31. data/lib/rgeo/cartesian/calculations.rb +64 -33
  32. data/lib/rgeo/cartesian/factory.rb +57 -102
  33. data/lib/rgeo/cartesian/feature_classes.rb +68 -46
  34. data/lib/rgeo/cartesian/feature_methods.rb +67 -25
  35. data/lib/rgeo/cartesian/interface.rb +6 -41
  36. data/lib/rgeo/cartesian/planar_graph.rb +373 -0
  37. data/lib/rgeo/cartesian/sweepline_intersector.rb +147 -0
  38. data/lib/rgeo/cartesian/valid_op.rb +69 -0
  39. data/lib/rgeo/cartesian.rb +3 -0
  40. data/lib/rgeo/coord_sys/cs/entities.rb +303 -99
  41. data/lib/rgeo/coord_sys/cs/factories.rb +0 -2
  42. data/lib/rgeo/coord_sys/cs/wkt_parser.rb +90 -42
  43. data/lib/rgeo/coord_sys.rb +1 -20
  44. data/lib/rgeo/error.rb +15 -0
  45. data/lib/rgeo/feature/curve.rb +0 -11
  46. data/lib/rgeo/feature/factory.rb +26 -36
  47. data/lib/rgeo/feature/factory_generator.rb +6 -14
  48. data/lib/rgeo/feature/geometry.rb +146 -66
  49. data/lib/rgeo/feature/geometry_collection.rb +16 -9
  50. data/lib/rgeo/feature/line_string.rb +4 -5
  51. data/lib/rgeo/feature/linear_ring.rb +0 -1
  52. data/lib/rgeo/feature/multi_curve.rb +0 -6
  53. data/lib/rgeo/feature/multi_surface.rb +3 -4
  54. data/lib/rgeo/feature/point.rb +4 -5
  55. data/lib/rgeo/feature/polygon.rb +1 -2
  56. data/lib/rgeo/feature/surface.rb +3 -4
  57. data/lib/rgeo/feature/types.rb +69 -85
  58. data/lib/rgeo/geographic/factory.rb +98 -125
  59. data/lib/rgeo/geographic/interface.rb +69 -166
  60. data/lib/rgeo/geographic/projected_feature_classes.rb +21 -9
  61. data/lib/rgeo/geographic/projected_feature_methods.rb +67 -42
  62. data/lib/rgeo/geographic/projected_window.rb +36 -22
  63. data/lib/rgeo/geographic/{proj4_projector.rb → projector.rb} +3 -5
  64. data/lib/rgeo/geographic/simple_mercator_projector.rb +26 -25
  65. data/lib/rgeo/geographic/spherical_feature_classes.rb +29 -9
  66. data/lib/rgeo/geographic/spherical_feature_methods.rb +86 -9
  67. data/lib/rgeo/geographic/spherical_math.rb +17 -20
  68. data/lib/rgeo/geographic.rb +1 -1
  69. data/lib/rgeo/geos/capi_factory.rb +87 -158
  70. data/lib/rgeo/geos/capi_feature_classes.rb +50 -36
  71. data/lib/rgeo/geos/ffi_factory.rb +105 -173
  72. data/lib/rgeo/geos/ffi_feature_classes.rb +34 -10
  73. data/lib/rgeo/geos/ffi_feature_methods.rb +105 -127
  74. data/lib/rgeo/geos/interface.rb +20 -59
  75. data/lib/rgeo/geos/utils.rb +5 -5
  76. data/lib/rgeo/geos/zm_factory.rb +53 -95
  77. data/lib/rgeo/geos/zm_feature_methods.rb +30 -33
  78. data/lib/rgeo/geos.rb +8 -8
  79. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +9 -22
  80. data/lib/rgeo/impl_helper/basic_geometry_methods.rb +1 -2
  81. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +28 -56
  82. data/lib/rgeo/impl_helper/basic_point_methods.rb +2 -14
  83. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +17 -26
  84. data/lib/rgeo/impl_helper/utils.rb +21 -0
  85. data/lib/rgeo/impl_helper/valid_op.rb +350 -0
  86. data/lib/rgeo/impl_helper/validity_check.rb +139 -0
  87. data/lib/rgeo/impl_helper.rb +1 -0
  88. data/lib/rgeo/version.rb +1 -1
  89. data/lib/rgeo/wkrep/wkb_generator.rb +73 -63
  90. data/lib/rgeo/wkrep/wkb_parser.rb +33 -31
  91. data/lib/rgeo/wkrep/wkt_generator.rb +52 -45
  92. data/lib/rgeo/wkrep/wkt_parser.rb +48 -35
  93. data/lib/rgeo.rb +1 -3
  94. metadata +50 -13
  95. data/lib/rgeo/coord_sys/srs_database/entry.rb +0 -107
  96. data/lib/rgeo/coord_sys/srs_database/sr_org.rb +0 -64
  97. data/lib/rgeo/coord_sys/srs_database/url_reader.rb +0 -65
@@ -6,79 +6,101 @@
6
6
  #
7
7
  # -----------------------------------------------------------------------------
8
8
 
9
+ require_relative "../impl_helper/validity_check"
10
+
9
11
  module RGeo
10
12
  module Cartesian
11
13
  class PointImpl # :nodoc:
12
- include RGeo::Feature::Point
13
- include RGeo::ImplHelper::BasicGeometryMethods
14
- include RGeo::ImplHelper::BasicPointMethods
15
- include RGeo::Cartesian::GeometryMethods
16
- include RGeo::Cartesian::PointMethods
14
+ include Feature::Point
15
+ include ImplHelper::ValidityCheck
16
+ include ImplHelper::BasicGeometryMethods
17
+ include ImplHelper::BasicPointMethods
18
+ include ImplHelper::ValidOp
19
+ include GeometryMethods
20
+ include PointMethods
17
21
  end
18
22
 
19
23
  class LineStringImpl # :nodoc:
20
- include RGeo::Feature::LineString
21
- include RGeo::ImplHelper::BasicGeometryMethods
22
- include RGeo::ImplHelper::BasicLineStringMethods
23
- include RGeo::Cartesian::GeometryMethods
24
- include RGeo::Cartesian::LineStringMethods
24
+ include Feature::LineString
25
+ include ImplHelper::ValidityCheck
26
+ include ImplHelper::BasicGeometryMethods
27
+ include ImplHelper::BasicLineStringMethods
28
+ include ImplHelper::ValidOp
29
+ include GeometryMethods
30
+ include LineStringMethods
25
31
  end
26
32
 
27
33
  class LineImpl # :nodoc:
28
- include RGeo::Feature::Line
29
- include RGeo::ImplHelper::BasicGeometryMethods
30
- include RGeo::ImplHelper::BasicLineStringMethods
31
- include RGeo::ImplHelper::BasicLineMethods
32
- include RGeo::Cartesian::GeometryMethods
33
- include RGeo::Cartesian::LineStringMethods
34
+ include Feature::Line
35
+ include ImplHelper::ValidityCheck
36
+ include ImplHelper::BasicGeometryMethods
37
+ include ImplHelper::BasicLineStringMethods
38
+ include ImplHelper::BasicLineMethods
39
+ include ImplHelper::ValidOp
40
+ include GeometryMethods
41
+ include LineStringMethods
34
42
  end
35
43
 
36
44
  class LinearRingImpl # :nodoc:
37
- include RGeo::Feature::LinearRing
38
- include RGeo::ImplHelper::BasicGeometryMethods
39
- include RGeo::ImplHelper::BasicLineStringMethods
40
- include RGeo::ImplHelper::BasicLinearRingMethods
41
- include RGeo::Cartesian::GeometryMethods
42
- include RGeo::Cartesian::LineStringMethods
45
+ include Feature::LinearRing
46
+ include ImplHelper::ValidityCheck
47
+ include ImplHelper::BasicGeometryMethods
48
+ include ImplHelper::BasicLineStringMethods
49
+ include ImplHelper::BasicLinearRingMethods
50
+ include ImplHelper::ValidOp
51
+ include GeometryMethods
52
+ include LineStringMethods
43
53
  end
44
54
 
45
55
  class PolygonImpl # :nodoc:
46
- include RGeo::Feature::Polygon
47
- include RGeo::ImplHelper::BasicGeometryMethods
48
- include RGeo::ImplHelper::BasicPolygonMethods
49
- include RGeo::Cartesian::GeometryMethods
56
+ include Feature::Polygon
57
+ include ImplHelper::ValidityCheck
58
+ include ImplHelper::BasicGeometryMethods
59
+ include ImplHelper::BasicPolygonMethods
60
+ include ValidOp
61
+ include GeometryMethods
50
62
  end
51
63
 
52
64
  class GeometryCollectionImpl # :nodoc:
53
- include RGeo::Feature::GeometryCollection
54
- include RGeo::ImplHelper::BasicGeometryMethods
55
- include RGeo::ImplHelper::BasicGeometryCollectionMethods
56
- include RGeo::Cartesian::GeometryMethods
65
+ include Feature::GeometryCollection
66
+ include ImplHelper::ValidityCheck
67
+ include ImplHelper::BasicGeometryMethods
68
+ include ImplHelper::BasicGeometryCollectionMethods
69
+ include ImplHelper::ValidOp
70
+ include GeometryMethods
57
71
  end
58
72
 
59
73
  class MultiPointImpl # :nodoc:
60
- include RGeo::Feature::MultiPoint
61
- include RGeo::ImplHelper::BasicGeometryMethods
62
- include RGeo::ImplHelper::BasicGeometryCollectionMethods
63
- include RGeo::ImplHelper::BasicMultiPointMethods
64
- include RGeo::Cartesian::GeometryMethods
74
+ include Feature::MultiPoint
75
+ include ImplHelper::ValidityCheck
76
+ include ImplHelper::BasicGeometryMethods
77
+ include ImplHelper::BasicGeometryCollectionMethods
78
+ include ImplHelper::BasicMultiPointMethods
79
+ include ImplHelper::ValidOp
80
+ include GeometryMethods
65
81
  end
66
82
 
67
83
  class MultiLineStringImpl # :nodoc:
68
- include RGeo::Feature::MultiLineString
69
- include RGeo::ImplHelper::BasicGeometryMethods
70
- include RGeo::ImplHelper::BasicGeometryCollectionMethods
71
- include RGeo::ImplHelper::BasicMultiLineStringMethods
72
- include RGeo::Cartesian::GeometryMethods
73
- include RGeo::Cartesian::MultiLineStringMethods
84
+ include Feature::MultiLineString
85
+ include ImplHelper::ValidityCheck
86
+ include ImplHelper::BasicGeometryMethods
87
+ include ImplHelper::BasicGeometryCollectionMethods
88
+ include ImplHelper::BasicMultiLineStringMethods
89
+ include ImplHelper::ValidOp
90
+ include GeometryMethods
91
+ include MultiLineStringMethods
74
92
  end
75
93
 
76
94
  class MultiPolygonImpl # :nodoc:
77
- include RGeo::Feature::MultiPolygon
78
- include RGeo::ImplHelper::BasicGeometryMethods
79
- include RGeo::ImplHelper::BasicGeometryCollectionMethods
80
- include RGeo::ImplHelper::BasicMultiPolygonMethods
81
- include RGeo::Cartesian::GeometryMethods
95
+ include Feature::MultiPolygon
96
+ include ImplHelper::ValidityCheck
97
+ include ImplHelper::BasicGeometryMethods
98
+ include ImplHelper::BasicGeometryCollectionMethods
99
+ include ImplHelper::BasicMultiPolygonMethods
100
+ include ImplHelper::ValidOp
101
+ include GeometryMethods
82
102
  end
103
+
104
+ ImplHelper::ValidityCheck.override_classes
83
105
  end
84
106
  end
@@ -16,6 +16,28 @@ module RGeo
16
16
  def envelope
17
17
  BoundingBox.new(factory).add(self).to_geometry
18
18
  end
19
+
20
+ def coordinate_dimension
21
+ factory.coordinate_dimension
22
+ end
23
+
24
+ def spatial_dimension
25
+ factory.spatial_dimension
26
+ end
27
+
28
+ def is_3d?
29
+ factory.property(:has_z_coordinate)
30
+ end
31
+
32
+ def measured?
33
+ factory.property(:has_m_coordinate)
34
+ end
35
+
36
+ private
37
+
38
+ def graph
39
+ @graph ||= GeometryGraph.new(self)
40
+ end
19
41
  end
20
42
 
21
43
  module PointMethods # :nodoc:
@@ -50,36 +72,56 @@ module RGeo
50
72
  end
51
73
 
52
74
  def simple?
53
- len = segments.length
54
- return false if segments.any?(&:degenerate?)
55
- return true if len == 1
56
- return segments[0].s != segments[1].e if len == 2
57
- segments.each_with_index do |seg, index|
58
- nindex = index + 1
59
- nindex = nil if nindex == len
60
- return false if nindex && seg.contains_point?(segments[nindex].e)
61
- pindex = index - 1
62
- pindex = nil if pindex < 0
63
- return false if pindex && seg.contains_point?(segments[pindex].s)
64
- next unless nindex
65
- oindex = nindex + 1
66
- while oindex < len
67
- oseg = segments[oindex]
68
- return false if !(index == 0 && oindex == len - 1 && seg.s == oseg.e) && seg.intersects_segment?(oseg)
69
- oindex += 1
70
- end
71
- end
72
- true
73
- end
74
-
75
- def is_simple?
76
- warn "The is_simple? method is deprecated, please use the simple? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
77
- simple?
75
+ # Use a SweeplineIntersector to determine if there are any self-intersections
76
+ # in the ring. The GeometryGraph of the ring could be used by comparing the
77
+ # edges to number of segments (graph.incident_edges.length == segments.length),
78
+ # but this adds computational and memory overhead if graph isn't already memoized.
79
+ # Since graph is not used elsewhere in LineStringMethods, we will just use the
80
+ # SweeplineIntersector for now.
81
+ li = SweeplineIntersector.new(segments)
82
+ li.proper_intersections.empty?
78
83
  end
79
84
 
80
85
  def length
81
86
  segments.inject(0.0) { |sum, seg| sum + seg.length }
82
87
  end
88
+
89
+ def crosses?(rhs)
90
+ case rhs
91
+ when Feature::LineString
92
+ crosses_line_string?(rhs)
93
+ else
94
+ super
95
+ end
96
+ end
97
+
98
+ private
99
+
100
+ # Determines if a cross occurs with another linestring.
101
+ # Process is to get the number of proper intersections in each geom
102
+ # then overlay and get the number of proper intersections from that.
103
+ # If the overlaid number is higher than the sum of individual self-ints
104
+ # then there is an intersection. Finally, we need to check the intersection
105
+ # to see that it is not a boundary point of either segment.
106
+ #
107
+ # @param rhs [Feature::LineString]
108
+ #
109
+ # @return [Boolean]
110
+ def crosses_line_string?(rhs)
111
+ self_ints = SweeplineIntersector.new(segments).proper_intersections
112
+ self_ints += SweeplineIntersector.new(rhs.segments).proper_intersections
113
+ overlay_ints = SweeplineIntersector.new(segments + rhs.segments).proper_intersections
114
+
115
+ (overlay_ints - self_ints).each do |int|
116
+ s1s = int.s1.s
117
+ s1e = int.s1.e
118
+ s2s = int.s2.s
119
+ s2e = int.s2.e
120
+ return true unless [s1s, s1e, s2s, s2e].include?(int.point)
121
+ end
122
+
123
+ false
124
+ end
83
125
  end
84
126
 
85
127
  module MultiLineStringMethods # :nodoc:
@@ -61,29 +61,19 @@ module RGeo
61
61
  # [<tt>:srid</tt>]
62
62
  # Set the SRID returned by geometries created by this factory.
63
63
  # Default is 0.
64
- # [<tt>:proj4</tt>]
65
- # The coordinate system in Proj4 format, either as a
66
- # CoordSys::Proj4 object or as a string or hash representing the
67
- # proj4 format. Optional.
68
64
  # [<tt>:coord_sys</tt>]
69
65
  # The coordinate system in OGC form, either as a subclass of
70
66
  # CoordSys::CS::CoordinateSystem, or as a string in WKT format.
71
- # Optional.
72
- # [<tt>:srs_database</tt>]
73
- # Optional. If provided, the value should be an implementation of
74
- # CoordSys::SRSDatabase::Interface. If both this and an SRID are
75
- # provided, they are used to look up the proj4 and coord_sys
76
- # objects from a spatial reference system database.
67
+ # Optional. If no coord_sys is given, but an SRID is the factory
68
+ # will try to create one using the CoordSys::CONFIG.default_coord_sys_class
69
+ # or the given :coord_sys_class option.
70
+ # [<tt>:coord_sys_class</tt>]
71
+ # CoordSys::CS::CoordinateSystem implementation used to instansiate
72
+ # a coord_sys based on the :srid given.
77
73
  # [<tt>:has_z_coordinate</tt>]
78
74
  # Support a Z coordinate. Default is false.
79
75
  # [<tt>:has_m_coordinate</tt>]
80
76
  # Support an M coordinate. Default is false.
81
- # [<tt>:uses_lenient_assertions</tt>]
82
- # If set to true, assertion checking is disabled. This includes
83
- # simplicity checking on LinearRing, and validity checks on
84
- # Polygon and MultiPolygon. This may speed up creation of certain
85
- # objects, at the expense of not doing the proper checking for
86
- # OGC compliance. Default is false.
87
77
  # [<tt>:wkt_parser</tt>]
88
78
  # Configure the parser for WKT. The value is a hash of
89
79
  # configuration parameters for WKRep::WKTParser.new. Default is
@@ -107,31 +97,6 @@ module RGeo
107
97
  def simple_factory(opts = {})
108
98
  Cartesian::Factory.new(opts)
109
99
  end
110
-
111
- # Returns a Feature::FactoryGenerator that creates preferred
112
- # factories. The given options are used as the default options.
113
- #
114
- # A common case for this is to provide the <tt>:srs_database</tt>
115
- # as a default. Then, the factory generator need only be passed
116
- # an SRID and it will automatically fetch the appropriate Proj4
117
- # and CoordSys objects.
118
-
119
- def preferred_factory_generator(defaults = {})
120
- proc { |c| preferred_factory(defaults.merge(c)) }
121
- end
122
- alias factory_generator preferred_factory_generator
123
-
124
- # Returns a Feature::FactoryGenerator that creates simple factories.
125
- # The given options are used as the default options.
126
- #
127
- # A common case for this is to provide the <tt>:srs_database</tt>
128
- # as a default. Then, the factory generator need only be passed
129
- # an SRID and it will automatically fetch the appropriate Proj4
130
- # and CoordSys objects.
131
-
132
- def simple_factory_generator(defaults = {})
133
- proc { |c| simple_factory(defaults.merge(c)) }
134
- end
135
100
  end
136
101
  end
137
102
  end