rgeo-dschee 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +29 -0
  3. data/ext/geos_c_impl/coordinates.c +65 -0
  4. data/ext/geos_c_impl/coordinates.h +2 -0
  5. data/ext/geos_c_impl/extconf.rb +43 -0
  6. data/ext/geos_c_impl/factory.c +995 -0
  7. data/ext/geos_c_impl/factory.h +238 -0
  8. data/ext/geos_c_impl/geometry.c +1093 -0
  9. data/ext/geos_c_impl/geometry.h +23 -0
  10. data/ext/geos_c_impl/geometry_collection.c +757 -0
  11. data/ext/geos_c_impl/geometry_collection.h +46 -0
  12. data/ext/geos_c_impl/line_string.c +675 -0
  13. data/ext/geos_c_impl/line_string.h +32 -0
  14. data/ext/geos_c_impl/main.c +40 -0
  15. data/ext/geos_c_impl/point.c +236 -0
  16. data/ext/geos_c_impl/point.h +30 -0
  17. data/ext/geos_c_impl/polygon.c +359 -0
  18. data/ext/geos_c_impl/polygon.h +43 -0
  19. data/ext/geos_c_impl/preface.h +38 -0
  20. data/ext/proj4_c_impl/extconf.rb +62 -0
  21. data/ext/proj4_c_impl/main.c +315 -0
  22. data/lib/rgeo.rb +89 -0
  23. data/lib/rgeo/cartesian.rb +25 -0
  24. data/lib/rgeo/cartesian/analysis.rb +77 -0
  25. data/lib/rgeo/cartesian/bounding_box.rb +398 -0
  26. data/lib/rgeo/cartesian/calculations.rb +113 -0
  27. data/lib/rgeo/cartesian/factory.rb +347 -0
  28. data/lib/rgeo/cartesian/feature_classes.rb +100 -0
  29. data/lib/rgeo/cartesian/feature_methods.rb +88 -0
  30. data/lib/rgeo/cartesian/interface.rb +135 -0
  31. data/lib/rgeo/coord_sys.rb +43 -0
  32. data/lib/rgeo/coord_sys/cs/entities.rb +1315 -0
  33. data/lib/rgeo/coord_sys/cs/factories.rb +148 -0
  34. data/lib/rgeo/coord_sys/cs/wkt_parser.rb +272 -0
  35. data/lib/rgeo/coord_sys/proj4.rb +293 -0
  36. data/lib/rgeo/coord_sys/srs_database/interface.rb +115 -0
  37. data/lib/rgeo/coord_sys/srs_database/proj4_data.rb +140 -0
  38. data/lib/rgeo/coord_sys/srs_database/sr_org.rb +62 -0
  39. data/lib/rgeo/coord_sys/srs_database/url_reader.rb +63 -0
  40. data/lib/rgeo/error.rb +27 -0
  41. data/lib/rgeo/feature.rb +54 -0
  42. data/lib/rgeo/feature/curve.rb +111 -0
  43. data/lib/rgeo/feature/factory.rb +278 -0
  44. data/lib/rgeo/feature/factory_generator.rb +96 -0
  45. data/lib/rgeo/feature/geometry.rb +624 -0
  46. data/lib/rgeo/feature/geometry_collection.rb +95 -0
  47. data/lib/rgeo/feature/line.rb +26 -0
  48. data/lib/rgeo/feature/line_string.rb +60 -0
  49. data/lib/rgeo/feature/linear_ring.rb +26 -0
  50. data/lib/rgeo/feature/mixins.rb +143 -0
  51. data/lib/rgeo/feature/multi_curve.rb +71 -0
  52. data/lib/rgeo/feature/multi_line_string.rb +26 -0
  53. data/lib/rgeo/feature/multi_point.rb +33 -0
  54. data/lib/rgeo/feature/multi_polygon.rb +57 -0
  55. data/lib/rgeo/feature/multi_surface.rb +73 -0
  56. data/lib/rgeo/feature/point.rb +84 -0
  57. data/lib/rgeo/feature/polygon.rb +97 -0
  58. data/lib/rgeo/feature/surface.rb +79 -0
  59. data/lib/rgeo/feature/types.rb +284 -0
  60. data/lib/rgeo/geographic.rb +40 -0
  61. data/lib/rgeo/geographic/factory.rb +450 -0
  62. data/lib/rgeo/geographic/interface.rb +489 -0
  63. data/lib/rgeo/geographic/proj4_projector.rb +58 -0
  64. data/lib/rgeo/geographic/projected_feature_classes.rb +107 -0
  65. data/lib/rgeo/geographic/projected_feature_methods.rb +212 -0
  66. data/lib/rgeo/geographic/projected_window.rb +383 -0
  67. data/lib/rgeo/geographic/simple_mercator_projector.rb +110 -0
  68. data/lib/rgeo/geographic/spherical_feature_classes.rb +100 -0
  69. data/lib/rgeo/geographic/spherical_feature_methods.rb +134 -0
  70. data/lib/rgeo/geographic/spherical_math.rb +188 -0
  71. data/lib/rgeo/geos.rb +89 -0
  72. data/lib/rgeo/geos/capi_factory.rb +470 -0
  73. data/lib/rgeo/geos/capi_feature_classes.rb +129 -0
  74. data/lib/rgeo/geos/ffi_factory.rb +592 -0
  75. data/lib/rgeo/geos/ffi_feature_classes.rb +83 -0
  76. data/lib/rgeo/geos/ffi_feature_methods.rb +574 -0
  77. data/lib/rgeo/geos/interface.rb +202 -0
  78. data/lib/rgeo/geos/utils.rb +74 -0
  79. data/lib/rgeo/geos/zm_factory.rb +405 -0
  80. data/lib/rgeo/geos/zm_feature_classes.rb +80 -0
  81. data/lib/rgeo/geos/zm_feature_methods.rb +344 -0
  82. data/lib/rgeo/impl_helper.rb +19 -0
  83. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +185 -0
  84. data/lib/rgeo/impl_helper/basic_geometry_methods.rb +61 -0
  85. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +146 -0
  86. data/lib/rgeo/impl_helper/basic_point_methods.rb +104 -0
  87. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +87 -0
  88. data/lib/rgeo/impl_helper/math.rb +14 -0
  89. data/lib/rgeo/impl_helper/utils.rb +29 -0
  90. data/lib/rgeo/version.rb +3 -0
  91. data/lib/rgeo/wkrep.rb +37 -0
  92. data/lib/rgeo/wkrep/wkb_generator.rb +201 -0
  93. data/lib/rgeo/wkrep/wkb_parser.rb +251 -0
  94. data/lib/rgeo/wkrep/wkt_generator.rb +207 -0
  95. data/lib/rgeo/wkrep/wkt_parser.rb +415 -0
  96. data/lib/rgeo/yaml.rb +23 -0
  97. data/test/cartesian_analysis_test.rb +65 -0
  98. data/test/cartesian_bbox_test.rb +123 -0
  99. data/test/common/factory_tests.rb +78 -0
  100. data/test/common/geometry_collection_tests.rb +237 -0
  101. data/test/common/line_string_tests.rb +330 -0
  102. data/test/common/multi_line_string_tests.rb +182 -0
  103. data/test/common/multi_point_tests.rb +200 -0
  104. data/test/common/multi_polygon_tests.rb +191 -0
  105. data/test/common/point_tests.rb +370 -0
  106. data/test/common/polygon_tests.rb +261 -0
  107. data/test/coord_sys/ogc_cs_test.rb +342 -0
  108. data/test/coord_sys/proj4_srs_data_test.rb +41 -0
  109. data/test/coord_sys/proj4_test.rb +150 -0
  110. data/test/coord_sys/sr_org_test.rb +32 -0
  111. data/test/coord_sys/url_reader_test.rb +42 -0
  112. data/test/geos_capi/factory_test.rb +31 -0
  113. data/test/geos_capi/geometry_collection_test.rb +24 -0
  114. data/test/geos_capi/line_string_test.rb +24 -0
  115. data/test/geos_capi/misc_test.rb +116 -0
  116. data/test/geos_capi/multi_line_string_test.rb +24 -0
  117. data/test/geos_capi/multi_point_test.rb +24 -0
  118. data/test/geos_capi/multi_polygon_test.rb +39 -0
  119. data/test/geos_capi/parsing_unparsing_test.rb +40 -0
  120. data/test/geos_capi/point_test.rb +72 -0
  121. data/test/geos_capi/polygon_test.rb +154 -0
  122. data/test/geos_capi/zmfactory_test.rb +57 -0
  123. data/test/geos_ffi/factory_test.rb +31 -0
  124. data/test/geos_ffi/geometry_collection_test.rb +24 -0
  125. data/test/geos_ffi/line_string_test.rb +24 -0
  126. data/test/geos_ffi/misc_test.rb +63 -0
  127. data/test/geos_ffi/multi_line_string_test.rb +24 -0
  128. data/test/geos_ffi/multi_point_test.rb +24 -0
  129. data/test/geos_ffi/multi_polygon_test.rb +33 -0
  130. data/test/geos_ffi/parsing_unparsing_test.rb +41 -0
  131. data/test/geos_ffi/point_test.rb +77 -0
  132. data/test/geos_ffi/polygon_test.rb +46 -0
  133. data/test/geos_ffi/zmfactory_test.rb +58 -0
  134. data/test/mixins_test.rb +141 -0
  135. data/test/oneoff_test.rb +26 -0
  136. data/test/projected_geographic/factory_test.rb +25 -0
  137. data/test/projected_geographic/geometry_collection_test.rb +24 -0
  138. data/test/projected_geographic/line_string_test.rb +24 -0
  139. data/test/projected_geographic/multi_line_string_test.rb +26 -0
  140. data/test/projected_geographic/multi_point_test.rb +30 -0
  141. data/test/projected_geographic/multi_polygon_test.rb +25 -0
  142. data/test/projected_geographic/point_test.rb +51 -0
  143. data/test/projected_geographic/polygon_test.rb +24 -0
  144. data/test/simple_cartesian/calculations_test.rb +99 -0
  145. data/test/simple_cartesian/factory_test.rb +27 -0
  146. data/test/simple_cartesian/geometry_collection_test.rb +30 -0
  147. data/test/simple_cartesian/line_string_test.rb +31 -0
  148. data/test/simple_cartesian/multi_line_string_test.rb +28 -0
  149. data/test/simple_cartesian/multi_point_test.rb +31 -0
  150. data/test/simple_cartesian/multi_polygon_test.rb +31 -0
  151. data/test/simple_cartesian/point_test.rb +50 -0
  152. data/test/simple_cartesian/polygon_test.rb +28 -0
  153. data/test/simple_mercator/factory_test.rb +25 -0
  154. data/test/simple_mercator/geometry_collection_test.rb +24 -0
  155. data/test/simple_mercator/line_string_test.rb +24 -0
  156. data/test/simple_mercator/multi_line_string_test.rb +26 -0
  157. data/test/simple_mercator/multi_point_test.rb +29 -0
  158. data/test/simple_mercator/multi_polygon_test.rb +25 -0
  159. data/test/simple_mercator/point_test.rb +55 -0
  160. data/test/simple_mercator/polygon_test.rb +24 -0
  161. data/test/simple_mercator/window_test.rb +173 -0
  162. data/test/spherical_geographic/calculations_test.rb +167 -0
  163. data/test/spherical_geographic/factory_test.rb +27 -0
  164. data/test/spherical_geographic/geometry_collection_test.rb +31 -0
  165. data/test/spherical_geographic/line_string_test.rb +31 -0
  166. data/test/spherical_geographic/multi_line_string_test.rb +29 -0
  167. data/test/spherical_geographic/multi_point_test.rb +31 -0
  168. data/test/spherical_geographic/multi_polygon_test.rb +31 -0
  169. data/test/spherical_geographic/point_test.rb +78 -0
  170. data/test/spherical_geographic/polygon_test.rb +28 -0
  171. data/test/types_test.rb +42 -0
  172. data/test/wkrep/wkb_generator_test.rb +185 -0
  173. data/test/wkrep/wkb_parser_test.rb +293 -0
  174. data/test/wkrep/wkt_generator_test.rb +294 -0
  175. data/test/wkrep/wkt_parser_test.rb +412 -0
  176. metadata +386 -0
