rgeo 0.3.3 → 0.3.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.
- data/History.rdoc +6 -0
- data/README.rdoc +1 -1
- data/Version +1 -1
- data/ext/geos_c_impl/extconf.rb +13 -13
- data/ext/geos_c_impl/factory.c +30 -18
- data/ext/geos_c_impl/factory.h +18 -12
- data/ext/geos_c_impl/geometry.c +11 -11
- data/ext/geos_c_impl/geometry.h +7 -7
- data/ext/geos_c_impl/geometry_collection.c +15 -15
- data/ext/geos_c_impl/geometry_collection.h +8 -8
- data/ext/geos_c_impl/line_string.c +14 -14
- data/ext/geos_c_impl/line_string.h +7 -7
- data/ext/geos_c_impl/main.c +7 -7
- data/ext/geos_c_impl/point.c +9 -9
- data/ext/geos_c_impl/point.h +7 -7
- data/ext/geos_c_impl/polygon.c +9 -9
- data/ext/geos_c_impl/polygon.h +7 -7
- data/ext/geos_c_impl/preface.h +7 -7
- data/ext/proj4_c_impl/extconf.rb +13 -13
- data/ext/proj4_c_impl/main.c +12 -12
- data/lib/rgeo.rb +26 -26
- data/lib/rgeo/cartesian.rb +12 -12
- data/lib/rgeo/cartesian/analysis.rb +26 -26
- data/lib/rgeo/cartesian/bounding_box.rb +83 -83
- data/lib/rgeo/cartesian/calculations.rb +36 -36
- data/lib/rgeo/cartesian/factory.rb +78 -78
- data/lib/rgeo/cartesian/feature_classes.rb +74 -74
- data/lib/rgeo/cartesian/feature_methods.rb +34 -34
- data/lib/rgeo/cartesian/interface.rb +33 -33
- data/lib/rgeo/coord_sys.rb +15 -15
- data/lib/rgeo/coord_sys/cs/entities.rb +533 -534
- data/lib/rgeo/coord_sys/cs/factories.rb +69 -69
- data/lib/rgeo/coord_sys/cs/wkt_parser.rb +44 -44
- data/lib/rgeo/coord_sys/proj4.rb +85 -85
- data/lib/rgeo/coord_sys/srs_database/active_record_table.rb +31 -31
- data/lib/rgeo/coord_sys/srs_database/interface.rb +44 -44
- data/lib/rgeo/coord_sys/srs_database/proj4_data.rb +31 -31
- data/lib/rgeo/coord_sys/srs_database/sr_org.rb +31 -31
- data/lib/rgeo/coord_sys/srs_database/url_reader.rb +29 -29
- data/lib/rgeo/error.rb +17 -17
- data/lib/rgeo/feature.rb +15 -15
- data/lib/rgeo/feature/curve.rb +58 -58
- data/lib/rgeo/feature/factory.rb +84 -84
- data/lib/rgeo/feature/factory_generator.rb +32 -32
- data/lib/rgeo/feature/geometry.rb +215 -215
- data/lib/rgeo/feature/geometry_collection.rb +46 -46
- data/lib/rgeo/feature/line.rb +21 -21
- data/lib/rgeo/feature/line_string.rb +35 -35
- data/lib/rgeo/feature/linear_ring.rb +20 -20
- data/lib/rgeo/feature/mixins.rb +61 -61
- data/lib/rgeo/feature/multi_curve.rb +37 -37
- data/lib/rgeo/feature/multi_line_string.rb +20 -20
- data/lib/rgeo/feature/multi_point.rb +22 -22
- data/lib/rgeo/feature/multi_polygon.rb +28 -28
- data/lib/rgeo/feature/multi_surface.rb +39 -39
- data/lib/rgeo/feature/point.rb +42 -42
- data/lib/rgeo/feature/polygon.rb +50 -50
- data/lib/rgeo/feature/surface.rb +42 -42
- data/lib/rgeo/feature/types.rb +58 -58
- data/lib/rgeo/geographic.rb +14 -14
- data/lib/rgeo/geographic/factory.rb +87 -87
- data/lib/rgeo/geographic/interface.rb +55 -55
- data/lib/rgeo/geographic/proj4_projector.rb +35 -35
- data/lib/rgeo/geographic/projected_feature_classes.rb +95 -95
- data/lib/rgeo/geographic/projected_feature_methods.rb +81 -81
- data/lib/rgeo/geographic/projected_window.rb +103 -103
- data/lib/rgeo/geographic/simple_mercator_projector.rb +32 -32
- data/lib/rgeo/geographic/spherical_feature_classes.rb +93 -93
- data/lib/rgeo/geographic/spherical_feature_methods.rb +25 -25
- data/lib/rgeo/geographic/spherical_math.rb +58 -58
- data/lib/rgeo/geos.rb +22 -17
- data/lib/rgeo/geos/factory.rb +93 -93
- data/lib/rgeo/geos/ffi_classes.rb +306 -231
- data/lib/rgeo/geos/ffi_factory.rb +100 -96
- data/lib/rgeo/geos/impl_additions.rb +22 -22
- data/lib/rgeo/geos/interface.rb +45 -45
- data/lib/rgeo/geos/zm_factory.rb +90 -90
- data/lib/rgeo/geos/zm_impl.rb +167 -167
- data/lib/rgeo/impl_helper.rb +11 -11
- data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +71 -71
- data/lib/rgeo/impl_helper/basic_geometry_methods.rb +29 -29
- data/lib/rgeo/impl_helper/basic_line_string_methods.rb +61 -61
- data/lib/rgeo/impl_helper/basic_point_methods.rb +43 -43
- data/lib/rgeo/impl_helper/basic_polygon_methods.rb +35 -35
- data/lib/rgeo/impl_helper/math.rb +13 -13
- data/lib/rgeo/version.rb +10 -10
- data/lib/rgeo/wkrep.rb +16 -16
- data/lib/rgeo/wkrep/wkb_generator.rb +51 -51
- data/lib/rgeo/wkrep/wkb_parser.rb +52 -52
- data/lib/rgeo/wkrep/wkt_generator.rb +51 -51
- data/lib/rgeo/wkrep/wkt_parser.rb +66 -66
- data/lib/rgeo/yaml.rb +14 -14
- data/test/common/geometry_collection_tests.rb +53 -53
- data/test/common/line_string_tests.rb +57 -57
- data/test/common/multi_line_string_tests.rb +43 -43
- data/test/common/multi_point_tests.rb +43 -43
- data/test/common/multi_polygon_tests.rb +43 -43
- data/test/common/point_tests.rb +75 -75
- data/test/common/polygon_tests.rb +37 -37
- data/test/coord_sys/tc_active_record_table.rb +25 -25
- data/test/coord_sys/tc_ogc_cs.rb +72 -72
- data/test/coord_sys/tc_proj4.rb +51 -51
- data/test/coord_sys/tc_proj4_srs_data.rb +17 -17
- data/test/coord_sys/tc_sr_org.rb +15 -15
- data/test/coord_sys/tc_url_reader.rb +19 -19
- data/test/geos_capi/tc_factory.rb +21 -21
- data/test/geos_capi/tc_geometry_collection.rb +15 -15
- data/test/geos_capi/tc_line_string.rb +15 -15
- data/test/geos_capi/tc_misc.rb +33 -22
- data/test/geos_capi/tc_multi_line_string.rb +15 -15
- data/test/geos_capi/tc_multi_point.rb +15 -15
- data/test/geos_capi/tc_multi_polygon.rb +15 -15
- data/test/geos_capi/tc_parsing_unparsing.rb +19 -19
- data/test/geos_capi/tc_point.rb +21 -21
- data/test/geos_capi/tc_polygon.rb +19 -19
- data/test/geos_capi/tc_zmfactory.rb +17 -17
- data/test/geos_ffi/tc_factory.rb +21 -21
- data/test/geos_ffi/tc_geometry_collection.rb +15 -15
- data/test/geos_ffi/tc_line_string.rb +15 -15
- data/test/geos_ffi/tc_misc.rb +49 -15
- data/test/geos_ffi/tc_multi_line_string.rb +15 -15
- data/test/geos_ffi/tc_multi_point.rb +15 -15
- data/test/geos_ffi/tc_multi_polygon.rb +15 -15
- data/test/geos_ffi/tc_parsing_unparsing.rb +19 -19
- data/test/geos_ffi/tc_point.rb +21 -21
- data/test/geos_ffi/tc_polygon.rb +19 -19
- data/test/geos_ffi/tc_zmfactory.rb +17 -17
- data/test/projected_geographic/tc_geometry_collection.rb +15 -15
- data/test/projected_geographic/tc_line_string.rb +15 -15
- data/test/projected_geographic/tc_multi_line_string.rb +15 -15
- data/test/projected_geographic/tc_multi_point.rb +15 -15
- data/test/projected_geographic/tc_multi_polygon.rb +15 -15
- data/test/projected_geographic/tc_point.rb +23 -23
- data/test/projected_geographic/tc_polygon.rb +15 -15
- data/test/simple_cartesian/tc_calculations.rb +31 -31
- data/test/simple_cartesian/tc_geometry_collection.rb +17 -17
- data/test/simple_cartesian/tc_line_string.rb +17 -17
- data/test/simple_cartesian/tc_multi_line_string.rb +17 -17
- data/test/simple_cartesian/tc_multi_point.rb +17 -17
- data/test/simple_cartesian/tc_multi_polygon.rb +17 -17
- data/test/simple_cartesian/tc_point.rb +21 -21
- data/test/simple_cartesian/tc_polygon.rb +17 -17
- data/test/simple_mercator/tc_geometry_collection.rb +15 -15
- data/test/simple_mercator/tc_line_string.rb +15 -15
- data/test/simple_mercator/tc_multi_line_string.rb +15 -15
- data/test/simple_mercator/tc_multi_point.rb +15 -15
- data/test/simple_mercator/tc_multi_polygon.rb +15 -15
- data/test/simple_mercator/tc_point.rb +23 -23
- data/test/simple_mercator/tc_polygon.rb +15 -15
- data/test/simple_mercator/tc_window.rb +50 -50
- data/test/spherical_geographic/tc_calculations.rb +47 -47
- data/test/spherical_geographic/tc_geometry_collection.rb +17 -17
- data/test/spherical_geographic/tc_line_string.rb +17 -17
- data/test/spherical_geographic/tc_multi_line_string.rb +17 -17
- data/test/spherical_geographic/tc_multi_point.rb +17 -17
- data/test/spherical_geographic/tc_multi_polygon.rb +17 -17
- data/test/spherical_geographic/tc_point.rb +23 -23
- data/test/spherical_geographic/tc_polygon.rb +17 -17
- data/test/tc_cartesian_analysis.rb +23 -23
- data/test/tc_mixins.rb +39 -39
- data/test/tc_oneoff.rb +15 -15
- data/test/tc_types.rb +17 -17
- data/test/wkrep/tc_wkb_generator.rb +67 -67
- data/test/wkrep/tc_wkb_parser.rb +73 -73
- data/test/wkrep/tc_wkt_generator.rb +75 -75
- data/test/wkrep/tc_wkt_parser.rb +97 -97
- metadata +3 -3
@@ -1,15 +1,15 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# Well-known text generator for RGeo
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010 Daniel Azuma
|
7
|
-
#
|
6
|
+
# Copyright 2010-2012 Daniel Azuma
|
7
|
+
#
|
8
8
|
# All rights reserved.
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# Redistribution and use in source and binary forms, with or without
|
11
11
|
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# * Redistributions of source code must retain the above copyright notice,
|
14
14
|
# this list of conditions and the following disclaimer.
|
15
15
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
@@ -18,7 +18,7 @@
|
|
18
18
|
# * Neither the name of the copyright holder, nor the names of any other
|
19
19
|
# contributors to this software, may be used to endorse or promote products
|
20
20
|
# derived from this software without specific prior written permission.
|
21
|
-
#
|
21
|
+
#
|
22
22
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
23
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
24
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
@@ -35,23 +35,23 @@
|
|
35
35
|
|
36
36
|
|
37
37
|
module RGeo
|
38
|
-
|
38
|
+
|
39
39
|
module WKRep
|
40
|
-
|
41
|
-
|
40
|
+
|
41
|
+
|
42
42
|
# This class provides the functionality of serializing a geometry as
|
43
43
|
# WKT (well-known text) format. You may also customize the serializer
|
44
44
|
# to generate PostGIS EWKT extensions to the output, or to follow the
|
45
45
|
# Simple Features Specification 1.2 extensions for Z and M.
|
46
|
-
#
|
46
|
+
#
|
47
47
|
# To use this class, create an instance with the desired settings and
|
48
48
|
# customizations, and call the generate method.
|
49
|
-
#
|
49
|
+
#
|
50
50
|
# === Configuration options
|
51
|
-
#
|
51
|
+
#
|
52
52
|
# The following options are recognized. These can be passed to the
|
53
53
|
# constructor, or set on the object afterwards.
|
54
|
-
#
|
54
|
+
#
|
55
55
|
# [<tt>:tag_format</tt>]
|
56
56
|
# The format for tags. Possible values are <tt>:wkt11</tt>,
|
57
57
|
# indicating SFS 1.1 WKT (i.e. no Z or M markers in the tags) but
|
@@ -76,44 +76,44 @@ module RGeo
|
|
76
76
|
# letters to lower case; or nil, indicating no case changes from
|
77
77
|
# the default (which is not specified exactly, but is chosen by the
|
78
78
|
# generator to emphasize readability.) Default is nil.
|
79
|
-
|
79
|
+
|
80
80
|
class WKTGenerator
|
81
|
-
|
82
|
-
|
81
|
+
|
82
|
+
|
83
83
|
# Create and configure a WKT generator. See the WKTGenerator
|
84
84
|
# documentation for the options that can be passed.
|
85
|
-
|
85
|
+
|
86
86
|
def initialize(opts_={})
|
87
87
|
@tag_format = opts_[:tag_format] || opts_[:type_format] || :wkt11
|
88
88
|
@emit_ewkt_srid = opts_[:emit_ewkt_srid] ? true : false if @tag_format == :ewkt
|
89
89
|
@square_brackets = opts_[:square_brackets] ? true : false
|
90
90
|
@convert_case = opts_[:convert_case]
|
91
91
|
end
|
92
|
-
|
93
|
-
|
92
|
+
|
93
|
+
|
94
94
|
# Returns the format for type tags. See WKTGenerator for details.
|
95
95
|
def tag_format
|
96
96
|
@tag_format
|
97
97
|
end
|
98
98
|
alias_method :type_format, :tag_format
|
99
|
-
|
99
|
+
|
100
100
|
# Returns whether SRID is embedded. See WKTGenerator for details.
|
101
101
|
def emit_ewkt_srid?
|
102
102
|
@emit_ewkt_srid
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
# Returns whether square brackets rather than parens are output.
|
106
106
|
# See WKTGenerator for details.
|
107
107
|
def square_brackets?
|
108
108
|
@square_brackets
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
111
|
# Returns the case for output. See WKTGenerator for details.
|
112
112
|
def convert_case
|
113
113
|
@convert_case
|
114
114
|
end
|
115
|
-
|
116
|
-
|
115
|
+
|
116
|
+
|
117
117
|
def _properties # :nodoc:
|
118
118
|
{
|
119
119
|
:tag_format => @tag_format,
|
@@ -122,11 +122,11 @@ module RGeo
|
|
122
122
|
:convert_case => @convert_case,
|
123
123
|
}
|
124
124
|
end
|
125
|
-
|
126
|
-
|
125
|
+
|
126
|
+
|
127
127
|
# Generate and return the WKT format for the given geometry object,
|
128
128
|
# according to the current settings.
|
129
|
-
|
129
|
+
|
130
130
|
def generate(obj_)
|
131
131
|
@begin_bracket = @square_brackets ? '[' : '('
|
132
132
|
@end_bracket = @square_brackets ? ']' : ')'
|
@@ -147,8 +147,8 @@ module RGeo
|
|
147
147
|
str_
|
148
148
|
end
|
149
149
|
end
|
150
|
-
|
151
|
-
|
150
|
+
|
151
|
+
|
152
152
|
def _generate_feature(obj_, toplevel_=false) # :nodoc:
|
153
153
|
type_ = obj_.geometry_type
|
154
154
|
type_ = Feature::LineString if type_.subtype_of?(Feature::LineString)
|
@@ -189,21 +189,21 @@ module RGeo
|
|
189
189
|
raise Error::ParseError, "Unrecognized geometry type: #{type_}"
|
190
190
|
end
|
191
191
|
end
|
192
|
-
|
193
|
-
|
192
|
+
|
193
|
+
|
194
194
|
def _generate_coords(obj_) # :nodoc:
|
195
195
|
str_ = "#{obj_.x.to_s} #{obj_.y.to_s}"
|
196
196
|
str_ << " #{obj_.z.to_s}" if @cur_support_z
|
197
197
|
str_ << " #{obj_.m.to_s}" if @cur_support_m
|
198
198
|
str_
|
199
199
|
end
|
200
|
-
|
201
|
-
|
200
|
+
|
201
|
+
|
202
202
|
def _generate_point(obj_) # :nodoc:
|
203
203
|
"#{@begin_bracket}#{_generate_coords(obj_)}#{@end_bracket}"
|
204
204
|
end
|
205
|
-
|
206
|
-
|
205
|
+
|
206
|
+
|
207
207
|
def _generate_line_string(obj_) # :nodoc:
|
208
208
|
if obj_.is_empty?
|
209
209
|
'EMPTY'
|
@@ -211,8 +211,8 @@ module RGeo
|
|
211
211
|
"#{@begin_bracket}#{obj_.points.map{ |p_| _generate_coords(p_) }.join(', ')}#{@end_bracket}"
|
212
212
|
end
|
213
213
|
end
|
214
|
-
|
215
|
-
|
214
|
+
|
215
|
+
|
216
216
|
def _generate_polygon(obj_) # :nodoc:
|
217
217
|
if obj_.is_empty?
|
218
218
|
'EMPTY'
|
@@ -220,8 +220,8 @@ module RGeo
|
|
220
220
|
"#{@begin_bracket}#{([_generate_line_string(obj_.exterior_ring)] + obj_.interior_rings.map{ |r_| _generate_line_string(r_) }).join(', ')}#{@end_bracket}"
|
221
221
|
end
|
222
222
|
end
|
223
|
-
|
224
|
-
|
223
|
+
|
224
|
+
|
225
225
|
def _generate_geometry_collection(obj_) # :nodoc:
|
226
226
|
if obj_.is_empty?
|
227
227
|
'EMPTY'
|
@@ -229,8 +229,8 @@ module RGeo
|
|
229
229
|
"#{@begin_bracket}#{obj_.map{ |f_| _generate_feature(f_) }.join(', ')}#{@end_bracket}"
|
230
230
|
end
|
231
231
|
end
|
232
|
-
|
233
|
-
|
232
|
+
|
233
|
+
|
234
234
|
def _generate_multi_point(obj_) # :nodoc:
|
235
235
|
if obj_.is_empty?
|
236
236
|
'EMPTY'
|
@@ -238,8 +238,8 @@ module RGeo
|
|
238
238
|
"#{@begin_bracket}#{obj_.map{ |f_| _generate_point(f_) }.join(', ')}#{@end_bracket}"
|
239
239
|
end
|
240
240
|
end
|
241
|
-
|
242
|
-
|
241
|
+
|
242
|
+
|
243
243
|
def _generate_multi_line_string(obj_) # :nodoc:
|
244
244
|
if obj_.is_empty?
|
245
245
|
'EMPTY'
|
@@ -247,8 +247,8 @@ module RGeo
|
|
247
247
|
"#{@begin_bracket}#{obj_.map{ |f_| _generate_line_string(f_) }.join(', ')}#{@end_bracket}"
|
248
248
|
end
|
249
249
|
end
|
250
|
-
|
251
|
-
|
250
|
+
|
251
|
+
|
252
252
|
def _generate_multi_polygon(obj_) # :nodoc:
|
253
253
|
if obj_.is_empty?
|
254
254
|
'EMPTY'
|
@@ -256,11 +256,11 @@ module RGeo
|
|
256
256
|
"#{@begin_bracket}#{obj_.map{ |f_| _generate_polygon(f_) }.join(', ')}#{@end_bracket}"
|
257
257
|
end
|
258
258
|
end
|
259
|
-
|
260
|
-
|
259
|
+
|
260
|
+
|
261
261
|
end
|
262
|
-
|
263
|
-
|
262
|
+
|
263
|
+
|
264
264
|
end
|
265
|
-
|
265
|
+
|
266
266
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# Well-known text parser for RGeo
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010 Daniel Azuma
|
7
|
-
#
|
6
|
+
# Copyright 2010-2012 Daniel Azuma
|
7
|
+
#
|
8
8
|
# All rights reserved.
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# Redistribution and use in source and binary forms, with or without
|
11
11
|
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# * Redistributions of source code must retain the above copyright notice,
|
14
14
|
# this list of conditions and the following disclaimer.
|
15
15
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
@@ -18,7 +18,7 @@
|
|
18
18
|
# * Neither the name of the copyright holder, nor the names of any other
|
19
19
|
# contributors to this software, may be used to endorse or promote products
|
20
20
|
# derived from this software without specific prior written permission.
|
21
|
-
#
|
21
|
+
#
|
22
22
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
23
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
24
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
@@ -38,29 +38,29 @@ require 'strscan'
|
|
38
38
|
|
39
39
|
|
40
40
|
module RGeo
|
41
|
-
|
41
|
+
|
42
42
|
module WKRep
|
43
|
-
|
44
|
-
|
43
|
+
|
44
|
+
|
45
45
|
# This class provides the functionality of parsing a geometry from
|
46
46
|
# WKT (well-known text) format. You may also customize the parser
|
47
47
|
# to recognize PostGIS EWKT extensions to the input, or Simple
|
48
48
|
# Features Specification 1.2 extensions for Z and M coordinates.
|
49
|
-
#
|
49
|
+
#
|
50
50
|
# To use this class, create an instance with the desired settings and
|
51
51
|
# customizations, and call the parse method.
|
52
|
-
#
|
52
|
+
#
|
53
53
|
# === Configuration options
|
54
|
-
#
|
54
|
+
#
|
55
55
|
# You must provide each parser with an RGeo::Feature::FactoryGenerator.
|
56
56
|
# It should understand the configuration options <tt>:srid</tt>,
|
57
57
|
# <tt>:has_z_coordinate</tt>, and <tt>:has_m_coordinate</tt>.
|
58
58
|
# You may also pass a specific RGeo::Feature::Factory, or nil to
|
59
59
|
# specify the default Cartesian FactoryGenerator.
|
60
|
-
#
|
60
|
+
#
|
61
61
|
# The following additional options are recognized. These can be passed
|
62
62
|
# to the constructor, or set on the object afterwards.
|
63
|
-
#
|
63
|
+
#
|
64
64
|
# [<tt>:support_ewkt</tt>]
|
65
65
|
# Activate support for PostGIS EWKT type tags, which appends an "M"
|
66
66
|
# to tags to indicate the presence of M but not Z, and also
|
@@ -80,13 +80,13 @@ module RGeo
|
|
80
80
|
# [<tt>:default_srid</tt>]
|
81
81
|
# A SRID to pass to the factory generator if no SRID is present in
|
82
82
|
# the input. Defaults to nil (i.e. don't specify a SRID).
|
83
|
-
|
83
|
+
|
84
84
|
class WKTParser
|
85
|
-
|
86
|
-
|
85
|
+
|
86
|
+
|
87
87
|
# Create and configure a WKT parser. See the WKTParser
|
88
88
|
# documentation for the options that can be passed.
|
89
|
-
|
89
|
+
|
90
90
|
def initialize(factory_generator_=nil, opts_={})
|
91
91
|
if factory_generator_.kind_of?(Feature::Factory::Instance)
|
92
92
|
@factory_generator = Feature::FactoryGenerator.single(factory_generator_)
|
@@ -104,44 +104,44 @@ module RGeo
|
|
104
104
|
@ignore_extra_tokens = opts_[:ignore_extra_tokens] ? true : false
|
105
105
|
@default_srid = opts_[:default_srid]
|
106
106
|
end
|
107
|
-
|
108
|
-
|
107
|
+
|
108
|
+
|
109
109
|
# Returns the factory generator. See WKTParser for details.
|
110
110
|
def factory_generator
|
111
111
|
@factory_generator
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
# If this parser was given an exact factory, returns it; otherwise
|
115
115
|
# returns nil.
|
116
116
|
def exact_factory
|
117
117
|
@exact_factory
|
118
118
|
end
|
119
|
-
|
119
|
+
|
120
120
|
# Returns true if this parser supports EWKT.
|
121
121
|
# See WKTParser for details.
|
122
122
|
def support_ewkt?
|
123
123
|
@support_ewkt
|
124
124
|
end
|
125
|
-
|
125
|
+
|
126
126
|
# Returns true if this parser supports SFS 1.2 extensions.
|
127
127
|
# See WKTParser for details.
|
128
128
|
def support_wkt12?
|
129
129
|
@support_wkt12
|
130
130
|
end
|
131
|
-
|
131
|
+
|
132
132
|
# Returns true if this parser strictly adheres to WKT 1.1.
|
133
133
|
# See WKTParser for details.
|
134
134
|
def strict_wkt11?
|
135
135
|
@strict_wkt11
|
136
136
|
end
|
137
|
-
|
137
|
+
|
138
138
|
# Returns true if this parser ignores extra tokens.
|
139
139
|
# See WKTParser for details.
|
140
140
|
def ignore_extra_tokens?
|
141
141
|
@ignore_extra_tokens
|
142
142
|
end
|
143
|
-
|
144
|
-
|
143
|
+
|
144
|
+
|
145
145
|
def _properties # :nodoc:
|
146
146
|
{
|
147
147
|
:support_ewkt => @support_ewkt,
|
@@ -151,10 +151,10 @@ module RGeo
|
|
151
151
|
:default_srid => @default_srid,
|
152
152
|
}
|
153
153
|
end
|
154
|
-
|
155
|
-
|
154
|
+
|
155
|
+
|
156
156
|
# Parse the given string, and return a geometry object.
|
157
|
-
|
157
|
+
|
158
158
|
def parse(str_)
|
159
159
|
str_ = str_.downcase
|
160
160
|
@cur_factory = @exact_factory
|
@@ -180,8 +180,8 @@ module RGeo
|
|
180
180
|
end
|
181
181
|
obj_
|
182
182
|
end
|
183
|
-
|
184
|
-
|
183
|
+
|
184
|
+
|
185
185
|
def _check_factory_support # :nodoc:
|
186
186
|
if @cur_expect_z && !@cur_factory_support_z
|
187
187
|
raise Error::ParseError, "Geometry calls for Z coordinate but factory doesn't support it."
|
@@ -190,8 +190,8 @@ module RGeo
|
|
190
190
|
raise Error::ParseError, "Geometry calls for M coordinate but factory doesn't support it."
|
191
191
|
end
|
192
192
|
end
|
193
|
-
|
194
|
-
|
193
|
+
|
194
|
+
|
195
195
|
def _ensure_factory # :nodoc:
|
196
196
|
unless @cur_factory
|
197
197
|
@cur_factory = @factory_generator.call(:srid => @cur_srid, :has_z_coordinate => @cur_expect_z, :has_m_coordinate => @cur_expect_m)
|
@@ -201,8 +201,8 @@ module RGeo
|
|
201
201
|
end
|
202
202
|
@cur_factory
|
203
203
|
end
|
204
|
-
|
205
|
-
|
204
|
+
|
205
|
+
|
206
206
|
def _parse_type_tag(contained_) # :nodoc:
|
207
207
|
_expect_token_type(::String)
|
208
208
|
if @support_ewkt && @cur_token =~ /^(.+)(m)$/
|
@@ -258,8 +258,8 @@ module RGeo
|
|
258
258
|
raise Error::ParseError, "Unknown type tag: #{type_.inspect}."
|
259
259
|
end
|
260
260
|
end
|
261
|
-
|
262
|
-
|
261
|
+
|
262
|
+
|
263
263
|
def _parse_coords # :nodoc:
|
264
264
|
_expect_token_type(::Numeric)
|
265
265
|
x_ = @cur_token
|
@@ -304,8 +304,8 @@ module RGeo
|
|
304
304
|
end
|
305
305
|
@cur_factory.point(x_, y_, *extra_)
|
306
306
|
end
|
307
|
-
|
308
|
-
|
307
|
+
|
308
|
+
|
309
309
|
def _parse_point(convert_empty_=false) # :nodoc:
|
310
310
|
if convert_empty_ && @cur_token == 'empty'
|
311
311
|
point_ = _ensure_factory.multi_point([])
|
@@ -318,8 +318,8 @@ module RGeo
|
|
318
318
|
_next_token
|
319
319
|
point_
|
320
320
|
end
|
321
|
-
|
322
|
-
|
321
|
+
|
322
|
+
|
323
323
|
def _parse_line_string # :nodoc:
|
324
324
|
points_ = []
|
325
325
|
if @cur_token != 'empty'
|
@@ -335,8 +335,8 @@ module RGeo
|
|
335
335
|
_next_token
|
336
336
|
_ensure_factory.line_string(points_)
|
337
337
|
end
|
338
|
-
|
339
|
-
|
338
|
+
|
339
|
+
|
340
340
|
def _parse_polygon # :nodoc:
|
341
341
|
inner_rings_ = []
|
342
342
|
if @cur_token == 'empty'
|
@@ -355,8 +355,8 @@ module RGeo
|
|
355
355
|
_next_token
|
356
356
|
_ensure_factory.polygon(outer_ring_, inner_rings_)
|
357
357
|
end
|
358
|
-
|
359
|
-
|
358
|
+
|
359
|
+
|
360
360
|
def _parse_geometry_collection # :nodoc:
|
361
361
|
geometries_ = []
|
362
362
|
if @cur_token != 'empty'
|
@@ -372,8 +372,8 @@ module RGeo
|
|
372
372
|
_next_token
|
373
373
|
_ensure_factory.collection(geometries_)
|
374
374
|
end
|
375
|
-
|
376
|
-
|
375
|
+
|
376
|
+
|
377
377
|
def _parse_multi_point # :nodoc:
|
378
378
|
points_ = []
|
379
379
|
if @cur_token != 'empty'
|
@@ -395,8 +395,8 @@ module RGeo
|
|
395
395
|
_next_token
|
396
396
|
_ensure_factory.multi_point(points_)
|
397
397
|
end
|
398
|
-
|
399
|
-
|
398
|
+
|
399
|
+
|
400
400
|
def _parse_multi_line_string # :nodoc:
|
401
401
|
line_strings_ = []
|
402
402
|
if @cur_token != 'empty'
|
@@ -412,8 +412,8 @@ module RGeo
|
|
412
412
|
_next_token
|
413
413
|
_ensure_factory.multi_line_string(line_strings_)
|
414
414
|
end
|
415
|
-
|
416
|
-
|
415
|
+
|
416
|
+
|
417
417
|
def _parse_multi_polygon # :nodoc:
|
418
418
|
polygons_ = []
|
419
419
|
if @cur_token != 'empty'
|
@@ -429,27 +429,27 @@ module RGeo
|
|
429
429
|
_next_token
|
430
430
|
_ensure_factory.multi_polygon(polygons_)
|
431
431
|
end
|
432
|
-
|
433
|
-
|
432
|
+
|
433
|
+
|
434
434
|
def _start_scanner(str_) # :nodoc:
|
435
435
|
@_scanner = ::StringScanner.new(str_)
|
436
436
|
_next_token
|
437
437
|
end
|
438
|
-
|
439
|
-
|
438
|
+
|
439
|
+
|
440
440
|
def _clean_scanner # :nodoc:
|
441
441
|
@_scanner = nil
|
442
442
|
@cur_token = nil
|
443
443
|
end
|
444
|
-
|
445
|
-
|
444
|
+
|
445
|
+
|
446
446
|
def _expect_token_type(type_) # :nodoc:
|
447
447
|
unless type_ === @cur_token
|
448
448
|
raise Error::ParseError, "#{type_.inspect} expected but #{@cur_token.inspect} found."
|
449
449
|
end
|
450
450
|
end
|
451
|
-
|
452
|
-
|
451
|
+
|
452
|
+
|
453
453
|
def _next_token # :nodoc:
|
454
454
|
if @_scanner.scan_until(/\(|\)|\[|\]|,|[^\s\(\)\[\],]+/)
|
455
455
|
token_ = @_scanner.matched
|
@@ -472,11 +472,11 @@ module RGeo
|
|
472
472
|
end
|
473
473
|
@cur_token
|
474
474
|
end
|
475
|
-
|
476
|
-
|
475
|
+
|
476
|
+
|
477
477
|
end
|
478
|
-
|
479
|
-
|
478
|
+
|
479
|
+
|
480
480
|
end
|
481
|
-
|
481
|
+
|
482
482
|
end
|