georuby 2.3.0 → 2.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -9
- data/Rakefile +13 -14
- data/lib/geo_ruby/ewk.rb +2 -0
- data/lib/geo_ruby/{simple_features → ewk}/ewkb_parser.rb +206 -218
- data/lib/geo_ruby/ewk/ewkt_parser.rb +321 -0
- data/lib/geo_ruby/geojson.rb +27 -32
- data/lib/geo_ruby/georss.rb +88 -66
- data/lib/geo_ruby/gpx.rb +113 -1
- data/lib/geo_ruby/kml.rb +43 -31
- data/lib/geo_ruby/shp.rb +1 -0
- data/lib/geo_ruby/shp4r/dbf.rb +7 -3
- data/lib/geo_ruby/shp4r/shp.rb +297 -284
- data/lib/geo_ruby/simple_features.rb +2 -6
- data/lib/geo_ruby/simple_features/circle.rb +15 -13
- data/lib/geo_ruby/simple_features/envelope.rb +84 -77
- data/lib/geo_ruby/simple_features/geometry.rb +89 -69
- data/lib/geo_ruby/simple_features/geometry_collection.rb +46 -43
- data/lib/geo_ruby/simple_features/geometry_factory.rb +50 -47
- data/lib/geo_ruby/simple_features/helper.rb +14 -14
- data/lib/geo_ruby/simple_features/line_string.rb +94 -97
- data/lib/geo_ruby/simple_features/linear_ring.rb +4 -9
- data/lib/geo_ruby/simple_features/multi_line_string.rb +18 -21
- data/lib/geo_ruby/simple_features/multi_point.rb +18 -20
- data/lib/geo_ruby/simple_features/multi_polygon.rb +19 -25
- data/lib/geo_ruby/simple_features/point.rb +134 -128
- data/lib/geo_ruby/simple_features/polygon.rb +60 -59
- data/lib/geo_ruby/version.rb +1 -1
- data/spec/data/geojson/feature.json +9 -0
- data/spec/data/geojson/feature_collection.json +3 -4
- data/spec/geo_ruby/{simple_features → ewk}/ewkb_parser_spec.rb +56 -57
- data/spec/geo_ruby/{simple_features → ewk}/ewkt_parser_spec.rb +62 -63
- data/spec/geo_ruby/geojson_spec.rb +34 -17
- data/spec/geo_ruby/georss_spec.rb +76 -64
- data/spec/geo_ruby/{gpx4r/gpx_spec.rb → gpx_spec.rb} +25 -25
- data/spec/geo_ruby/kml_spec.rb +40 -36
- data/spec/geo_ruby/shp4r/shp_spec.rb +51 -51
- data/spec/geo_ruby/simple_features/circle_spec.rb +2 -2
- data/spec/geo_ruby/simple_features/envelope_spec.rb +8 -8
- data/spec/geo_ruby/simple_features/geometry_collection_spec.rb +26 -26
- data/spec/geo_ruby/simple_features/geometry_factory_spec.rb +5 -5
- data/spec/geo_ruby/simple_features/geometry_spec.rb +8 -8
- data/spec/geo_ruby/simple_features/line_string_spec.rb +102 -102
- data/spec/geo_ruby/simple_features/linear_ring_spec.rb +7 -7
- data/spec/geo_ruby/simple_features/multi_line_string_spec.rb +20 -20
- data/spec/geo_ruby/simple_features/multi_point_spec.rb +16 -16
- data/spec/geo_ruby/simple_features/multi_polygon_spec.rb +19 -19
- data/spec/geo_ruby/simple_features/point_spec.rb +180 -174
- data/spec/geo_ruby/simple_features/polygon_spec.rb +55 -56
- data/spec/geo_ruby_spec.rb +4 -4
- data/spec/spec_helper.rb +19 -13
- metadata +10 -9
- data/lib/geo_ruby/gpx4r/gpx.rb +0 -118
- data/lib/geo_ruby/simple_features/ewkt_parser.rb +0 -336
@@ -1,12 +1,9 @@
|
|
1
1
|
module GeoRuby
|
2
2
|
module SimpleFeatures
|
3
|
-
|
4
|
-
%w[
|
3
|
+
%w(
|
5
4
|
geometry
|
6
5
|
circle
|
7
6
|
envelope
|
8
|
-
ewkb_parser
|
9
|
-
ewkt_parser
|
10
7
|
geometry_collection
|
11
8
|
geometry_factory
|
12
9
|
helper
|
@@ -17,9 +14,8 @@ module GeoRuby
|
|
17
14
|
multi_polygon
|
18
15
|
point
|
19
16
|
polygon
|
20
|
-
|
17
|
+
).each do |rel_file|
|
21
18
|
require File.join(File.dirname(__FILE__), 'simple_features', rel_file)
|
22
19
|
end
|
23
|
-
|
24
20
|
end
|
25
21
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module GeoRuby
|
2
2
|
module SimpleFeatures
|
3
|
-
#Represents a point. It is in 3D if the Z coordinate is not +nil+.
|
3
|
+
# Represents a point. It is in 3D if the Z coordinate is not +nil+.
|
4
4
|
class Circle < Geometry
|
5
5
|
attr_accessor :radius, :center
|
6
|
-
|
6
|
+
alias_method :r, :radius
|
7
|
+
alias_method :c, :center
|
7
8
|
|
8
9
|
def initialize(srid = DEFAULT_SRID, with_z = false, with_m = false)
|
9
10
|
super(srid, with_z, with_m)
|
@@ -14,26 +15,28 @@ module GeoRuby
|
|
14
15
|
Point.from_x_y(@center.x + @r, @center.y + @r)]
|
15
16
|
end
|
16
17
|
|
18
|
+
def diameter
|
19
|
+
radius * 2
|
20
|
+
end
|
21
|
+
|
17
22
|
def m_range
|
18
|
-
|
23
|
+
fail NotImplementedError
|
19
24
|
end
|
20
25
|
|
21
26
|
def ==(other)
|
22
27
|
return false unless other.is_a?(Circle)
|
23
|
-
@center == other.center
|
28
|
+
@center == other.center && @radius == other.radius
|
24
29
|
end
|
25
30
|
|
26
31
|
def to_json(options = {})
|
27
|
-
{:
|
28
|
-
|
29
|
-
|
32
|
+
{ type: 'Circle',
|
33
|
+
coordinates: @center.to_coordinates,
|
34
|
+
radius: @radius }.to_json(options)
|
30
35
|
end
|
31
|
-
|
36
|
+
alias_method :as_geojson, :to_json
|
32
37
|
|
33
|
-
def contains_point?(
|
34
|
-
|
35
|
-
point.to_coordinates, :spherical => true, :unit => :m)
|
36
|
-
dist <= @radius
|
38
|
+
def contains_point?(_point)
|
39
|
+
fail NotImplementedError
|
37
40
|
end
|
38
41
|
|
39
42
|
class << self
|
@@ -51,7 +54,6 @@ module GeoRuby
|
|
51
54
|
circle
|
52
55
|
end
|
53
56
|
end
|
54
|
-
|
55
57
|
end
|
56
58
|
end
|
57
59
|
end
|
@@ -1,95 +1,101 @@
|
|
1
1
|
module GeoRuby
|
2
2
|
module SimpleFeatures
|
3
|
-
|
4
|
-
#Contains the bounding box of a geometry
|
3
|
+
# Contains the bounding box of a geometry
|
5
4
|
class Envelope
|
6
5
|
attr_accessor :lower_corner, :upper_corner
|
7
6
|
attr_accessor :srid, :with_z, :zoom
|
8
7
|
|
9
|
-
#Creates a enw Envelope with +lower_corner+ as the first element
|
8
|
+
# Creates a enw Envelope with +lower_corner+ as the first element
|
9
|
+
# of the corners array and +upper_corner+ as the second element
|
10
10
|
def initialize(srid = DEFAULT_SRID, with_z = false)
|
11
11
|
@srid = srid
|
12
12
|
@with_z = with_z
|
13
13
|
end
|
14
14
|
|
15
|
-
#Merges the argument with the current evelope
|
15
|
+
# Merges the argument with the current evelope
|
16
16
|
def extend!(envelope)
|
17
|
-
lower_corner.x = [lower_corner.x,envelope.lower_corner.x].min
|
18
|
-
lower_corner.y = [lower_corner.y,envelope.lower_corner.y].min
|
19
|
-
upper_corner.x = [upper_corner.x,envelope.upper_corner.x].max
|
20
|
-
upper_corner.y = [upper_corner.y,envelope.upper_corner.y].max
|
17
|
+
lower_corner.x = [lower_corner.x, envelope.lower_corner.x].min
|
18
|
+
lower_corner.y = [lower_corner.y, envelope.lower_corner.y].min
|
19
|
+
upper_corner.x = [upper_corner.x, envelope.upper_corner.x].max
|
20
|
+
upper_corner.y = [upper_corner.y, envelope.upper_corner.y].max
|
21
21
|
self
|
22
22
|
end
|
23
23
|
|
24
|
-
#Merges the argument with the current evelope and sends back a new
|
25
|
-
#envelope without changing the current one
|
24
|
+
# Merges the argument with the current evelope and sends back a new
|
25
|
+
# envelope without changing the current one
|
26
26
|
def extend(envelope)
|
27
|
-
e = Envelope.from_points([Point.from_x_y(lower_corner.x,lower_corner.y),
|
28
|
-
|
27
|
+
e = Envelope.from_points([Point.from_x_y(lower_corner.x, lower_corner.y),
|
28
|
+
Point.from_x_y(upper_corner.x, upper_corner.y)], srid, with_z)
|
29
29
|
e.extend!(envelope)
|
30
30
|
e
|
31
31
|
end
|
32
|
-
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
|
44
|
-
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
# #
|
49
|
-
# return [centrelat,centrelng], zoom
|
50
|
-
|
51
|
-
|
32
|
+
|
33
|
+
# def bounding_box(markers)
|
34
|
+
# max_lat, max_lon, min_lat, min_lon = -Float::MAX, -Float::MAX, Float::MAX, Float::MAX
|
35
|
+
# markers.each do |marker|
|
36
|
+
# coord = marker.point
|
37
|
+
# max_lat = coord.lat if coord.lat > max_lat
|
38
|
+
# min_lat = coord.lat if coord.lat < min_lat
|
39
|
+
# max_lon = coord.lng if coord.lng > max_lon
|
40
|
+
# min_lon = coord.lng if coord.lng < min_lon
|
41
|
+
# end
|
42
|
+
# min_point = Point.from_x_y(min_lat,min_lon)
|
43
|
+
# max_point = Point.from_x_y(max_lat,max_lon)
|
44
|
+
|
45
|
+
# end
|
46
|
+
# centrelat = (max_lat + min_lat)/2
|
47
|
+
# centrelng = (max_lon + min_lon)/2
|
48
|
+
# # logger.info("distance[#{distance}],zoom[#{zoom}]")
|
49
|
+
# #return GLatLngBounds.new(GLatLng.new(min_point),GLatLng.new(max_point)), [centrelat,centrelng], zoom
|
50
|
+
# return [centrelat,centrelng], zoom
|
51
|
+
|
52
|
+
# Sends back the center of the envelope
|
52
53
|
def center
|
53
|
-
Point.from_x_y((lower_corner.x + upper_corner.x)/2,(lower_corner.y + upper_corner.y)/2, srid)
|
54
|
+
Point.from_x_y((lower_corner.x + upper_corner.x) / 2, (lower_corner.y + upper_corner.y) / 2, srid)
|
54
55
|
end
|
55
56
|
|
56
|
-
#Zoom level
|
57
|
+
# Zoom level
|
57
58
|
def zoom
|
58
59
|
distance = lower_corner.spherical_distance(upper_corner) / 10_000
|
59
60
|
@zoom = case distance
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
61
|
+
when 150..9000 then 5
|
62
|
+
when 80..149 then 6
|
63
|
+
when 50..79 then 7
|
64
|
+
when 20..49 then 8
|
65
|
+
when 10..19 then 9
|
66
|
+
when 5..9 then 10
|
67
|
+
else 13
|
68
|
+
end
|
68
69
|
end
|
69
70
|
|
70
|
-
#Tests the equality of line strings
|
71
|
+
# Tests the equality of line strings
|
71
72
|
def ==(other_envelope)
|
72
73
|
if other_envelope.class != self.class
|
73
74
|
false
|
74
75
|
else
|
75
|
-
upper_corner == other_envelope.upper_corner
|
76
|
+
upper_corner == other_envelope.upper_corner && lower_corner == other_envelope.lower_corner
|
76
77
|
end
|
77
78
|
end
|
78
79
|
|
79
|
-
#georss serialization: Dialect can be passed as option <tt>:dialect</tt>
|
80
|
-
|
80
|
+
# georss serialization: Dialect can be passed as option <tt>:dialect</tt>
|
81
|
+
# and set to <tt>:simple</tt> (default) <tt>:w3cgeo</tt> or <tt>:gml</tt>.
|
82
|
+
# Options <tt>:featuretypetag
|
81
83
|
def as_georss(options = {})
|
82
|
-
dialect= options[:dialect] || :simple
|
83
|
-
case(dialect)
|
84
|
+
dialect = options[:dialect] || :simple
|
85
|
+
case (dialect)
|
84
86
|
when :simple
|
85
|
-
geom_attr =
|
86
|
-
|
87
|
-
|
87
|
+
geom_attr = ''
|
88
|
+
if options[:featuretypetag]
|
89
|
+
geom_attr += " featuretypetag=\"#{options[:featuretypetag]}\""
|
90
|
+
end
|
91
|
+
if options[:relationshiptag]
|
92
|
+
geom_attr += " relationshiptag=\"#{options[:relationshiptag]}\""
|
93
|
+
end
|
88
94
|
geom_attr += " floor=\"#{options[:floor]}\"" if options[:floor]
|
89
95
|
geom_attr += " radius=\"#{options[:radius]}\"" if options[:radius]
|
90
96
|
geom_attr += " elev=\"#{options[:elev]}\"" if options[:elev]
|
91
97
|
|
92
|
-
georss_simple_representation(options.merge(:
|
98
|
+
georss_simple_representation(options.merge(geom_attr: geom_attr))
|
93
99
|
when :w3cgeo
|
94
100
|
georss_w3cgeo_representation(options)
|
95
101
|
when :gml
|
@@ -97,41 +103,43 @@ module GeoRuby
|
|
97
103
|
end
|
98
104
|
end
|
99
105
|
|
100
|
-
|
106
|
+
# georss simple representation
|
101
107
|
def georss_simple_representation(options = {}) #:nodoc:
|
102
|
-
georss_ns = options[:georss_ns] ||
|
108
|
+
georss_ns = options[:georss_ns] || 'georss'
|
103
109
|
geom_attr = options[:geom_attr]
|
104
110
|
"<#{georss_ns}:box#{geom_attr}>#{lower_corner.y} #{lower_corner.x} #{upper_corner.y} #{upper_corner.x}</#{georss_ns}:box>\n"
|
105
111
|
end
|
106
112
|
|
107
|
-
#georss w3c representation : outputs the first point of the line
|
113
|
+
# georss w3c representation : outputs the first point of the line
|
108
114
|
def georss_w3cgeo_representation(options = {}) #:nodoc:
|
109
|
-
w3cgeo_ns = options[:w3cgeo_ns] ||
|
110
|
-
point =
|
115
|
+
w3cgeo_ns = options[:w3cgeo_ns] || 'geo'
|
116
|
+
point = center
|
111
117
|
"<#{w3cgeo_ns}:lat>#{point.y}</#{w3cgeo_ns}:lat>\n<#{w3cgeo_ns}:long>#{point.x}</#{w3cgeo_ns}:long>\n"
|
112
118
|
end
|
113
119
|
|
114
|
-
#georss gml representation
|
120
|
+
# georss gml representation
|
115
121
|
def georss_gml_representation(options = {}) #:nodoc:
|
116
|
-
georss_ns = options[:georss_ns] ||
|
117
|
-
gml_ns = options[:gml_ns] ||
|
122
|
+
georss_ns = options[:georss_ns] || 'georss'
|
123
|
+
gml_ns = options[:gml_ns] || 'gml'
|
118
124
|
result = "<#{georss_ns}:where>\n<#{gml_ns}:Envelope>\n"
|
119
|
-
result += "<#{gml_ns}:LowerCorner
|
120
|
-
|
121
|
-
result += "
|
125
|
+
result += "<#{gml_ns}:LowerCorner>#{lower_corner.y} #{lower_corner.x}"\
|
126
|
+
"</#{gml_ns}:LowerCorner>"
|
127
|
+
result += "<#{gml_ns}:UpperCorner>#{upper_corner.y} #{upper_corner.x}"\
|
128
|
+
"</#{gml_ns}:UpperCorner>"
|
129
|
+
result + "</#{gml_ns}:Envelope>\n</#{georss_ns}:where>\n"
|
122
130
|
end
|
123
131
|
|
124
|
-
#Sends back a latlonaltbox
|
132
|
+
# Sends back a latlonaltbox
|
125
133
|
def as_kml(options = {})
|
126
|
-
geom_data =
|
134
|
+
geom_data = ''
|
127
135
|
geom_data = "<altitudeMode>#{options[:altitude_mode]}</altitudeMode>\n" if options[:altitude_mode]
|
128
136
|
|
129
|
-
allow_z = with_z && (!options[:altitude_mode].nil?) && options[:atitude_mode] !=
|
137
|
+
allow_z = with_z && (!options[:altitude_mode].nil?) && options[:atitude_mode] != 'clampToGround'
|
130
138
|
|
131
|
-
kml_representation(options.merge(:geom_data
|
139
|
+
kml_representation(options.merge(geom_data: geom_data, allow_z: allow_z))
|
132
140
|
end
|
133
141
|
|
134
|
-
def kml_representation(options = {})#:nodoc:
|
142
|
+
def kml_representation(options = {}) #:nodoc:
|
135
143
|
result = "<LatLonAltBox>\n"
|
136
144
|
result += options[:geom_data]
|
137
145
|
result += "<north>#{upper_corner.y}</north>\n"
|
@@ -144,24 +152,23 @@ module GeoRuby
|
|
144
152
|
result += "<maxAltitude>#{upper_corner.z}</maxAltitude>"
|
145
153
|
end
|
146
154
|
|
147
|
-
result
|
155
|
+
result + "</LatLonAltBox>\n"
|
148
156
|
end
|
149
157
|
|
150
|
-
#Creates a new envelope. Accept an array of 2 points as argument
|
151
|
-
def self.from_points(points,srid=DEFAULT_SRID,with_z=false)
|
152
|
-
|
153
|
-
e = Envelope.new(srid,with_z)
|
158
|
+
# Creates a new envelope. Accept an array of 2 points as argument
|
159
|
+
def self.from_points(points, srid = DEFAULT_SRID, with_z = false)
|
160
|
+
fail 'Not an array' unless points.class == Array
|
161
|
+
e = Envelope.new(srid, with_z)
|
154
162
|
e.lower_corner, e.upper_corner = points
|
155
163
|
e
|
156
164
|
end
|
157
165
|
|
158
|
-
#Creates a new envelope. Accept a sequence of point coordinates as argument : ((x,y),(x,y))
|
166
|
+
# Creates a new envelope. Accept a sequence of point coordinates as argument : ((x,y),(x,y))
|
159
167
|
def self.from_coordinates(points, srid = DEFAULT_SRID, with_z = false)
|
160
|
-
e = Envelope.new(srid,with_z)
|
161
|
-
e.lower_corner, e.upper_corner = points.collect{|point_coords| Point.from_coordinates(point_coords,srid,with_z)}
|
168
|
+
e = Envelope.new(srid, with_z)
|
169
|
+
e.lower_corner, e.upper_corner = points.collect { |point_coords| Point.from_coordinates(point_coords, srid, with_z) }
|
162
170
|
e
|
163
171
|
end
|
164
|
-
|
165
172
|
end
|
166
173
|
end
|
167
174
|
end
|
@@ -1,32 +1,31 @@
|
|
1
|
-
module GeoRuby#:nodoc:
|
1
|
+
module GeoRuby #:nodoc:
|
2
2
|
module SimpleFeatures
|
3
|
-
|
4
3
|
# Default SRID
|
5
4
|
DEFAULT_SRID = 4326 unless defined? DEFAULT_SRID
|
6
5
|
|
7
|
-
#Root of all geometric data classes.
|
8
|
-
#Objects of class Geometry should not be instantiated.
|
6
|
+
# Root of all geometric data classes.
|
7
|
+
# Objects of class Geometry should not be instantiated.
|
9
8
|
class Geometry
|
10
|
-
#SRID of the geometry
|
11
|
-
attr_reader :srid #writer defined below
|
12
|
-
#Flag indicating if the z ordinate of the geometry is meaningful
|
9
|
+
# SRID of the geometry
|
10
|
+
attr_reader :srid # writer defined below
|
11
|
+
# Flag indicating if the z ordinate of the geometry is meaningful
|
13
12
|
attr_accessor :with_z
|
14
|
-
|
15
|
-
#Flag indicating if the m ordinate of the geometry is meaningful
|
13
|
+
alias_method :with_z?, :with_z
|
14
|
+
# Flag indicating if the m ordinate of the geometry is meaningful
|
16
15
|
attr_accessor :with_m
|
17
|
-
|
16
|
+
alias_method :with_m?, :with_m
|
18
17
|
|
19
|
-
def initialize(srid=DEFAULT_SRID, with_z=false, with_m=false)
|
20
|
-
@srid=srid
|
21
|
-
@with_z=with_z
|
22
|
-
@with_m=with_m
|
18
|
+
def initialize(srid = DEFAULT_SRID, with_z = false, with_m = false)
|
19
|
+
@srid = srid
|
20
|
+
@with_z = with_z
|
21
|
+
@with_m = with_m
|
23
22
|
end
|
24
23
|
|
25
24
|
def srid=(new_srid)
|
26
25
|
@srid = new_srid
|
27
26
|
unless self.is_a?(Point)
|
28
|
-
|
29
|
-
geom.srid=new_srid
|
27
|
+
each do |geom|
|
28
|
+
geom.srid = new_srid
|
30
29
|
end
|
31
30
|
end
|
32
31
|
end
|
@@ -43,30 +42,30 @@ module GeoRuby#:nodoc:
|
|
43
42
|
# Returns an Envelope object for the geometry
|
44
43
|
#
|
45
44
|
def envelope
|
46
|
-
Envelope.from_points(bounding_box, srid,with_z)
|
45
|
+
Envelope.from_points(bounding_box, srid, with_z)
|
47
46
|
end
|
48
47
|
|
49
48
|
#
|
50
49
|
# Outputs the geometry as an EWKB string.
|
51
50
|
#
|
52
51
|
# The +allow_srid+, +allow_z+ and +allow_m+ arguments allow the output
|
53
|
-
# to include srid, z and m respectively if they are present
|
52
|
+
# to include srid, z and m respectively if they are present.
|
54
53
|
# If these arguments are set to false, srid, z and m are not included,
|
55
54
|
# even if they are present in the geometry.
|
56
55
|
# By default, the output string contains all the information in the object.
|
57
56
|
#
|
58
|
-
def as_ewkb(allow_srid=true, allow_z=true, allow_m=true)
|
59
|
-
ewkb = 1.chr #little_endian by default
|
57
|
+
def as_ewkb(allow_srid = true, allow_z = true, allow_m = true)
|
58
|
+
ewkb = 1.chr # little_endian by default
|
60
59
|
|
61
60
|
type = binary_geometry_type
|
62
|
-
type
|
63
|
-
type
|
61
|
+
type |= Z_MASK if @with_z && allow_z
|
62
|
+
type |= M_MASK if @with_m && allow_m
|
64
63
|
|
65
64
|
if allow_srid
|
66
65
|
type = type | SRID_MASK
|
67
|
-
ewkb << [type, @srid].pack(
|
66
|
+
ewkb << [type, @srid].pack('VV')
|
68
67
|
else
|
69
|
-
ewkb << [type].pack(
|
68
|
+
ewkb << [type].pack('V')
|
70
69
|
end
|
71
70
|
|
72
71
|
ewkb << binary_representation(allow_z, allow_m)
|
@@ -82,9 +81,9 @@ module GeoRuby#:nodoc:
|
|
82
81
|
#
|
83
82
|
# Outputs the geometry as a HexEWKB string.
|
84
83
|
# It is almost the same as a WKB string, except that each byte of a WKB
|
85
|
-
# string is replaced by its
|
84
|
+
# string is replaced by its hex 2-char representation in a HexEWKB string.
|
86
85
|
#
|
87
|
-
def as_hex_ewkb(allow_srid=true, allow_z=true, allow_m=true)
|
86
|
+
def as_hex_ewkb(allow_srid = true, allow_z = true, allow_m = true)
|
88
87
|
as_ewkb(allow_srid, allow_z, allow_m).unpack('H*').join('').upcase
|
89
88
|
end
|
90
89
|
|
@@ -92,21 +91,22 @@ module GeoRuby#:nodoc:
|
|
92
91
|
# Outputs the geometry as a strict HexWKB string
|
93
92
|
#
|
94
93
|
def as_hex_wkb
|
95
|
-
as_hex_ewkb(false,false,false)
|
94
|
+
as_hex_ewkb(false, false, false)
|
96
95
|
end
|
97
96
|
|
98
97
|
#
|
99
98
|
# Outputs the geometry as an EWKT string.
|
100
99
|
#
|
101
|
-
def as_ewkt(allow_srid=true,allow_z=true,allow_m=true)
|
100
|
+
def as_ewkt(allow_srid = true, allow_z = true, allow_m = true)
|
102
101
|
if allow_srid
|
103
|
-
ewkt="SRID=#{@srid};"
|
102
|
+
ewkt = "SRID=#{@srid};"
|
104
103
|
else
|
105
|
-
ewkt=
|
104
|
+
ewkt = ''
|
106
105
|
end
|
107
106
|
ewkt << text_geometry_type
|
108
|
-
|
109
|
-
ewkt <<
|
107
|
+
# to distinguish the M from the Z when there is actually no Z...
|
108
|
+
ewkt << 'M' if @with_m && allow_m && (!@with_z || !allow_z)
|
109
|
+
ewkt << '(' << text_representation(allow_z, allow_m) << ')'
|
110
110
|
end
|
111
111
|
|
112
112
|
#
|
@@ -118,18 +118,23 @@ module GeoRuby#:nodoc:
|
|
118
118
|
|
119
119
|
# Outputs the geometry in georss format.
|
120
120
|
# Assumes the geometries are in latlon format, with x as lon and y as lat.
|
121
|
-
# Pass the <tt>:dialect</tt> option to swhit format. Possible values are:
|
121
|
+
# Pass the <tt>:dialect</tt> option to swhit format. Possible values are:
|
122
|
+
# <tt>:simple</tt> (default), <tt>:w3cgeo</tt> and <tt>:gml</tt>.
|
122
123
|
def as_georss(options = {})
|
123
|
-
dialect= options[:dialect] || :simple
|
124
|
-
case(dialect)
|
124
|
+
dialect = options[:dialect] || :simple
|
125
|
+
case (dialect)
|
125
126
|
when :simple
|
126
|
-
geom_attr =
|
127
|
-
|
128
|
-
|
127
|
+
geom_attr = ''
|
128
|
+
if options[:featuretypetag]
|
129
|
+
geom_attr += " featuretypetag=\"#{options[:featuretypetag]}\""
|
130
|
+
end
|
131
|
+
if options[:relationshiptag]
|
132
|
+
geom_attr += " relationshiptag=\"#{options[:relationshiptag]}\""
|
133
|
+
end
|
129
134
|
geom_attr += " floor=\"#{options[:floor]}\"" if options[:floor]
|
130
135
|
geom_attr += " radius=\"#{options[:radius]}\"" if options[:radius]
|
131
136
|
geom_attr += " elev=\"#{options[:elev]}\"" if options[:elev]
|
132
|
-
georss_simple_representation(options.merge(:
|
137
|
+
georss_simple_representation(options.merge(geom_attr: geom_attr))
|
133
138
|
when :w3cgeo
|
134
139
|
georss_w3cgeo_representation(options)
|
135
140
|
when :gml
|
@@ -137,22 +142,32 @@ module GeoRuby#:nodoc:
|
|
137
142
|
end
|
138
143
|
end
|
139
144
|
|
140
|
-
# Iutputs the geometry in kml format : options are <tt>:id</tt>,
|
141
|
-
# <tt>:
|
142
|
-
#
|
145
|
+
# Iutputs the geometry in kml format : options are <tt>:id</tt>,
|
146
|
+
# <tt>:tesselate</tt>, <tt>:extrude</tt>, <tt>:altitude_mode</tt>.
|
147
|
+
# If the altitude_mode option is not present, the Z (if present) will not
|
148
|
+
# be output (since it won't be used by GE: clampToGround is the default)
|
143
149
|
def as_kml(options = {})
|
144
|
-
id_attr =
|
150
|
+
id_attr = ''
|
145
151
|
id_attr = " id=\"#{options[:id]}\"" if options[:id]
|
146
152
|
|
147
|
-
geom_data =
|
148
|
-
|
149
|
-
|
150
|
-
|
153
|
+
geom_data = ''
|
154
|
+
if options[:extrude]
|
155
|
+
geom_data += "<extrude>#{options[:extrude]}</extrude>\n"
|
156
|
+
end
|
157
|
+
if options[:tesselate]
|
158
|
+
geom_data += "<tesselate>#{options[:tesselate]}</tesselate>\n"
|
159
|
+
end
|
160
|
+
if options[:altitude_mode]
|
161
|
+
geom_data += "<altitudeMode>#{options[:altitude_mode]}</altitudeMode>\n"
|
162
|
+
end
|
151
163
|
|
152
|
-
allow_z = (with_z || !options[:altitude].nil?
|
164
|
+
allow_z = (with_z || !options[:altitude].nil?) &&
|
165
|
+
(!options[:altitude_mode].nil?) &&
|
166
|
+
options[:atitude_mode] != 'clampToGround'
|
153
167
|
fixed_z = options[:altitude]
|
154
168
|
|
155
|
-
kml_representation(options.merge(:
|
169
|
+
kml_representation(options.merge(id_attr: id_attr, geom_data: geom_data,
|
170
|
+
allow_z: allow_z, fixed_z: fixed_z))
|
156
171
|
end
|
157
172
|
|
158
173
|
# simple geojson representation
|
@@ -161,50 +176,55 @@ module GeoRuby#:nodoc:
|
|
161
176
|
as_json(options).to_json(options)
|
162
177
|
end
|
163
178
|
|
164
|
-
def as_json(
|
179
|
+
def as_json(_options = {})
|
165
180
|
# Implemented by each class
|
166
181
|
end
|
167
|
-
|
182
|
+
alias_method :as_geojson, :as_json
|
168
183
|
|
169
|
-
# Creates a geometry based on a EWKB string. The actual class returned
|
184
|
+
# Creates a geometry based on a EWKB string. The actual class returned
|
185
|
+
# depends of the content of the string passed as argument.
|
186
|
+
# Since WKB strings are a subset of EWKB, they are also valid.
|
170
187
|
def self.from_ewkb(ewkb)
|
171
|
-
factory = GeometryFactory
|
172
|
-
ewkb_parser = EWKBParser
|
188
|
+
factory = GeometryFactory.new
|
189
|
+
ewkb_parser = EWKBParser.new(factory)
|
173
190
|
ewkb_parser.parse(ewkb)
|
174
191
|
factory.geometry
|
175
192
|
end
|
176
193
|
|
177
194
|
# Creates a geometry based on a HexEWKB string given.
|
178
195
|
def self.from_hex_ewkb(hexewkb)
|
179
|
-
factory = GeometryFactory
|
180
|
-
hexewkb_parser = HexEWKBParser
|
196
|
+
factory = GeometryFactory.new
|
197
|
+
hexewkb_parser = HexEWKBParser.new(factory)
|
181
198
|
hexewkb_parser.parse(hexewkb)
|
182
199
|
factory.geometry
|
183
200
|
end
|
184
201
|
|
185
|
-
# Creates a geometry based on a EWKT string. Since WKT strings are a
|
202
|
+
# Creates a geometry based on a EWKT string. Since WKT strings are a
|
203
|
+
# subset of EWKT, they are also valid.
|
186
204
|
def self.from_ewkt(ewkt)
|
187
|
-
factory = GeometryFactory
|
188
|
-
ewkt_parser= EWKTParser
|
205
|
+
factory = GeometryFactory.new
|
206
|
+
ewkt_parser = EWKTParser.new(factory)
|
189
207
|
ewkt_parser.parse(ewkt)
|
190
208
|
factory.geometry
|
191
209
|
end
|
192
210
|
|
193
211
|
# Creates a geometry based on the GeoRSS string given.
|
194
212
|
def self.from_georss(georss)
|
195
|
-
georss_parser= GeorssParser
|
213
|
+
georss_parser = GeorssParser.new
|
196
214
|
georss_parser.parse(georss)
|
197
215
|
georss_parser.geometry
|
198
216
|
end
|
199
217
|
|
200
|
-
# sends back an array: The first element is the goemetry based on the
|
218
|
+
# sends back an array: The first element is the goemetry based on the
|
219
|
+
# GeoRSS string passed as argument. The second one is the GeoRSSTags
|
220
|
+
# (found only with the Simple format)
|
201
221
|
def self.from_georss_with_tags(georss)
|
202
|
-
georss_parser= GeorssParser
|
203
|
-
georss_parser.parse(georss,true)
|
222
|
+
georss_parser = GeorssParser.new
|
223
|
+
georss_parser.parse(georss, true)
|
204
224
|
[georss_parser.geometry, georss_parser.georss_tags]
|
205
225
|
end
|
206
226
|
|
207
|
-
#Sends back a geometry from a KML encoded geometry string.
|
227
|
+
# Sends back a geometry from a KML encoded geometry string.
|
208
228
|
def self.from_kml(kml)
|
209
229
|
factory = GeometryFactory.new
|
210
230
|
parser = KmlParser.new(factory)
|
@@ -213,8 +233,8 @@ module GeoRuby#:nodoc:
|
|
213
233
|
|
214
234
|
# Some GeoJSON files do not include srid info, so
|
215
235
|
# we provide an optional parameter
|
216
|
-
def self.from_geojson(geojson, srid=DEFAULT_SRID)
|
217
|
-
geojson_parser=
|
236
|
+
def self.from_geojson(geojson, srid = DEFAULT_SRID)
|
237
|
+
geojson_parser = GeoJSONParser.new
|
218
238
|
geojson_parser.parse(geojson, srid)
|
219
239
|
geojson_parser.geometry
|
220
240
|
end
|
@@ -222,9 +242,9 @@ module GeoRuby#:nodoc:
|
|
222
242
|
private
|
223
243
|
|
224
244
|
def self.split_coords(coords)
|
225
|
-
coords.split(
|
226
|
-
coord.gsub(
|
227
|
-
|
245
|
+
coords.split(' ').collect do |coord|
|
246
|
+
coord.gsub(',', ' ')
|
247
|
+
end
|
228
248
|
end
|
229
249
|
end
|
230
250
|
end
|