data/lib/rgeo/geos.rb ADDED
@@ -0,0 +1,89 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # GEOS wrapper for RGeo
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+
7
+ module RGeo
8
+ # The Geos module provides general tools for creating and manipulating
9
+ # a GEOS-backed implementation of the SFS. This is a full implementation
10
+ # of the SFS using a Cartesian coordinate system. It uses the GEOS C++
11
+ # library to perform most operations, and hence is available only if
12
+ # GEOS version 3.2 or later is installed and accessible when the rgeo
13
+ # gem is installed. RGeo feature calls are translated into appropriate
14
+ # GEOS calls and directed to the library's C api. RGeo also corrects a
15
+ # few cases of missing or non-standard behavior in GEOS.
16
+ #
17
+ # This module also provides a namespace for the implementation classes
18
+ # themselves; however, those classes are meant to be opaque and are
19
+ # therefore not documented.
20
+ #
21
+ # To use the Geos implementation, first obtain a factory using the
22
+ # ::RGeo::Geos.factory method. You may then call any of the standard
23
+ # factory methods on the resulting object.
24
+
25
+ module Geos
26
+ end
27
+ end
28
+
29
+ # :stopdoc:
30
+
31
+ module RGeo
32
+ module Geos
33
+ # Implementation files
34
+ require "rgeo/geos/utils"
35
+ require "rgeo/geos/interface"
36
+ begin
37
+ require "rgeo/geos/geos_c_impl"
38
+ rescue ::LoadError; end
39
+ CAPI_SUPPORTED = ::RGeo::Geos.const_defined?(:CAPIGeometryMethods)
40
+ if CAPI_SUPPORTED
41
+ require "rgeo/geos/capi_feature_classes"
42
+ require "rgeo/geos/capi_factory"
43
+ end
44
+ require "rgeo/geos/ffi_feature_methods"
45
+ require "rgeo/geos/ffi_feature_classes"
46
+ require "rgeo/geos/ffi_factory"
47
+ require "rgeo/geos/zm_feature_methods"
48
+ require "rgeo/geos/zm_feature_classes"
49
+ require "rgeo/geos/zm_factory"
50
+
51
+ # Determine ffi support.
52
+ begin
53
+ require "ffi-geos"
54
+ # An additional check to make sure FFI loaded okay. This can fail on
55
+ # some versions of ffi-geos and some versions of Rubinius.
56
+ raise "Problem loading FFI" unless ::FFI::AutoPointer
57
+ FFI_SUPPORTED = true
58
+ FFI_SUPPORT_EXCEPTION = nil
59
+ rescue ::LoadError => ex_
60
+ FFI_SUPPORTED = false
61
+ FFI_SUPPORT_EXCEPTION = ex_
62
+ rescue => ex_
63
+ FFI_SUPPORTED = false
64
+ FFI_SUPPORT_EXCEPTION = ex_
65
+ end
66
+
67
+ # Default preferred native interface
68
+ if CAPI_SUPPORTED
69
+ self.preferred_native_interface = :capi
70
+ elsif FFI_SUPPORTED
71
+ self.preferred_native_interface = :ffi
72
+ end
73
+
74
+ # There is some trouble with END_CAP in GEOS
75
+ # In docs CAP_ROUND = 1, but it's work properly with 0
76
+ CAP_ROUND = 0
77
+ CAP_FLAT = 1
78
+ CAP_SQUARE = 2
79
+
80
+ JOIN_ROUND = 0
81
+ JOIN_MITRE = 1
82
+ JOIN_BEVEL = 2
83
+
84
+ # Init internal utilities
85
+ Utils._init
86
+ end
87
+ end
88
+
89
+ # :startdoc:
@@ -0,0 +1,470 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # GEOS factory implementation
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+
7
+ module RGeo
8
+ module Geos
9
+ # This the GEOS CAPI implementation of ::RGeo::Feature::Factory.
10
+
11
+ class CAPIFactory
12
+ include Feature::Factory::Instance
13
+
14
+ class << self
15
+ # Create a new factory. Returns nil if the GEOS CAPI implementation
16
+ # is not supported.
17
+ #
18
+ # See ::RGeo::Geos.factory for a list of supported options.
19
+
20
+ def create(opts_ = {})
21
+ # Make sure GEOS is available
22
+ return nil unless respond_to?(:_create)
23
+
24
+ # Get flags to pass to the C extension
25
+ flags_ = 0
26
+ flags_ |= 1 if opts_[:uses_lenient_assertions] || opts_[:lenient_multi_polygon_assertions] || opts_[:uses_lenient_multi_polygon_assertions]
27
+ flags_ |= 2 if opts_[:has_z_coordinate]
28
+ flags_ |= 4 if opts_[:has_m_coordinate]
29
+ if flags_ & 6 == 6
30
+ raise Error::UnsupportedOperation, "GEOS cannot support both Z and M coordinates at the same time."
31
+ end
32
+ flags_ |= 8 unless opts_[:auto_prepare] == :disabled
33
+
34
+ # Buffer resolution
35
+ buffer_resolution_ = opts_[:buffer_resolution].to_i
36
+ buffer_resolution_ = 1 if buffer_resolution_ < 1
37
+
38
+ # Interpret the generator options
39
+ wkt_generator_ = opts_[:wkt_generator]
40
+ case wkt_generator_
41
+ when :geos
42
+ wkt_generator_ = nil
43
+ when ::Hash
44
+ wkt_generator_ = WKRep::WKTGenerator.new(wkt_generator_)
45
+ else
46
+ wkt_generator_ = WKRep::WKTGenerator.new(convert_case: :upper)
47
+ end
48
+ wkb_generator_ = opts_[:wkb_generator]
49
+ case wkb_generator_
50
+ when :geos
51
+ wkb_generator_ = nil
52
+ when ::Hash
53
+ wkb_generator_ = WKRep::WKBGenerator.new(wkb_generator_)
54
+ else
55
+ wkb_generator_ = WKRep::WKBGenerator.new
56
+ end
57
+
58
+ # Coordinate system (srid, proj4, and coord_sys)
59
+ srid_ = opts_[:srid]
60
+ proj4_ = opts_[:proj4]
61
+ if CoordSys::Proj4.supported?
62
+ if proj4_.is_a?(::String) || proj4_.is_a?(::Hash)
63
+ proj4_ = CoordSys::Proj4.create(proj4_)
64
+ end
65
+ else
66
+ proj4_ = nil
67
+ end
68
+ coord_sys_ = opts_[:coord_sys]
69
+ if coord_sys_.is_a?(::String)
70
+ coord_sys_ = begin
71
+ CoordSys::CS.create_from_wkt(coord_sys_)
72
+ rescue
73
+ nil
74
+ end
75
+ end
76
+ if (!proj4_ || !coord_sys_) && srid_ && (db_ = opts_[:srs_database])
77
+ entry_ = db_.get(srid_.to_i)
78
+ if entry_
79
+ proj4_ ||= entry_.proj4
80
+ coord_sys_ ||= entry_.coord_sys
81
+ end
82
+ end
83
+ srid_ ||= coord_sys_.authority_code if coord_sys_
84
+
85
+ # Create the factory and set instance variables
86
+ result_ = _create(flags_, srid_.to_i, buffer_resolution_,
87
+ wkt_generator_, wkb_generator_, proj4_, coord_sys_)
88
+
89
+ # Interpret parser options
90
+ wkt_parser_ = opts_[:wkt_parser]
91
+ case wkt_parser_
92
+ when :geos
93
+ wkt_parser_ = nil
94
+ when ::Hash
95
+ wkt_parser_ = WKRep::WKTParser.new(result_, wkt_parser_)
96
+ else
97
+ wkt_parser_ = WKRep::WKTParser.new(result_)
98
+ end
99
+ wkb_parser_ = opts_[:wkb_parser]
100
+ case wkb_parser_
101
+ when :geos
102
+ wkb_parser_ = nil
103
+ when ::Hash
104
+ wkb_parser_ = WKRep::WKBParser.new(result_, wkb_parser_)
105
+ else
106
+ wkb_parser_ = WKRep::WKBParser.new(result_)
107
+ end
108
+ result_._set_wkrep_parsers(wkt_parser_, wkb_parser_)
109
+
110
+ # Return the result
111
+ result_
112
+ end
113
+ alias_method :new, :create
114
+ end
115
+
116
+ # Standard object inspection output
117
+
118
+ def inspect
119
+ "#<#{self.class}:0x#{object_id.to_s(16)} srid=#{_srid} bufres=#{_buffer_resolution} flags=#{_flags}>"
120
+ end
121
+
122
+ # Factory equivalence test.
123
+
124
+ def eql?(rhs_)
125
+ rhs_.is_a?(CAPIFactory) && rhs_.srid == _srid &&
126
+ rhs_._buffer_resolution == _buffer_resolution && rhs_._flags == _flags &&
127
+ rhs_.proj4 == _proj4
128
+ end
129
+ alias_method :==, :eql?
130
+
131
+ # Standard hash code
132
+
133
+ def hash
134
+ @hash ||= [_srid, _buffer_resolution, _flags, _proj4].hash
135
+ end
136
+
137
+ # Marshal support
138
+
139
+ def marshal_dump # :nodoc:
140
+ hash_ = {
141
+ "hasz" => (_flags & 0x2 != 0),
142
+ "hasm" => (_flags & 0x4 != 0),
143
+ "srid" => _srid,
144
+ "bufr" => _buffer_resolution,
145
+ "wktg" => _wkt_generator ? _wkt_generator._properties : {},
146
+ "wkbg" => _wkb_generator ? _wkb_generator._properties : {},
147
+ "wktp" => _wkt_parser ? _wkt_parser._properties : {},
148
+ "wkbp" => _wkb_parser ? _wkb_parser._properties : {},
149
+ "lmpa" => (_flags & 0x1 != 0),
150
+ "apre" => ((_flags & 0x8) >> 3)
151
+ }
152
+ if (proj4_ = _proj4)
153
+ hash_["proj4"] = proj4_.marshal_dump
154
+ end
155
+ if (coord_sys_ = _coord_sys)
156
+ hash_["cs"] = coord_sys_.to_wkt
157
+ end
158
+ hash_
159
+ end
160
+
161
+ def marshal_load(data_) # :nodoc:
162
+ if CoordSys::Proj4.supported? && (proj4_data_ = data_["proj4"])
163
+ proj4_ = CoordSys::Proj4.allocate
164
+ proj4_.marshal_load(proj4_data_)
165
+ else
166
+ proj4_ = nil
167
+ end
168
+ if (coord_sys_data_ = data_["cs"])
169
+ coord_sys_ = CoordSys::CS.create_from_wkt(coord_sys_data_)
170
+ else
171
+ coord_sys_ = nil
172
+ end
173
+ initialize_copy(CAPIFactory.create(
174
+ has_z_coordinate: data_["hasz"],
175
+ has_m_coordinate: data_["hasm"],
176
+ srid: data_["srid"],
177
+ buffer_resolution: data_["bufr"],
178
+ wkt_generator: ImplHelper::Utils.symbolize_hash(data_["wktg"]),
179
+ wkb_generator: ImplHelper::Utils.symbolize_hash(data_["wkbg"]),
180
+ wkt_parser: ImplHelper::Utils.symbolize_hash(data_["wktp"]),
181
+ wkb_parser: ImplHelper::Utils.symbolize_hash(data_["wkbp"]),
182
+ uses_lenient_multi_polygon_assertions: data_["lmpa"],
183
+ auto_prepare: (data_["apre"] == 0 ? :disabled : :simple),
184
+ proj4: proj4_,
185
+ coord_sys: coord_sys_
186
+ ))
187
+ end
188
+
189
+ # Psych support
190
+
191
+ def encode_with(coder_) # :nodoc:
192
+ coder_["has_z_coordinate"] = (_flags & 0x2 != 0)
193
+ coder_["has_m_coordinate"] = (_flags & 0x4 != 0)
194
+ coder_["srid"] = _srid
195
+ coder_["buffer_resolution"] = _buffer_resolution
196
+ coder_["lenient_multi_polygon_assertions"] = (_flags & 0x1 != 0)
197
+ coder_["wkt_generator"] = _wkt_generator ? _wkt_generator._properties : {}
198
+ coder_["wkb_generator"] = _wkb_generator ? _wkb_generator._properties : {}
199
+ coder_["wkt_parser"] = _wkt_parser ? _wkt_parser._properties : {}
200
+ coder_["wkb_parser"] = _wkb_parser ? _wkb_parser._properties : {}
201
+ coder_["auto_prepare"] = ((_flags & 0x8) == 0 ? "disabled" : "simple")
202
+ if (proj4_ = _proj4)
203
+ str_ = proj4_.original_str || proj4_.canonical_str
204
+ coder_["proj4"] = proj4_.radians? ? { "proj4" => str_, "radians" => true } : str_
205
+ end
206
+ if (coord_sys_ = _coord_sys)
207
+ coder_["coord_sys"] = coord_sys_.to_wkt
208
+ end
209
+ end
210
+
211
+ def init_with(coder_) # :nodoc:
212
+ if (proj4_data_ = coder_["proj4"])
213
+ if proj4_data_.is_a?(::Hash)
214
+ proj4_ = CoordSys::Proj4.create(proj4_data_["proj4"], radians: proj4_data_["radians"])
215
+ else
216
+ proj4_ = CoordSys::Proj4.create(proj4_data_.to_s)
217
+ end
218
+ else
219
+ proj4_ = nil
220
+ end
221
+ if (coord_sys_data_ = coder_["cs"])
222
+ coord_sys_ = CoordSys::CS.create_from_wkt(coord_sys_data_.to_s)
223
+ else
224
+ coord_sys_ = nil
225
+ end
226
+ initialize_copy(CAPIFactory.create(
227
+ has_z_coordinate: coder_["has_z_coordinate"],
228
+ has_m_coordinate: coder_["has_m_coordinate"],
229
+ srid: coder_["srid"],
230
+ buffer_resolution: coder_["buffer_resolution"],
231
+ wkt_generator: ImplHelper::Utils.symbolize_hash(coder_["wkt_generator"]),
232
+ wkb_generator: ImplHelper::Utils.symbolize_hash(coder_["wkb_generator"]),
233
+ wkt_parser: ImplHelper::Utils.symbolize_hash(coder_["wkt_parser"]),
234
+ wkb_parser: ImplHelper::Utils.symbolize_hash(coder_["wkb_parser"]),
235
+ auto_prepare: coder_["auto_prepare"] == "disabled" ? :disabled : :simple,
236
+ uses_lenient_multi_polygon_assertions: coder_["lenient_multi_polygon_assertions"],
237
+ proj4: proj4_,
238
+ coord_sys: coord_sys_
239
+ ))
240
+ end
241
+
242
+ # Returns the SRID of geometries created by this factory.
243
+
244
+ def srid
245
+ _srid
246
+ end
247
+
248
+ # Returns the resolution used by buffer calculations on geometries
249
+ # created by this factory
250
+
251
+ def buffer_resolution
252
+ _buffer_resolution
253
+ end
254
+
255
+ # Returns true if this factory is lenient with MultiPolygon assertions
256
+
257
+ def lenient_multi_polygon_assertions?
258
+ _flags & 0x1 != 0
259
+ end
260
+
261
+ # See ::RGeo::Feature::Factory#property
262
+
263
+ def property(name_)
264
+ case name_
265
+ when :has_z_coordinate
266
+ _flags & 0x2 != 0
267
+ when :has_m_coordinate
268
+ _flags & 0x4 != 0
269
+ when :is_cartesian
270
+ true
271
+ when :uses_lenient_multi_polygon_assertions
272
+ _flags & 0x1 != 0
273
+ when :buffer_resolution
274
+ _buffer_resolution
275
+ when :auto_prepare
276
+ _flags & 0x8 != 0 ? :simple : :disabled
277
+ end
278
+ end
279
+
280
+ # See ::RGeo::Feature::Factory#parse_wkt
281
+
282
+ def parse_wkt(str_)
283
+ if (wkt_parser_ = _wkt_parser)
284
+ wkt_parser_.parse(str_)
285
+ else
286
+ _parse_wkt_impl(str_)
287
+ end
288
+ end
289
+
290
+ # See ::RGeo::Feature::Factory#parse_wkb
291
+
292
+ def parse_wkb(str_)
293
+ if (wkb_parser_ = _wkb_parser)
294
+ wkb_parser_.parse(str_)
295
+ else
296
+ _parse_wkb_impl(str_)
297
+ end
298
+ end
299
+
300
+ # See ::RGeo::Feature::Factory#point
301
+
302
+ def point(x_, y_, *extra_)
303
+ if extra_.length > (_flags & 6 == 0 ? 0 : 1)
304
+ nil
305
+ else
306
+ begin
307
+ CAPIPointImpl.create(self, x_, y_, extra_[0].to_f)
308
+ rescue
309
+ nil
310
+ end
311
+ end
312
+ end
313
+
314
+ # See ::RGeo::Feature::Factory#line_string
315
+
316
+ def line_string(points_)
317
+ points_ = points_.to_a unless points_.is_a?(::Array)
318
+ begin
319
+ CAPILineStringImpl.create(self, points_)
320
+ rescue
321
+ nil
322
+ end
323
+ end
324
+
325
+ # See ::RGeo::Feature::Factory#line
326
+
327
+ def line(start_, end_)
328
+ CAPILineImpl.create(self, start_, end_)
329
+ rescue
330
+ nil
331
+ end
332
+
333
+ # See ::RGeo::Feature::Factory#linear_ring
334
+
335
+ def linear_ring(points_)
336
+ points_ = points_.to_a unless points_.is_a?(::Array)
337
+ begin
338
+ CAPILinearRingImpl.create(self, points_)
339
+ rescue
340
+ nil
341
+ end
342
+ end
343
+
344
+ # See ::RGeo::Feature::Factory#polygon
345
+
346
+ def polygon(outer_ring_, inner_rings_ = nil)
347
+ inner_rings_ = inner_rings_.to_a unless inner_rings_.is_a?(::Array)
348
+ begin
349
+ CAPIPolygonImpl.create(self, outer_ring_, inner_rings_)
350
+ rescue
351
+ nil
352
+ end
353
+ end
354
+
355
+ # See ::RGeo::Feature::Factory#collection
356
+
357
+ def collection(elems_)
358
+ elems_ = elems_.to_a unless elems_.is_a?(::Array)
359
+ begin
360
+ CAPIGeometryCollectionImpl.create(self, elems_)
361
+ rescue
362
+ nil
363
+ end
364
+ end
365
+
366
+ # See ::RGeo::Feature::Factory#multi_point
367
+
368
+ def multi_point(elems_)
369
+ elems_ = elems_.to_a unless elems_.is_a?(::Array)
370
+ begin
371
+ CAPIMultiPointImpl.create(self, elems_)
372
+ rescue
373
+ nil
374
+ end
375
+ end
376
+
377
+ # See ::RGeo::Feature::Factory#multi_line_string
378
+
379
+ def multi_line_string(elems_)
380
+ elems_ = elems_.to_a unless elems_.is_a?(::Array)
381
+ begin
382
+ CAPIMultiLineStringImpl.create(self, elems_)
383
+ rescue
384
+ nil
385
+ end
386
+ end
387
+
388
+ # See ::RGeo::Feature::Factory#multi_polygon
389
+
390
+ def multi_polygon(elems_)
391
+ elems_ = elems_.to_a unless elems_.is_a?(::Array)
392
+ begin
393
+ CAPIMultiPolygonImpl.create(self, elems_)
394
+ rescue
395
+ nil
396
+ end
397
+ end
398
+
399
+ # See ::RGeo::Feature::Factory#proj4
400
+
401
+ def proj4
402
+ _proj4
403
+ end
404
+
405
+ # See ::RGeo::Feature::Factory#coord_sys
406
+
407
+ def coord_sys
408
+ _coord_sys
409
+ end
410
+
411
+ # See ::RGeo::Feature::Factory#override_cast
412
+
413
+ def override_cast(original_, ntype_, flags_)
414
+ return nil unless Geos.supported?
415
+ keep_subtype_ = flags_[:keep_subtype]
416
+ # force_new_ = flags_[:force_new]
417
+ project_ = flags_[:project]
418
+ type_ = original_.geometry_type
419
+ ntype_ = type_ if keep_subtype_ && type_.include?(ntype_)
420
+ case original_
421
+ when CAPIGeometryMethods
422
+ # Optimization if we're just changing factories, but the
423
+ # factories are zm-compatible and proj4-compatible.
424
+ if original_.factory != self && ntype_ == type_ &&
425
+ original_.factory._flags & 0x6 == _flags & 0x6 &&
426
+ (!project_ || original_.factory.proj4 == _proj4)
427
+ result_ = original_.dup
428
+ result_._set_factory(self)
429
+ return result_
430
+ end
431
+ # LineString conversion optimization.
432
+ if (original_.factory != self || ntype_ != type_) &&
433
+ original_.factory._flags & 0x6 == _flags & 0x6 &&
434
+ (!project_ || original_.factory.proj4 == _proj4) &&
435
+ type_.subtype_of?(Feature::LineString) && ntype_.subtype_of?(Feature::LineString)
436
+ return IMPL_CLASSES[ntype_]._copy_from(self, original_)
437
+ end
438
+ when ZMGeometryMethods
439
+ # Optimization for just removing a coordinate from an otherwise
440
+ # compatible factory
441
+ if _flags & 0x6 == 0x2 && self == original_.factory.z_factory
442
+ return Feature.cast(original_.z_geometry, ntype_, flags_)
443
+ elsif _flags & 0x6 == 0x4 && self == original_.factory.m_factory
444
+ return Feature.cast(original_.m_geometry, ntype_, flags_)
445
+ end
446
+ end
447
+ false
448
+ end
449
+
450
+ # :stopdoc:
451
+
452
+ IMPL_CLASSES = {
453
+ Feature::Point => CAPIPointImpl,
454
+ Feature::LineString => CAPILineStringImpl,
455
+ Feature::LinearRing => CAPILinearRingImpl,
456
+ Feature::Line => CAPILineImpl,
457
+ Feature::GeometryCollection => CAPIGeometryCollectionImpl,
458
+ Feature::MultiPoint => CAPIMultiPointImpl,
459
+ Feature::MultiLineString => CAPIMultiLineStringImpl,
460
+ Feature::MultiPolygon => CAPIMultiPolygonImpl
461
+ }.freeze
462
+
463
+ # :startdoc:
464
+ end
465
+
466
+ # Deprecated alias of CAPIFactory.
467
+ # Defined primarily to support old YAML serializations.
468
+ Factory = CAPIFactory
469
+ end
470
+ end