rgeo 1.1.2 → 2.0.0
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.
- checksums.yaml +4 -4
- data/ext/geos_c_impl/extconf.rb +5 -3
- data/ext/geos_c_impl/factory.c +4 -4
- data/ext/geos_c_impl/geometry.c +1 -1
- data/lib/rgeo.rb +2 -4
- data/lib/rgeo/cartesian.rb +6 -16
- data/lib/rgeo/cartesian/analysis.rb +22 -20
- data/lib/rgeo/cartesian/bounding_box.rb +83 -79
- data/lib/rgeo/cartesian/calculations.rb +40 -38
- data/lib/rgeo/cartesian/factory.rb +134 -169
- data/lib/rgeo/cartesian/feature_classes.rb +2 -18
- data/lib/rgeo/cartesian/feature_methods.rb +37 -39
- data/lib/rgeo/cartesian/interface.rb +11 -9
- data/lib/rgeo/coord_sys.rb +9 -8
- data/lib/rgeo/coord_sys/cs/entities.rb +345 -303
- data/lib/rgeo/coord_sys/cs/factories.rb +30 -28
- data/lib/rgeo/coord_sys/cs/wkt_parser.rb +128 -126
- data/lib/rgeo/coord_sys/srs_database/{interface.rb → entry.rb} +26 -32
- data/lib/rgeo/coord_sys/srs_database/sr_org.rb +19 -17
- data/lib/rgeo/coord_sys/srs_database/url_reader.rb +21 -19
- data/lib/rgeo/error.rb +3 -1
- data/lib/rgeo/feature.rb +23 -34
- data/lib/rgeo/feature/curve.rb +2 -0
- data/lib/rgeo/feature/factory.rb +15 -13
- data/lib/rgeo/feature/factory_generator.rb +7 -5
- data/lib/rgeo/feature/geometry.rb +31 -29
- data/lib/rgeo/feature/geometry_collection.rb +6 -4
- data/lib/rgeo/feature/line.rb +2 -0
- data/lib/rgeo/feature/line_string.rb +3 -1
- data/lib/rgeo/feature/linear_ring.rb +2 -0
- data/lib/rgeo/feature/multi_curve.rb +2 -0
- data/lib/rgeo/feature/multi_line_string.rb +2 -0
- data/lib/rgeo/feature/multi_point.rb +2 -0
- data/lib/rgeo/feature/multi_polygon.rb +2 -0
- data/lib/rgeo/feature/multi_surface.rb +2 -0
- data/lib/rgeo/feature/point.rb +2 -0
- data/lib/rgeo/feature/polygon.rb +3 -1
- data/lib/rgeo/feature/surface.rb +2 -0
- data/lib/rgeo/feature/types.rb +107 -103
- data/lib/rgeo/geographic.rb +17 -27
- data/lib/rgeo/geographic/factory.rb +154 -199
- data/lib/rgeo/geographic/interface.rb +141 -137
- data/lib/rgeo/geographic/proj4_projector.rb +28 -23
- data/lib/rgeo/geographic/projected_feature_classes.rb +2 -18
- data/lib/rgeo/geographic/projected_feature_methods.rb +59 -49
- data/lib/rgeo/geographic/projected_window.rb +4 -2
- data/lib/rgeo/geographic/simple_mercator_projector.rb +41 -39
- data/lib/rgeo/geographic/spherical_feature_classes.rb +2 -18
- data/lib/rgeo/geographic/spherical_feature_methods.rb +67 -67
- data/lib/rgeo/geographic/spherical_math.rb +81 -87
- data/lib/rgeo/geos.rb +23 -34
- data/lib/rgeo/geos/capi_factory.rb +106 -135
- data/lib/rgeo/geos/capi_feature_classes.rb +19 -37
- data/lib/rgeo/geos/ffi_factory.rb +276 -297
- data/lib/rgeo/geos/ffi_feature_classes.rb +2 -20
- data/lib/rgeo/geos/ffi_feature_methods.rb +170 -166
- data/lib/rgeo/geos/interface.rb +25 -23
- data/lib/rgeo/geos/utils.rb +47 -39
- data/lib/rgeo/geos/zm_factory.rb +171 -185
- data/lib/rgeo/geos/zm_feature_classes.rb +2 -20
- data/lib/rgeo/geos/zm_feature_methods.rb +76 -72
- data/lib/rgeo/impl_helper.rb +1 -11
- data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +72 -75
- data/lib/rgeo/impl_helper/basic_geometry_methods.rb +21 -23
- data/lib/rgeo/impl_helper/basic_line_string_methods.rb +57 -49
- data/lib/rgeo/impl_helper/basic_point_methods.rb +29 -25
- data/lib/rgeo/impl_helper/basic_polygon_methods.rb +31 -27
- data/lib/rgeo/impl_helper/math.rb +2 -0
- data/lib/rgeo/impl_helper/utils.rb +9 -15
- data/lib/rgeo/version.rb +3 -1
- data/lib/rgeo/wkrep.rb +20 -30
- data/lib/rgeo/wkrep/wkb_generator.rb +87 -84
- data/lib/rgeo/wkrep/wkb_parser.rb +93 -93
- data/lib/rgeo/wkrep/wkt_generator.rb +67 -63
- data/lib/rgeo/wkrep/wkt_parser.rb +172 -168
- metadata +17 -32
- data/lib/rgeo/feature/mixins.rb +0 -143
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# -----------------------------------------------------------------------------
|
2
4
|
#
|
3
5
|
# OGC CS factory for RGeo
|
@@ -40,31 +42,31 @@ module RGeo
|
|
40
42
|
# Create a CompoundCoordinateSystem from a name, and two
|
41
43
|
# constituent coordinate systems.
|
42
44
|
|
43
|
-
def create_compound_coordinate_system(
|
44
|
-
CompoundCoordinateSystem.create(
|
45
|
+
def create_compound_coordinate_system(name, head, tail)
|
46
|
+
CompoundCoordinateSystem.create(name, head, tail)
|
45
47
|
end
|
46
48
|
|
47
49
|
# Create an Ellipsoid from a name, semi-major axis, and semi-minor
|
48
50
|
# axis. You can also provide a LinearUnit, but this is optional
|
49
51
|
# and may be set to nil.
|
50
52
|
|
51
|
-
def create_ellipsoid(
|
52
|
-
Ellipsoid.create_ellipsoid(
|
53
|
+
def create_ellipsoid(name, semi_major_axis, semi_minor_axis, linear_unit)
|
54
|
+
Ellipsoid.create_ellipsoid(name, semi_major_axis, semi_minor_axis, linear_unit)
|
53
55
|
end
|
54
56
|
|
55
57
|
# Create an Ellipsoid from a name, semi-major axis, and an inverse
|
56
58
|
# flattening factor. You can also provide a LinearUnit, but this
|
57
59
|
# is optional and may be set to nil.
|
58
60
|
|
59
|
-
def create_flattened_sphere(
|
60
|
-
Ellipsoid.create_flattened_sphere(
|
61
|
+
def create_flattened_sphere(name, semi_major_axis, inverse_flattening, linear_unit)
|
62
|
+
Ellipsoid.create_flattened_sphere(name, semi_major_axis, inverse_flattening, linear_unit)
|
61
63
|
end
|
62
64
|
|
63
65
|
# Create any object given the OGC WKT format. Raises
|
64
66
|
# Error::ParseError if a syntax error is encounterred.
|
65
67
|
|
66
|
-
def create_from_wkt(
|
67
|
-
WKTParser.new(
|
68
|
+
def create_from_wkt(str)
|
69
|
+
WKTParser.new(str).parse
|
68
70
|
end
|
69
71
|
|
70
72
|
# Create a GeographicCoordinateSystem, given a name, an
|
@@ -72,36 +74,36 @@ module RGeo
|
|
72
74
|
# AxisInfo objects. The AxisInfo objects are optional and may be
|
73
75
|
# set to nil.
|
74
76
|
|
75
|
-
def create_geographic_coordinate_system(
|
76
|
-
GeographicCoordinateSystem.create(
|
77
|
+
def create_geographic_coordinate_system(name, angular_unit, horizontal_datum, prime_meridian, axis0, axis1)
|
78
|
+
GeographicCoordinateSystem.create(name, angular_unit, horizontal_datum, prime_meridian, axis0, axis1)
|
77
79
|
end
|
78
80
|
|
79
81
|
# Create a HorizontalDatum given a name, a horizontal datum type
|
80
82
|
# code, an Ellipsoid, and a WGS84ConversionInfo. The
|
81
83
|
# WGS84ConversionInfo is optional and may be set to nil.
|
82
84
|
|
83
|
-
def create_horizontal_datum(
|
84
|
-
HorizontalDatum.create(
|
85
|
+
def create_horizontal_datum(name, horizontal_datum_type, ellipsoid, to_wgs84)
|
86
|
+
HorizontalDatum.create(name, horizontal_datum_type, ellipsoid, to_wgs84)
|
85
87
|
end
|
86
88
|
|
87
89
|
# Create a LocalCoordinateSystem given a name, a LocalDatum, a
|
88
90
|
# Unit, and an array of at least one AxisInfo.
|
89
91
|
|
90
|
-
def create_local_coordinate_system(
|
91
|
-
LocalCoordinateSystem.create(
|
92
|
+
def create_local_coordinate_system(name, datum, unit, axes)
|
93
|
+
LocalCoordinateSystem.create(name, datum, unit, axes)
|
92
94
|
end
|
93
95
|
|
94
96
|
# Create a LocalDatum given a name and a local datum type code.
|
95
97
|
|
96
|
-
def create_local_datum(
|
97
|
-
LocalDatum.create(name,
|
98
|
+
def create_local_datum(_name, local_datum_type)
|
99
|
+
LocalDatum.create(name, local_datum_type)
|
98
100
|
end
|
99
101
|
|
100
102
|
# Create a PrimeMeridian given a name, an AngularUnit, and a
|
101
103
|
# longitude offset.
|
102
104
|
|
103
|
-
def create_prime_meridian(
|
104
|
-
PrimeMeridian.create(name,
|
105
|
+
def create_prime_meridian(_name, angular_unit, longitude)
|
106
|
+
PrimeMeridian.create(name, angular_unit, longitude)
|
105
107
|
end
|
106
108
|
|
107
109
|
# Create a ProjectedCoordinateSystem given a name, a
|
@@ -109,29 +111,29 @@ module RGeo
|
|
109
111
|
# two AxisInfo objects. The AxisInfo objects are optional and may
|
110
112
|
# be set to nil.
|
111
113
|
|
112
|
-
def create_projected_coordinate_system(
|
113
|
-
ProjectedCoordinateSystem.create(
|
114
|
+
def create_projected_coordinate_system(name, gcs, projection, linear_unit, axis0, axis1)
|
115
|
+
ProjectedCoordinateSystem.create(name, gcs, projection, linear_unit, axis0, axis1)
|
114
116
|
end
|
115
117
|
|
116
118
|
# Create a Projection given a name, a projection class, and an
|
117
119
|
# array of ProjectionParameter.
|
118
120
|
|
119
|
-
def create_projection(
|
120
|
-
Projection.create(
|
121
|
+
def create_projection(name, wkt_projection_class, parameters)
|
122
|
+
Projection.create(name, wkt_projection_class, parameters)
|
121
123
|
end
|
122
124
|
|
123
125
|
# Create a VerticalCoordinateSystem given a name, a VerticalDatum,
|
124
126
|
# a VerticalUnit, and an AxisInfo. The AxisInfo is optional and
|
125
127
|
# may be nil.
|
126
128
|
|
127
|
-
def create_vertical_coordinate_system(
|
128
|
-
VerticalCoordinateSystem.create(
|
129
|
+
def create_vertical_coordinate_system(name, vertical_datum, vertical_unit, axis)
|
130
|
+
VerticalCoordinateSystem.create(name, vertical_datum, vertical_unit, axis)
|
129
131
|
end
|
130
132
|
|
131
133
|
# Create a VerticalDatum given a name ane a datum type code.
|
132
134
|
|
133
|
-
def create_vertical_datum(
|
134
|
-
VerticalDatum.create(
|
135
|
+
def create_vertical_datum(name, vertical_datum_type)
|
136
|
+
VerticalDatum.create(name, vertical_datum_type)
|
135
137
|
end
|
136
138
|
end
|
137
139
|
|
@@ -139,8 +141,8 @@ module RGeo
|
|
139
141
|
# Parsees OGC WKT format and returns the object created. Raises
|
140
142
|
# Error::ParseError if a syntax error is encounterred.
|
141
143
|
|
142
|
-
def create_from_wkt(
|
143
|
-
WKTParser.new(
|
144
|
+
def create_from_wkt(str)
|
145
|
+
WKTParser.new(str).parse
|
144
146
|
end
|
145
147
|
end
|
146
148
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# -----------------------------------------------------------------------------
|
2
4
|
#
|
3
5
|
# OGC CS wkt parser for RGeo
|
@@ -8,141 +10,141 @@ module RGeo
|
|
8
10
|
module CoordSys
|
9
11
|
module CS
|
10
12
|
class WKTParser # :nodoc:
|
11
|
-
def initialize(
|
12
|
-
@scanner =
|
13
|
+
def initialize(str)
|
14
|
+
@scanner = StringScanner.new(str)
|
13
15
|
next_token
|
14
16
|
end
|
15
17
|
|
16
|
-
def parse(
|
18
|
+
def parse(containing_type = nil) # :nodoc:
|
17
19
|
if @cur_token.is_a?(QuotedString) ||
|
18
|
-
@cur_token.is_a?(
|
19
|
-
(
|
20
|
-
|
20
|
+
@cur_token.is_a?(Numeric) ||
|
21
|
+
(containing_type == "AXIS" && @cur_token.is_a?(TypeString))
|
22
|
+
value = @cur_token
|
21
23
|
next_token
|
22
|
-
return
|
24
|
+
return value
|
23
25
|
end
|
24
26
|
unless @cur_token.is_a?(TypeString)
|
25
27
|
raise Error::ParseError("Found token #{@cur_token} when we expected a value")
|
26
28
|
end
|
27
|
-
|
29
|
+
type = @cur_token
|
28
30
|
next_token
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
consume_tokentype(:begin)
|
32
|
+
args = ArgumentList.new
|
33
|
+
args << parse(type)
|
32
34
|
loop do
|
33
35
|
break unless @cur_token == :comma
|
34
36
|
next_token
|
35
|
-
|
37
|
+
args << parse(type)
|
36
38
|
end
|
37
|
-
|
38
|
-
|
39
|
-
case
|
39
|
+
consume_tokentype(:end)
|
40
|
+
obj = nil
|
41
|
+
case type
|
40
42
|
when "AUTHORITY"
|
41
|
-
|
43
|
+
obj = AuthorityClause.new(args.shift(QuotedString), args.shift(QuotedString))
|
42
44
|
when "EXTENSION"
|
43
|
-
|
45
|
+
obj = ExtensionClause.new(args.shift(QuotedString), args.shift(QuotedString))
|
44
46
|
when "AXIS"
|
45
|
-
|
47
|
+
obj = AxisInfo.create(args.shift(QuotedString), args.shift(TypeString))
|
46
48
|
when "TOWGS84"
|
47
|
-
|
48
|
-
unless
|
49
|
-
raise Error::ParseError("Expected 7 Bursa Wolf parameters but found #{
|
49
|
+
bursa_wolf_params = args.find_all(Numeric)
|
50
|
+
unless bursa_wolf_params.size == 7
|
51
|
+
raise Error::ParseError("Expected 7 Bursa Wolf parameters but found #{bursa_wolf_params.size}")
|
50
52
|
end
|
51
|
-
|
53
|
+
obj = WGS84ConversionInfo.create(*bursa_wolf_params)
|
52
54
|
when "UNIT"
|
53
|
-
case
|
55
|
+
case containing_type
|
54
56
|
when "GEOCCS", "VERT_CS", "PROJCS", "SPHEROID"
|
55
|
-
|
57
|
+
klass = LinearUnit
|
56
58
|
when "GEOGCS"
|
57
|
-
|
59
|
+
klass = AngularUnit
|
58
60
|
else
|
59
|
-
|
61
|
+
klass = Unit
|
60
62
|
end
|
61
|
-
|
63
|
+
obj = klass.create(args.shift(QuotedString), args.shift(Numeric), *args.create_optionals)
|
62
64
|
when "PARAMETER"
|
63
|
-
|
65
|
+
obj = ProjectionParameter.create(args.shift(QuotedString), args.shift(Numeric))
|
64
66
|
when "PRIMEM"
|
65
|
-
|
67
|
+
obj = PrimeMeridian.create(args.shift(QuotedString), nil, args.shift(Numeric), *args.create_optionals)
|
66
68
|
when "SPHEROID"
|
67
|
-
|
69
|
+
obj = Ellipsoid.create_flattened_sphere(args.shift(QuotedString), args.shift(Numeric), args.shift(Numeric), args.find_first(LinearUnit), *args.create_optionals)
|
68
70
|
when "PROJECTION"
|
69
|
-
|
70
|
-
|
71
|
+
name = args.shift(QuotedString)
|
72
|
+
obj = Projection.create(name, name, args.find_all(ProjectionParameter), *args.create_optionals)
|
71
73
|
when "DATUM"
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
74
|
+
name = args.shift(QuotedString)
|
75
|
+
ellipsoid = args.find_first(Ellipsoid)
|
76
|
+
to_wgs84 = args.find_first(WGS84ConversionInfo)
|
77
|
+
obj = HorizontalDatum.create(name, HD_GEOCENTRIC, ellipsoid, to_wgs84, *args.create_optionals)
|
76
78
|
when "VERT_DATUM"
|
77
|
-
|
79
|
+
obj = VerticalDatum.create(args.shift(QuotedString), args.shift(Numeric), *args.create_optionals)
|
78
80
|
when "LOCAL_DATUM"
|
79
|
-
|
81
|
+
obj = LocalDatum.create(args.shift(QuotedString), args.shift(Numeric), *args.create_optionals)
|
80
82
|
when "COMPD_CS"
|
81
|
-
|
83
|
+
obj = CompoundCoordinateSystem.create(args.shift(QuotedString), args.shift(CoordinateSystem), args.shift(CoordinateSystem), *args.create_optionals)
|
82
84
|
when "LOCAL_CS"
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
unless
|
85
|
+
name = args.shift(QuotedString)
|
86
|
+
local_datum = args.find_first(LocalDatum)
|
87
|
+
unit = args.find_first(Unit)
|
88
|
+
axes = args.find_all(AxisInfo)
|
89
|
+
unless axes.size > 0
|
88
90
|
raise Error::ParseError("Expected at least one AXIS in a LOCAL_CS")
|
89
91
|
end
|
90
|
-
|
92
|
+
obj = LocalCoordinateSystem.create(name, local_datum, unit, axes, *args.create_optionals)
|
91
93
|
when "GEOCCS"
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
unless
|
94
|
+
name = args.shift(QuotedString)
|
95
|
+
horizontal_datum = args.find_first(HorizontalDatum)
|
96
|
+
prime_meridian = args.find_first(PrimeMeridian)
|
97
|
+
linear_unit = args.find_first(LinearUnit)
|
98
|
+
axes = args.find_all(AxisInfo)
|
99
|
+
unless axes.size == 0 || axes.size == 3
|
98
100
|
raise Error::ParseError("GEOCCS must contain either 0 or 3 AXIS parameters")
|
99
101
|
end
|
100
|
-
|
102
|
+
obj = GeocentricCoordinateSystem.create(name, horizontal_datum, prime_meridian, linear_unit, axes[0], axes[1], axes[2], *args.create_optionals)
|
101
103
|
when "VERT_CS"
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
104
|
+
name = args.shift(QuotedString)
|
105
|
+
vertical_datum = args.find_first(VerticalDatum)
|
106
|
+
linear_unit = args.find_first(LinearUnit)
|
107
|
+
axis = args.find_first(AxisInfo)
|
108
|
+
obj = VerticalCoordinateSystem.create(name, vertical_datum, linear_unit, axis, *args.create_optionals)
|
107
109
|
when "GEOGCS"
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
unless
|
110
|
+
name = args.shift(QuotedString)
|
111
|
+
horizontal_datum = args.find_first(HorizontalDatum)
|
112
|
+
prime_meridian = args.find_first(PrimeMeridian)
|
113
|
+
angular_unit = args.find_first(AngularUnit)
|
114
|
+
axes = args.find_all(AxisInfo)
|
115
|
+
unless axes.size == 0 || axes.size == 2
|
114
116
|
raise Error::ParseError("GEOGCS must contain either 0 or 2 AXIS parameters")
|
115
117
|
end
|
116
|
-
|
118
|
+
obj = GeographicCoordinateSystem.create(name, angular_unit, horizontal_datum, prime_meridian, axes[0], axes[1], *args.create_optionals)
|
117
119
|
when "PROJCS"
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
unless
|
120
|
+
name = args.shift(QuotedString)
|
121
|
+
geographic_coordinate_system = args.find_first(GeographicCoordinateSystem)
|
122
|
+
projection = args.find_first(Projection)
|
123
|
+
parameters = args.find_all(ProjectionParameter)
|
124
|
+
projection.instance_variable_get(:@parameters).concat(parameters)
|
125
|
+
linear_unit = args.find_first(LinearUnit)
|
126
|
+
axes = args.find_all(AxisInfo)
|
127
|
+
unless axes.size == 0 || axes.size == 2
|
126
128
|
raise Error::ParseError("PROJCS must contain either 0 or 2 AXIS parameters")
|
127
129
|
end
|
128
|
-
|
130
|
+
obj = ProjectedCoordinateSystem.create(name, geographic_coordinate_system, projection, linear_unit, axes[0], axes[1], *args.create_optionals)
|
129
131
|
else
|
130
|
-
raise Error::ParseError, "Unrecognized type: #{
|
132
|
+
raise Error::ParseError, "Unrecognized type: #{type}"
|
131
133
|
end
|
132
|
-
|
133
|
-
|
134
|
+
args.assert_empty
|
135
|
+
obj
|
134
136
|
end
|
135
137
|
|
136
|
-
def
|
137
|
-
|
138
|
-
|
138
|
+
def consume_tokentype(type) # :nodoc:
|
139
|
+
expect_tokentype(type)
|
140
|
+
tok = @cur_token
|
139
141
|
next_token
|
140
|
-
|
142
|
+
tok
|
141
143
|
end
|
142
144
|
|
143
|
-
def
|
144
|
-
unless
|
145
|
-
raise Error::ParseError, "#{
|
145
|
+
def expect_tokentype(type) # :nodoc:
|
146
|
+
unless type === @cur_token
|
147
|
+
raise Error::ParseError, "#{type.inspect} expected but #{@cur_token.inspect} found."
|
146
148
|
end
|
147
149
|
end
|
148
150
|
|
@@ -168,11 +170,11 @@ module RGeo
|
|
168
170
|
@cur_token = nil
|
169
171
|
else
|
170
172
|
@scanner.scan_until(/[^\s\(\)\[\],"]+/)
|
171
|
-
|
172
|
-
if
|
173
|
-
@cur_token =
|
173
|
+
token = @scanner.matched
|
174
|
+
if token =~ /^[-+]?(\d+(\.\d*)?|\.\d+)(e[-+]?\d+)?$/
|
175
|
+
@cur_token = token.to_f
|
174
176
|
else
|
175
|
-
raise Error::ParseError, "Bad token: #{
|
177
|
+
raise Error::ParseError, "Bad token: #{token.inspect}"
|
176
178
|
end
|
177
179
|
end
|
178
180
|
@cur_token
|
@@ -180,16 +182,16 @@ module RGeo
|
|
180
182
|
|
181
183
|
attr_reader :cur_token
|
182
184
|
|
183
|
-
class QuotedString <
|
185
|
+
class QuotedString < String # :nodoc:
|
184
186
|
end
|
185
187
|
|
186
|
-
class TypeString <
|
188
|
+
class TypeString < String # :nodoc:
|
187
189
|
end
|
188
190
|
|
189
191
|
class AuthorityClause # :nodoc:
|
190
|
-
def initialize(
|
191
|
-
@name =
|
192
|
-
@code =
|
192
|
+
def initialize(name, code) # :nodoc:
|
193
|
+
@name = name
|
194
|
+
@code = code
|
193
195
|
end
|
194
196
|
|
195
197
|
def to_a # :nodoc:
|
@@ -198,9 +200,9 @@ module RGeo
|
|
198
200
|
end
|
199
201
|
|
200
202
|
class ExtensionClause # :nodoc:
|
201
|
-
def initialize(
|
202
|
-
@key =
|
203
|
-
@value =
|
203
|
+
def initialize(key, value) # :nodoc:
|
204
|
+
@key = key
|
205
|
+
@value = value
|
204
206
|
end
|
205
207
|
|
206
208
|
attr_reader :key # :nodoc:
|
@@ -208,62 +210,62 @@ module RGeo
|
|
208
210
|
end
|
209
211
|
|
210
212
|
class ArgumentList # :nodoc:
|
211
|
-
def initialize
|
213
|
+
def initialize # :nodoc:
|
212
214
|
@values = []
|
213
215
|
end
|
214
216
|
|
215
|
-
def <<(
|
216
|
-
@values <<
|
217
|
+
def <<(value) # :nodoc:
|
218
|
+
@values << value
|
217
219
|
end
|
218
220
|
|
219
221
|
def assert_empty # :nodoc:
|
220
222
|
if @values.size > 0
|
221
|
-
|
222
|
-
|
223
|
+
names = @values.map do |val|
|
224
|
+
val.is_a?(Base) ? val.wkt_typename : val.inspect
|
223
225
|
end
|
224
|
-
raise Error::ParseError, "#{@values.size} unexpected arguments: #{
|
226
|
+
raise Error::ParseError, "#{@values.size} unexpected arguments: #{names.join(', ')}"
|
225
227
|
end
|
226
228
|
end
|
227
229
|
|
228
|
-
def find_first(
|
229
|
-
@values.each_with_index do |
|
230
|
-
if
|
231
|
-
@values.slice!(
|
232
|
-
return
|
230
|
+
def find_first(klass) # :nodoc:
|
231
|
+
@values.each_with_index do |val, index|
|
232
|
+
if val.is_a?(klass)
|
233
|
+
@values.slice!(index)
|
234
|
+
return val
|
233
235
|
end
|
234
236
|
end
|
235
237
|
nil
|
236
238
|
end
|
237
239
|
|
238
|
-
def find_all(
|
239
|
-
|
240
|
-
|
241
|
-
@values.each do |
|
242
|
-
if
|
243
|
-
|
240
|
+
def find_all(klass) # :nodoc:
|
241
|
+
results = []
|
242
|
+
nvalues = []
|
243
|
+
@values.each do |val|
|
244
|
+
if val.is_a?(klass)
|
245
|
+
results << val
|
244
246
|
else
|
245
|
-
|
247
|
+
nvalues << val
|
246
248
|
end
|
247
249
|
end
|
248
|
-
@values =
|
249
|
-
|
250
|
+
@values = nvalues
|
251
|
+
results
|
250
252
|
end
|
251
253
|
|
252
|
-
def create_optionals
|
253
|
-
|
254
|
-
find_all(ExtensionClause).each { |
|
255
|
-
(find_first(AuthorityClause) || [nil, nil]).to_a + [nil, nil, nil,
|
254
|
+
def create_optionals # :nodoc:
|
255
|
+
hash = {}
|
256
|
+
find_all(ExtensionClause).each { |ec| hash[ec.key] = ec.value }
|
257
|
+
(find_first(AuthorityClause) || [nil, nil]).to_a + [nil, nil, nil, hash]
|
256
258
|
end
|
257
259
|
|
258
|
-
def shift(
|
259
|
-
|
260
|
-
unless
|
261
|
-
raise Error::ParseError, "No arguments left... expected #{
|
260
|
+
def shift(klass = nil) # :nodoc:
|
261
|
+
val = @values.shift
|
262
|
+
unless val
|
263
|
+
raise Error::ParseError, "No arguments left... expected #{klass}"
|
262
264
|
end
|
263
|
-
if
|
264
|
-
raise Error::ParseError, "Expected #{
|
265
|
+
if klass && !val.is_a?(klass)
|
266
|
+
raise Error::ParseError, "Expected #{klass} but got #{val.class}"
|
265
267
|
end
|
266
|
-
|
268
|
+
val
|
267
269
|
end
|
268
270
|
end
|
269
271
|
end
|