georuby 2.2.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/geo_ruby/geojson.rb +1 -1
- data/lib/geo_ruby/simple_features/envelope.rb +2 -2
- data/lib/geo_ruby/simple_features/point.rb +138 -101
- data/lib/geo_ruby/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1df3941993b62765a00e7f70707184ef283c189a
|
4
|
+
data.tar.gz: 14626bcff00c29e6ac59747d54501e2d0e5b4be7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98448b91aa33033dc06db092a68e72d1e04a0dcad9c895cd34953c78acc9da96c28adbb74d3c951c835a98c2f01cfaa658d1f9028f127e282f05bc89c7dc7ff5
|
7
|
+
data.tar.gz: 2bba7b1eed46c75f3871508f82b4015803eef2617d1d474fcfe4dd3c7830c054d9a88c9f6e5b5e5121cb43da9129d376366a0d94c1ae0dc542d72cad404c8c78
|
data/lib/geo_ruby/geojson.rb
CHANGED
@@ -55,7 +55,7 @@ module GeoRuby
|
|
55
55
|
|
56
56
|
#Zoom level
|
57
57
|
def zoom
|
58
|
-
distance = lower_corner.spherical_distance(upper_corner)/
|
58
|
+
distance = lower_corner.spherical_distance(upper_corner) / 10_000
|
59
59
|
@zoom = case distance
|
60
60
|
when 150..9000 then 5
|
61
61
|
when 80..149 then 6
|
@@ -156,7 +156,7 @@ module GeoRuby
|
|
156
156
|
end
|
157
157
|
|
158
158
|
#Creates a new envelope. Accept a sequence of point coordinates as argument : ((x,y),(x,y))
|
159
|
-
def self.from_coordinates(points,srid=DEFAULT_SRID,with_z=false)
|
159
|
+
def self.from_coordinates(points, srid = DEFAULT_SRID, with_z = false)
|
160
160
|
e = Envelope.new(srid,with_z)
|
161
161
|
e.lower_corner, e.upper_corner = points.collect{|point_coords| Point.from_coordinates(point_coords,srid,with_z)}
|
162
162
|
e
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
require
|
2
|
+
require 'geo_ruby/simple_features/geometry'
|
3
3
|
|
4
4
|
module GeoRuby
|
5
5
|
module SimpleFeatures
|
@@ -10,7 +10,8 @@ module GeoRuby
|
|
10
10
|
attr_accessor :x,:y,:z,:m
|
11
11
|
attr_reader :r, :t # radium and theta
|
12
12
|
|
13
|
-
#
|
13
|
+
# If you prefer calling the coordinates lat and lon
|
14
|
+
# (or lng, for GeoKit compatibility)
|
14
15
|
alias :lon :x
|
15
16
|
alias :lng :x
|
16
17
|
alias :lat :y
|
@@ -21,10 +22,12 @@ module GeoRuby
|
|
21
22
|
def initialize(srid = DEFAULT_SRID, with_z = false, with_m = false)
|
22
23
|
super(srid, with_z, with_m)
|
23
24
|
@x = @y = 0.0
|
24
|
-
@z=0.0 #default value : meaningful if with_z
|
25
|
-
@m=0.0 #default value : meaningful if with_m
|
25
|
+
@z = 0.0 #default value : meaningful if with_z
|
26
|
+
@m = 0.0 #default value : meaningful if with_m
|
26
27
|
end
|
27
|
-
|
28
|
+
|
29
|
+
# Sets all coordinates in one call.
|
30
|
+
# Use the +m+ accessor to set the m.
|
28
31
|
def set_x_y_z(x, y, z)
|
29
32
|
@x = x && !x.is_a?(Numeric) ? x.to_f : x
|
30
33
|
@y = y && !y.is_a?(Numeric) ? y.to_f : y
|
@@ -33,7 +36,7 @@ module GeoRuby
|
|
33
36
|
end
|
34
37
|
alias :set_lon_lat_z :set_x_y_z
|
35
38
|
|
36
|
-
#
|
39
|
+
# Sets all coordinates of a 2D point in one call
|
37
40
|
def set_x_y(x, y)
|
38
41
|
@x = x && !x.is_a?(Numeric) ? x.to_f : x
|
39
42
|
@y = y && !y.is_a?(Numeric) ? y.to_f : y
|
@@ -41,21 +44,26 @@ module GeoRuby
|
|
41
44
|
end
|
42
45
|
alias :set_lon_lat :set_x_y
|
43
46
|
|
44
|
-
# Return the distance between the 2D points (ie taking care only
|
45
|
-
# the
|
47
|
+
# Return the distance between the 2D points (ie taking care only
|
48
|
+
# of the x and y coordinates), assuming the points are in
|
49
|
+
# projected coordinates.
|
50
|
+
#
|
51
|
+
# Euclidian distance in whatever unit the x and y ordinates are.
|
46
52
|
def euclidian_distance(point)
|
47
53
|
Math.sqrt((point.x - x)**2 + (point.y - y)**2)
|
48
54
|
end
|
49
55
|
|
50
56
|
# Spherical distance in meters, using 'Haversine' formula.
|
51
57
|
# with a radius of 6471000m
|
52
|
-
# Assumes x is the lon and y the lat, in degrees
|
53
|
-
# The user has to make sure using this distance makes sense
|
58
|
+
# Assumes x is the lon and y the lat, in degrees.
|
59
|
+
# The user has to make sure using this distance makes sense
|
60
|
+
# (ie she should be in latlon coordinates)
|
54
61
|
def spherical_distance(point, r = 6370997.0)
|
55
62
|
dlat = (point.lat - lat) * DEG2RAD / 2
|
56
63
|
dlon = (point.lon - lon) * DEG2RAD / 2
|
57
64
|
|
58
|
-
a = Math.sin(dlat)**2 + Math.cos(lat * DEG2RAD) *
|
65
|
+
a = Math.sin(dlat)**2 + Math.cos(lat * DEG2RAD) *
|
66
|
+
Math.cos(point.lat * DEG2RAD) * Math.sin(dlon)**2
|
59
67
|
c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a))
|
60
68
|
r * c
|
61
69
|
end
|
@@ -65,7 +73,7 @@ module GeoRuby
|
|
65
73
|
# b is the semi-minor axis (polar radius) of the ellipsoid
|
66
74
|
# Their values by default are set to the ones of the WGS84 ellipsoid
|
67
75
|
def ellipsoidal_distance(point, a = 6378137.0, b = 6356752.3142)
|
68
|
-
f = (a-b) / a
|
76
|
+
f = (a - b) / a
|
69
77
|
l = (point.lon - lon) * DEG2RAD
|
70
78
|
|
71
79
|
u1 = Math.atan((1-f) * Math.tan(lat * DEG2RAD ))
|
@@ -79,33 +87,43 @@ module GeoRuby
|
|
79
87
|
lambdaP = 2 * Math::PI
|
80
88
|
iterLimit = 20
|
81
89
|
|
82
|
-
while (lambda-lambdaP).abs > 1e-12 && --iterLimit>0
|
90
|
+
while (lambda - lambdaP).abs > 1e-12 && --iterLimit > 0
|
83
91
|
sinLambda = Math.sin(lambda)
|
84
92
|
cosLambda = Math.cos(lambda)
|
85
|
-
sinSigma
|
93
|
+
sinSigma =\
|
94
|
+
Math.sqrt((cosU2 * sinLambda) * (cosU2 * sinLambda) +
|
95
|
+
(cosU1 * sinU2 - sinU1 * cosU2 * cosLambda) *
|
96
|
+
(cosU1 * sinU2 - sinU1 * cosU2 * cosLambda))
|
86
97
|
|
87
|
-
return 0 if sinSigma == 0 #coincident points
|
98
|
+
return 0 if sinSigma == 0 # coincident points
|
88
99
|
|
89
|
-
cosSigma
|
90
|
-
sigma
|
91
|
-
sinAlpha
|
92
|
-
cosSqAlpha = 1 - sinAlpha*sinAlpha
|
93
|
-
cos2SigmaM = cosSigma - 2*sinU1*sinU2/cosSqAlpha
|
100
|
+
cosSigma = sinU1 * sinU2 + cosU1 * cosU2 * cosLambda
|
101
|
+
sigma = Math.atan2(sinSigma, cosSigma)
|
102
|
+
sinAlpha = cosU1 * cosU2 * sinLambda / sinSigma
|
103
|
+
cosSqAlpha = 1 - sinAlpha * sinAlpha
|
104
|
+
cos2SigmaM = cosSigma - 2 * sinU1 * sinU2 / cosSqAlpha
|
94
105
|
|
95
|
-
|
106
|
+
# equatorial line: cosSqAlpha=0
|
107
|
+
cos2SigmaM = 0 if (cos2SigmaM.nan?)
|
96
108
|
|
97
|
-
c = f/16*cosSqAlpha*(4+f*(4-3*cosSqAlpha))
|
109
|
+
c = f / 16 * cosSqAlpha * (4 + f * (4 - 3 * cosSqAlpha))
|
98
110
|
lambdaP = lambda
|
99
|
-
lambda = l + (1-c) * f * sinAlpha * (sigma + c * sinSigma *
|
111
|
+
lambda = l + (1 - c) * f * sinAlpha * (sigma + c * sinSigma *
|
112
|
+
(cos2SigmaM + c * cosSigma * (-1 + 2 * cos2SigmaM *
|
113
|
+
cos2SigmaM)))
|
100
114
|
end
|
115
|
+
|
101
116
|
return NaN if iterLimit==0 #formula failed to converge
|
102
117
|
|
103
118
|
uSq = cosSqAlpha * (a*a - b*b) / (b*b)
|
104
119
|
a_bis = 1 + uSq/16384*(4096+uSq*(-768+uSq*(320-175*uSq)))
|
105
|
-
b_bis = uSq/1024 * (256+uSq*(-128+uSq*(74-47*uSq)))
|
106
|
-
deltaSigma = b_bis * sinSigma*(cos2SigmaM + b_bis/4
|
120
|
+
b_bis = uSq/1024 * (256+uSq*(-128 + uSq * (74 - 47 * uSq)))
|
121
|
+
deltaSigma = b_bis * sinSigma * (cos2SigmaM + b_bis / 4 *
|
122
|
+
(cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM) - b_bis / 6 *
|
123
|
+
cos2SigmaM * (-3 + 4 * sinSigma * sinSigma) * (-3 + 4 *
|
124
|
+
cos2SigmaM * cos2SigmaM)))
|
107
125
|
|
108
|
-
b*a_bis*(sigma-deltaSigma)
|
126
|
+
b * a_bis * (sigma - deltaSigma)
|
109
127
|
end
|
110
128
|
|
111
129
|
# Orthogonal Distance
|
@@ -120,13 +138,14 @@ module GeoRuby
|
|
120
138
|
return 0.0 if len.zero?
|
121
139
|
res = dot / len
|
122
140
|
|
123
|
-
xx, yy
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
141
|
+
xx, yy =\
|
142
|
+
if res < 0
|
143
|
+
[head.x, head.y]
|
144
|
+
elsif res > 1
|
145
|
+
[tail.x, tail.y]
|
146
|
+
else
|
147
|
+
[head.x + res * c, head.y + res * d]
|
148
|
+
end
|
130
149
|
# todo benchmark if worth creating an instance
|
131
150
|
# euclidian_distance(Point.from_x_y(xx, yy))
|
132
151
|
Math.sqrt((@x - xx) ** 2 + (@y - yy) ** 2)
|
@@ -158,10 +177,10 @@ module GeoRuby
|
|
158
177
|
|
159
178
|
# Bounding box in 2D/3D. Returns an array of 2 points
|
160
179
|
def bounding_box
|
161
|
-
|
162
|
-
[Point.from_x_y(@x,@y),Point.from_x_y(@x,@y)]
|
163
|
-
else
|
180
|
+
if with_z
|
164
181
|
[Point.from_x_y_z(@x,@y,@z),Point.from_x_y_z(@x,@y,@z)]
|
182
|
+
else
|
183
|
+
[Point.from_x_y(@x,@y),Point.from_x_y(@x,@y)]
|
165
184
|
end
|
166
185
|
end
|
167
186
|
|
@@ -172,14 +191,14 @@ module GeoRuby
|
|
172
191
|
# Tests the equality of the position of points + m
|
173
192
|
def ==(other)
|
174
193
|
return false unless other.kind_of?(Point)
|
175
|
-
@x == other.x
|
194
|
+
@x == other.x && @y == other.y && @z == other.z && @m == other.m
|
176
195
|
end
|
177
196
|
|
178
197
|
# Binary representation of a point. It lacks some headers to be a valid EWKB representation.
|
179
198
|
def binary_representation(allow_z=true,allow_m=true) #:nodoc:
|
180
|
-
bin_rep = [@x.to_f,@y.to_f].pack(
|
181
|
-
bin_rep += [@z.to_f].pack(
|
182
|
-
bin_rep += [@m.to_f].pack(
|
199
|
+
bin_rep = [@x.to_f,@y.to_f].pack('EE')
|
200
|
+
bin_rep += [@z.to_f].pack('E') if @with_z && allow_z #Default value so no crash
|
201
|
+
bin_rep += [@m.to_f].pack('E') if @with_m && allow_m #idem
|
183
202
|
bin_rep
|
184
203
|
end
|
185
204
|
|
@@ -191,14 +210,14 @@ module GeoRuby
|
|
191
210
|
# Text representation of a point
|
192
211
|
def text_representation(allow_z=true,allow_m=true) #:nodoc:
|
193
212
|
tex_rep = "#{@x} #{@y}"
|
194
|
-
tex_rep += " #{@z}" if @with_z
|
195
|
-
tex_rep += " #{@m}" if @with_m
|
213
|
+
tex_rep += " #{@z}" if @with_z && allow_z
|
214
|
+
tex_rep += " #{@m}" if @with_m && allow_m
|
196
215
|
tex_rep
|
197
216
|
end
|
198
217
|
|
199
218
|
# WKT geometry type of a point
|
200
219
|
def text_geometry_type #:nodoc:
|
201
|
-
|
220
|
+
'POINT'
|
202
221
|
end
|
203
222
|
|
204
223
|
# georss simple representation
|
@@ -223,9 +242,12 @@ module GeoRuby
|
|
223
242
|
out += "</#{gml_ns}:pos>\n</#{gml_ns}:Point>\n</#{georss_ns}:where>\n"
|
224
243
|
end
|
225
244
|
|
226
|
-
# outputs the geometry in kml format : options are
|
227
|
-
# <tt>:
|
228
|
-
#
|
245
|
+
# outputs the geometry in kml format : options are
|
246
|
+
# <tt>:id</tt>, <tt>:tesselate</tt>, <tt>:extrude</tt>,
|
247
|
+
# <tt>:altitude_mode</tt>.
|
248
|
+
# If the altitude_mode option is not present, the Z (if present)
|
249
|
+
# will not be output (since it won't be used by GE anyway:
|
250
|
+
# clampToGround is the default)
|
229
251
|
def kml_representation(options = {}) #:nodoc:
|
230
252
|
out = "<Point#{options[:id_attr]}>\n"
|
231
253
|
out += options[:geom_data] if options[:geom_data]
|
@@ -237,10 +259,10 @@ module GeoRuby
|
|
237
259
|
|
238
260
|
def html_representation(options = {})
|
239
261
|
options[:coord] = true if options[:coord].nil?
|
240
|
-
out =
|
262
|
+
out = '<span class=\'geo\'>'
|
241
263
|
out += "<abbr class='latitude' title='#{x}'>#{as_lat(options)}</abbr>"
|
242
264
|
out += "<abbr class='longitude' title='#{y}'>#{as_long(options)}</abbr>"
|
243
|
-
out +=
|
265
|
+
out += '</span>'
|
244
266
|
end
|
245
267
|
|
246
268
|
# Human representation of the geom, don't use directly, use:
|
@@ -249,12 +271,12 @@ module GeoRuby
|
|
249
271
|
g.map do |k, v|
|
250
272
|
deg = v.to_i.abs
|
251
273
|
min = (60 * (v.abs - deg)).to_i
|
252
|
-
labs = (v *
|
253
|
-
sec = ((((labs - labs.to_i) * 60) - ((labs - labs.to_i) * 60).to_i) *
|
274
|
+
labs = (v * 1_000_000).abs / 1_000_000
|
275
|
+
sec = ((((labs - labs.to_i) * 60) - ((labs - labs.to_i) * 60).to_i) * 100_000) * 60 / 100_000
|
254
276
|
str = options[:full] ? "%.i°%.2i′%05.2f″" : "%.i°%.2i′%02.0f″"
|
255
277
|
if options[:coord]
|
256
278
|
out = str % [deg,min,sec]
|
257
|
-
out += k == :x ? v > 0 ?
|
279
|
+
out += k == :x ? v > 0 ? 'N' : 'S' : v > 0 ? 'E' : 'W'
|
258
280
|
else
|
259
281
|
str % [v.to_i, min, sec]
|
260
282
|
end
|
@@ -277,7 +299,7 @@ module GeoRuby
|
|
277
299
|
# Outputs the geometry in coordinates format:
|
278
300
|
# 47°52′48″, -20°06′00″
|
279
301
|
def as_latlong(options = {})
|
280
|
-
human_representation(options).join(
|
302
|
+
human_representation(options).join(', ')
|
281
303
|
end
|
282
304
|
alias :as_ll :as_latlong
|
283
305
|
|
@@ -286,9 +308,11 @@ module GeoRuby
|
|
286
308
|
# http://www.engineeringtoolbox.com/converting-cartesian-polar-coordinates-d_1347.html
|
287
309
|
# http://rcoordinate.rubyforge.org/svn/point.rb
|
288
310
|
# outputs radium
|
289
|
-
def r
|
311
|
+
def r
|
312
|
+
Math.sqrt(@x**2 + @y**2)
|
313
|
+
end
|
290
314
|
|
291
|
-
#
|
315
|
+
# Outputs theta
|
292
316
|
def theta_rad
|
293
317
|
if @x.zero?
|
294
318
|
@y < 0 ? 3 * HALFPI : HALFPI
|
@@ -298,13 +322,17 @@ module GeoRuby
|
|
298
322
|
end
|
299
323
|
end
|
300
324
|
|
301
|
-
#
|
302
|
-
def theta_deg
|
325
|
+
# Outputs theta in degrees
|
326
|
+
def theta_deg
|
327
|
+
theta_rad / DEG2RAD
|
328
|
+
end
|
303
329
|
|
304
|
-
#
|
305
|
-
def as_polar
|
330
|
+
# Outputs an array containing polar distance and theta
|
331
|
+
def as_polar
|
332
|
+
[r, t]
|
333
|
+
end
|
306
334
|
|
307
|
-
#
|
335
|
+
# Invert signal of all coordinates
|
308
336
|
def -@
|
309
337
|
set_x_y_z(-@x, -@y, -@z)
|
310
338
|
end
|
@@ -312,86 +340,95 @@ module GeoRuby
|
|
312
340
|
# TODO Perhaps should support with_m analogous to from_coordinates?
|
313
341
|
def to_coordinates
|
314
342
|
if with_z
|
315
|
-
[x,y,z]
|
343
|
+
[x, y, z]
|
316
344
|
else
|
317
|
-
[x,y]
|
345
|
+
[x, y]
|
318
346
|
end
|
319
347
|
end
|
320
348
|
|
349
|
+
# Simple helper for 2D maps
|
350
|
+
def to_xy
|
351
|
+
[x, y]
|
352
|
+
end
|
353
|
+
|
354
|
+
# Simple helper for 3D maps
|
355
|
+
def to_xyz
|
356
|
+
[x, y, z]
|
357
|
+
end
|
358
|
+
|
321
359
|
def as_json(options = {})
|
322
|
-
{:type => 'Point',
|
323
|
-
:coordinates => self.to_coordinates}
|
360
|
+
{ :type => 'Point', :coordinates => self.to_coordinates }
|
324
361
|
end
|
325
362
|
|
326
|
-
#
|
363
|
+
# Simple geojson representation
|
327
364
|
# TODO add CRS / SRID support?
|
328
365
|
def to_json(options = {})
|
329
366
|
as_json(options).to_json(options)
|
330
367
|
end
|
331
368
|
alias :as_geojson :to_json
|
332
369
|
|
333
|
-
#
|
334
|
-
def self.from_coordinates(coords,srid=DEFAULT_SRID,with_z=false,with_m=false)
|
335
|
-
if ! (with_z
|
336
|
-
from_x_y(coords[0],coords[1],srid)
|
337
|
-
elsif with_z
|
338
|
-
from_x_y_z_m(coords[0],coords[1],coords[2],coords[3],srid)
|
370
|
+
# Creates a point from an array of coordinates
|
371
|
+
def self.from_coordinates(coords, srid = DEFAULT_SRID, with_z = false, with_m = false)
|
372
|
+
if ! (with_z || with_m)
|
373
|
+
from_x_y(coords[0], coords[1], srid)
|
374
|
+
elsif with_z && with_m
|
375
|
+
from_x_y_z_m(coords[0], coords[1], coords[2], coords[3], srid)
|
339
376
|
elsif with_z
|
340
|
-
from_x_y_z(coords[0],coords[1],coords[2],srid)
|
377
|
+
from_x_y_z(coords[0], coords[1], coords[2], srid)
|
341
378
|
else
|
342
|
-
from_x_y_m(coords[0],coords[1],coords[2],srid)
|
379
|
+
from_x_y_m(coords[0], coords[1], coords[2], srid)
|
343
380
|
end
|
344
381
|
end
|
345
382
|
|
346
|
-
#
|
347
|
-
def self.from_x_y(x, y, srid=DEFAULT_SRID)
|
348
|
-
point= new(srid)
|
349
|
-
point.set_x_y(x,y)
|
383
|
+
# Creates a point from the X and Y coordinates
|
384
|
+
def self.from_x_y(x, y, srid = DEFAULT_SRID)
|
385
|
+
point = new(srid)
|
386
|
+
point.set_x_y(x, y)
|
350
387
|
end
|
351
388
|
|
352
|
-
#
|
353
|
-
def self.from_x_y_z(x, y, z, srid=DEFAULT_SRID)
|
354
|
-
point= new(srid,true)
|
355
|
-
point.set_x_y_z(x,y,z)
|
389
|
+
# Creates a point from the X, Y and Z coordinates
|
390
|
+
def self.from_x_y_z(x, y, z, srid = DEFAULT_SRID)
|
391
|
+
point = new(srid, true)
|
392
|
+
point.set_x_y_z(x, y, z)
|
356
393
|
end
|
357
394
|
|
358
|
-
#
|
359
|
-
def self.from_x_y_m(x, y, m, srid=DEFAULT_SRID)
|
360
|
-
point= new(srid,false,true)
|
361
|
-
point.m=m
|
362
|
-
point.set_x_y(x,y)
|
395
|
+
# Creates a point from the X, Y and M coordinates
|
396
|
+
def self.from_x_y_m(x, y, m, srid = DEFAULT_SRID)
|
397
|
+
point = new(srid, false, true)
|
398
|
+
point.m = m
|
399
|
+
point.set_x_y(x, y)
|
363
400
|
end
|
364
401
|
|
365
|
-
#
|
366
|
-
def self.from_x_y_z_m(x, y, z, m, srid=DEFAULT_SRID)
|
367
|
-
point= new(srid,true,true)
|
368
|
-
point.m=m
|
369
|
-
point.set_x_y_z(x,y,z)
|
402
|
+
# Creates a point from the X, Y, Z and M coordinates
|
403
|
+
def self.from_x_y_z_m(x, y, z, m, srid = DEFAULT_SRID)
|
404
|
+
point = new(srid, true, true)
|
405
|
+
point.m = m
|
406
|
+
point.set_x_y_z(x, y, z)
|
370
407
|
end
|
371
408
|
|
372
|
-
#
|
373
|
-
#r and theta(degrees)
|
374
|
-
def self.from_r_t(r, t, srid=DEFAULT_SRID)
|
409
|
+
# Creates a point using polar coordinates
|
410
|
+
# r and theta(degrees)
|
411
|
+
def self.from_r_t(r, t, srid = DEFAULT_SRID)
|
375
412
|
t *= DEG2RAD
|
376
413
|
x = r * Math.cos(t)
|
377
414
|
y = r * Math.sin(t)
|
378
|
-
point= new(srid)
|
379
|
-
point.set_x_y(x,y)
|
415
|
+
point = new(srid)
|
416
|
+
point.set_x_y(x, y)
|
380
417
|
end
|
381
418
|
|
382
|
-
#
|
383
|
-
def self.from_latlong(lat, lon, srid=DEFAULT_SRID)
|
384
|
-
p = [lat,lon].map do |l|
|
419
|
+
# Creates a point using coordinates like 22`34 23.45N
|
420
|
+
def self.from_latlong(lat, lon, srid = DEFAULT_SRID)
|
421
|
+
p = [lat, lon].map do |l|
|
385
422
|
sig, deg, min, sec, cen = l.scan(/(-)?(\d{1,2})\D*(\d{2})\D*(\d{2})(\D*(\d{1,3}))?/).flatten
|
386
423
|
sig = true if l =~ /W|S/
|
387
424
|
dec = deg.to_i + (min.to_i * 60 + "#{sec}#{cen}".to_f) / 3600
|
388
425
|
sig ? dec * -1 : dec
|
389
426
|
end
|
390
|
-
point= new(srid)
|
391
|
-
point.set_x_y(p[0],p[1])
|
427
|
+
point = new(srid)
|
428
|
+
point.set_x_y(p[0], p[1])
|
392
429
|
end
|
393
430
|
|
394
|
-
#
|
431
|
+
# Aliasing the constructors in case you like lat/lon instead of y/x
|
395
432
|
class << self
|
396
433
|
alias :xy :from_x_y
|
397
434
|
alias :from_xy :from_x_y
|
data/lib/geo_ruby/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: georuby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guilhem Vellut
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-11-
|
14
|
+
date: 2013-11-13 00:00:00.000000000 Z
|
15
15
|
dependencies: []
|
16
16
|
description: GeoRuby provides geometric data types from the OGC 'Simple Features'
|
17
17
|
specification.
|