georuby 2.0.0 → 2.2.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 +7 -0
- data/{README.rdoc → README.md} +45 -34
- data/lib/geo_ruby/simple_features.rb +2 -2
- data/lib/geo_ruby/simple_features/geometry.rb +62 -43
- data/lib/geo_ruby/simple_features/line_string.rb +2 -2
- data/lib/geo_ruby/simple_features/point.rb +82 -61
- data/lib/geo_ruby/version.rb +1 -1
- data/lib/georuby.rb +2 -0
- data/spec/geo_ruby/georss_spec.rb +7 -7
- data/spec/geo_ruby/kml_spec.rb +22 -3
- data/spec/geo_ruby/simple_features/geometry_spec.rb +10 -2
- data/spec/geo_ruby/simple_features/line_string_spec.rb +5 -5
- data/spec/geo_ruby/simple_features/point_spec.rb +65 -4
- data/spec/spec_helper.rb +5 -1
- metadata +12 -98
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 18405683e03e3da7a272be360c5bb5c8bff05a25
|
4
|
+
data.tar.gz: 5ceefaf8c76fdf9f8d9b47b54ec1530b8eb485b4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c4a344a8b430b5bdf67e3f90c5f4b9327d53a69eb23ef87b3bdebfe97bf65c7ab4ebee285f970e5b1ae61896a7622f2c0deb237d268a3c54b2a4f39d1d0a7ed3
|
7
|
+
data.tar.gz: bbd50a644084b9f1e60cd128438cd7f33b88e9de603263553be23a47528f917b0e7d2c1de8f0d3d3588d08515a16aeeca6cd925fa03d065f06dea9ddad437730
|
data/{README.rdoc → README.md}
RENAMED
@@ -1,20 +1,25 @@
|
|
1
|
-
|
1
|
+
GeoRuby
|
2
|
+
=======
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
play nice with data returned from PostGIS or any Spatial Extensions (MongoDB, MySQL...).
|
7
|
-
Although without any kind of advanced functionalities (such as geometric operators or reprojections).
|
4
|
+
This is intended as a holder for geometric data.
|
5
|
+
The data model roughly follows the OGC "Simple Features for SQL" specification,
|
6
|
+
so it should play nice with data returned from PostGIS or any Spatial Extensions (MongoDB, MySQL...).
|
8
7
|
It also supports various output and input formats (GeoRSS, KML, Shapefile).
|
8
|
+
GeoRuby is written in pure Ruby.
|
9
9
|
|
10
10
|
OGC:"http://www.opengis.org/docs/99-049.pdf"
|
11
11
|
|
12
|
-
|
13
|
-
If you are looking for Proj/Geos/ext C rubygem checkout:
|
12
|
+
If you are looking for Proj/Geos (geometric operators or reprojections) rubygem checkout: (C extension)
|
14
13
|
rgeo:"https://github.com/dazuma/rgeo"
|
15
14
|
|
15
|
+
[](http://badge.fury.io/rb/georuby)
|
16
|
+
[](https://codeclimate.com/github/nofxx/georuby)
|
17
|
+
[](https://travis-ci.org/nofxx/georuby)
|
18
|
+
[](https://coveralls.io/r/nofxx/georuby)
|
16
19
|
|
17
|
-
|
20
|
+
|
21
|
+
Available data types
|
22
|
+
--------------------
|
18
23
|
|
19
24
|
The following geometric data types are provided :
|
20
25
|
- Point
|
@@ -31,7 +36,8 @@ They can be in 2D, 3DZ, 3DM, and 4D.
|
|
31
36
|
On top of this an Envelope class is available, to contain the bounding box of a geometry.
|
32
37
|
|
33
38
|
|
34
|
-
|
39
|
+
Installation
|
40
|
+
------------
|
35
41
|
|
36
42
|
To install the latest version, just type:
|
37
43
|
|
@@ -43,19 +49,21 @@ Or include on your projects`s Gemfile:
|
|
43
49
|
gem 'georuby'
|
44
50
|
|
45
51
|
|
46
|
-
Optional, require if you need
|
52
|
+
Optional, require if you need the functionality:
|
47
53
|
|
48
|
-
require 'geo_ruby/shp4r/shp'
|
49
|
-
require 'geo_ruby/gpx4r/gpx'
|
50
|
-
require 'geo_ruby/geojson'
|
51
|
-
require 'geo_ruby/georss'
|
52
|
-
require 'geo_ruby/kml'
|
53
54
|
|
55
|
+
require 'geo_ruby/shp4r/shp' # Shapefile
|
56
|
+
require 'geo_ruby/gpx4r/gpx' # GPX data
|
57
|
+
require 'geo_ruby/geojson' # GeoJSON
|
58
|
+
require 'geo_ruby/georss' # GeoRSS
|
59
|
+
require 'geo_ruby/kml' # KML data
|
54
60
|
|
55
|
-
== Use
|
56
61
|
|
62
|
+
Use
|
63
|
+
===
|
57
64
|
|
58
|
-
|
65
|
+
Simple Examples
|
66
|
+
----------------
|
59
67
|
|
60
68
|
Creating a 3D Point:
|
61
69
|
|
@@ -67,7 +75,8 @@ Creating a LineString:
|
|
67
75
|
LineString.from_coordinates([[1,1],[2,2]],4326))
|
68
76
|
|
69
77
|
|
70
|
-
|
78
|
+
Input and output
|
79
|
+
----------------
|
71
80
|
|
72
81
|
These geometries can be input and output in WKB/EWKB/WKT/EWKT format as well as
|
73
82
|
the related HexWKB and HexEWKB formats. HexEWKB and WKB are the default form under
|
@@ -92,7 +101,8 @@ the altitude data will not be output even if present. Envelopes output a LatLonA
|
|
92
101
|
For the output, the following geometric types are supported : Point, LineString, Polygon.
|
93
102
|
|
94
103
|
|
95
|
-
|
104
|
+
SHP reading et writing
|
105
|
+
---
|
96
106
|
|
97
107
|
Georuby has support for reading ESRI shapefiles (http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf).
|
98
108
|
A tool called <tt>shp2sql.rb</tt> is also provided: it shows how to use the SHP reading functionality together
|
@@ -144,15 +154,19 @@ Also currently, error reporting is minimal and it has not been tested that
|
|
144
154
|
thoroughly so caveat emptor and backup before performing any destructive operation.
|
145
155
|
|
146
156
|
|
147
|
-
|
157
|
+
GPX Reading
|
158
|
+
---
|
148
159
|
|
149
160
|
You can read and convert GPX Files to LineString/Polygon:
|
150
161
|
|
151
|
-
gpxfile = GpxFile.open(tour.gpx')
|
162
|
+
gpxfile = GpxFile.open('tour.gpx')
|
152
163
|
gpxfile.as_line_string
|
153
164
|
=> GeoRuby::SimpleFeatures::LineString..
|
154
165
|
|
155
|
-
|
166
|
+
|
167
|
+
GeoJSON Support
|
168
|
+
-------
|
169
|
+
|
156
170
|
Basic GeoJSON support has been implemented per v1.0 of the {spec}[http://geojson.org/geojson-spec.html].
|
157
171
|
|
158
172
|
USAGE:
|
@@ -169,15 +183,19 @@ TODO:
|
|
169
183
|
|
170
184
|
GeoJSON support implemented by {Marcus Mateus}[http://github.com/marcusmateus] and released courtesy {SimpliTex}[http://simplitex.com].
|
171
185
|
|
186
|
+
|
187
|
+
=== Extra Features
|
188
|
+
|
189
|
+
- Writing of ESRI shapefiles
|
190
|
+
- Reading of ESRI shapefiles
|
191
|
+
- Tool to import spatial features in MySQL and PostGIS from a SHP file
|
192
|
+
|
193
|
+
|
172
194
|
=== Acknowledgement
|
173
195
|
|
174
196
|
The SHP reading part uses the DBF library (http://rubyforge.org/projects/dbf/) by Keith Morrison (http://infused.org).
|
175
197
|
Thanks also to Pramukta Kumar and Pete Schwamb for their contributions.
|
176
198
|
|
177
|
-
=== License
|
178
|
-
|
179
|
-
GeoRuby is released under the MIT license.
|
180
|
-
|
181
199
|
|
182
200
|
== Support (Original GeoRuby gem)
|
183
201
|
|
@@ -185,13 +203,6 @@ Any questions, enhancement proposals, bug notifications or corrections
|
|
185
203
|
can be sent to mailto:guilhem.vellut@gmail.com.
|
186
204
|
|
187
205
|
|
188
|
-
=== Changes since the last version
|
189
|
-
|
190
|
-
- Writing of ESRI shapefiles
|
191
|
-
- Reading of ESRI shapefiles
|
192
|
-
- Addition of a small tool to import spatial features in MySQL and PostGIS from a SHP file
|
193
|
-
|
194
|
-
|
195
206
|
=== Coming in the next versions
|
196
207
|
|
197
208
|
- Schema modification of existing shapefiles
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module GeoRuby#:nodoc:
|
2
2
|
module SimpleFeatures
|
3
|
-
#arbitrary default SRID
|
4
|
-
DEFAULT_SRID = 4326 unless defined? DEFAULT_SRID
|
5
3
|
|
4
|
+
# Default SRID
|
5
|
+
DEFAULT_SRID = 4326 unless defined? DEFAULT_SRID
|
6
6
|
|
7
7
|
#Root of all geometric data classes.
|
8
8
|
#Objects of class Geometry should not be instantiated.
|
@@ -16,7 +16,7 @@ module GeoRuby#:nodoc:
|
|
16
16
|
attr_accessor :with_m
|
17
17
|
alias :with_m? :with_m
|
18
18
|
|
19
|
-
def initialize(srid=DEFAULT_SRID,with_z=false,with_m=false)
|
19
|
+
def initialize(srid=DEFAULT_SRID, with_z=false, with_m=false)
|
20
20
|
@srid=srid
|
21
21
|
@with_z=with_z
|
22
22
|
@with_m=with_m
|
@@ -31,59 +31,73 @@ module GeoRuby#:nodoc:
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
#to be implemented in subclasses
|
34
|
+
# to be implemented in subclasses
|
35
35
|
def bounding_box
|
36
36
|
end
|
37
37
|
|
38
|
-
#to be implemented in subclasses
|
38
|
+
# to be implemented in subclasses
|
39
39
|
def m_range
|
40
40
|
end
|
41
41
|
|
42
|
-
#
|
42
|
+
#
|
43
|
+
# Returns an Envelope object for the geometry
|
44
|
+
#
|
43
45
|
def envelope
|
44
|
-
Envelope.from_points(bounding_box,srid,with_z)
|
46
|
+
Envelope.from_points(bounding_box, srid,with_z)
|
45
47
|
end
|
46
48
|
|
47
|
-
#
|
48
|
-
#
|
49
|
-
|
50
|
-
|
49
|
+
#
|
50
|
+
# Outputs the geometry as an EWKB string.
|
51
|
+
#
|
52
|
+
# The +allow_srid+, +allow_z+ and +allow_m+ arguments allow the output
|
53
|
+
# to include srid, z and m respectively if they are present in the geometry.
|
54
|
+
# If these arguments are set to false, srid, z and m are not included,
|
55
|
+
# even if they are present in the geometry.
|
56
|
+
# By default, the output string contains all the information in the object.
|
57
|
+
#
|
58
|
+
def as_ewkb(allow_srid=true, allow_z=true, allow_m=true)
|
59
|
+
ewkb = 1.chr #little_endian by default
|
51
60
|
|
52
|
-
|
61
|
+
type = binary_geometry_type
|
62
|
+
type = type | Z_MASK if @with_z and allow_z
|
63
|
+
type = type | M_MASK if @with_m and allow_m
|
53
64
|
|
54
|
-
type= binary_geometry_type
|
55
|
-
if @with_z and allow_z
|
56
|
-
type = type | Z_MASK
|
57
|
-
end
|
58
|
-
if @with_m and allow_m
|
59
|
-
type = type | M_MASK
|
60
|
-
end
|
61
65
|
if allow_srid
|
62
66
|
type = type | SRID_MASK
|
63
|
-
ewkb << [type
|
67
|
+
ewkb << [type, @srid].pack("VV")
|
64
68
|
else
|
65
69
|
ewkb << [type].pack("V")
|
66
70
|
end
|
67
71
|
|
68
|
-
ewkb
|
72
|
+
ewkb << binary_representation(allow_z, allow_m)
|
69
73
|
end
|
70
74
|
|
71
|
-
#
|
75
|
+
#
|
76
|
+
# Outputs the geometry as a strict WKB string.
|
77
|
+
#
|
72
78
|
def as_wkb
|
73
|
-
as_ewkb(false,false,false)
|
79
|
+
as_ewkb(false, false, false)
|
74
80
|
end
|
75
81
|
|
76
|
-
#
|
77
|
-
|
82
|
+
#
|
83
|
+
# Outputs the geometry as a HexEWKB string.
|
84
|
+
# It is almost the same as a WKB string, except that each byte of a WKB
|
85
|
+
# string is replaced by its hexadecimal 2-character representation in a HexEWKB string.
|
86
|
+
#
|
87
|
+
def as_hex_ewkb(allow_srid=true, allow_z=true, allow_m=true)
|
78
88
|
as_ewkb(allow_srid, allow_z, allow_m).unpack('H*').join('').upcase
|
79
89
|
end
|
80
90
|
|
81
|
-
#
|
91
|
+
#
|
92
|
+
# Outputs the geometry as a strict HexWKB string
|
93
|
+
#
|
82
94
|
def as_hex_wkb
|
83
95
|
as_hex_ewkb(false,false,false)
|
84
96
|
end
|
85
97
|
|
86
|
-
#
|
98
|
+
#
|
99
|
+
# Outputs the geometry as an EWKT string.
|
100
|
+
#
|
87
101
|
def as_ewkt(allow_srid=true,allow_z=true,allow_m=true)
|
88
102
|
if allow_srid
|
89
103
|
ewkt="SRID=#{@srid};"
|
@@ -95,14 +109,16 @@ module GeoRuby#:nodoc:
|
|
95
109
|
ewkt << "(" << text_representation(allow_z,allow_m) << ")"
|
96
110
|
end
|
97
111
|
|
98
|
-
#
|
112
|
+
#
|
113
|
+
# Outputs the geometry as strict WKT string.
|
114
|
+
#
|
99
115
|
def as_wkt
|
100
|
-
as_ewkt(false,false,false)
|
116
|
+
as_ewkt(false, false, false)
|
101
117
|
end
|
102
118
|
|
103
|
-
#Outputs the geometry in georss format.
|
104
|
-
#Assumes the geometries are in latlon format, with x as lon and y as lat.
|
105
|
-
#Pass the <tt>:dialect</tt> option to swhit format. Possible values are: <tt>:simple</tt> (default), <tt>:w3cgeo</tt> and <tt>:gml</tt>.
|
119
|
+
# Outputs the geometry in georss format.
|
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: <tt>:simple</tt> (default), <tt>:w3cgeo</tt> and <tt>:gml</tt>.
|
106
122
|
def as_georss(options = {})
|
107
123
|
dialect= options[:dialect] || :simple
|
108
124
|
case(dialect)
|
@@ -121,9 +137,9 @@ module GeoRuby#:nodoc:
|
|
121
137
|
end
|
122
138
|
end
|
123
139
|
|
124
|
-
#Iutputs the geometry in kml format : options are <tt>:id</tt>, <tt>:tesselate</tt>, <tt>:extrude</tt>,
|
125
|
-
|
126
|
-
#it won't be used by GE anyway: clampToGround is the default)
|
140
|
+
# Iutputs the geometry in kml format : options are <tt>:id</tt>, <tt>:tesselate</tt>, <tt>:extrude</tt>,
|
141
|
+
# <tt>:altitude_mode</tt>. If the altitude_mode option is not present, the Z (if present) will not be output (since
|
142
|
+
# it won't be used by GE anyway: clampToGround is the default)
|
127
143
|
def as_kml(options = {})
|
128
144
|
id_attr = ""
|
129
145
|
id_attr = " id=\"#{options[:id]}\"" if options[:id]
|
@@ -139,21 +155,23 @@ module GeoRuby#:nodoc:
|
|
139
155
|
kml_representation(options.merge(:id_attr => id_attr, :geom_data => geom_data, :allow_z => allow_z, :fixed_z => fixed_z))
|
140
156
|
end
|
141
157
|
|
142
|
-
#Creates a geometry based on a EWKB string. The actual class returned depends of the content of the string passed as argument. Since WKB strings are a subset of EWKB, they are also valid.
|
158
|
+
# Creates a geometry based on a EWKB string. The actual class returned depends of the content of the string passed as argument. Since WKB strings are a subset of EWKB, they are also valid.
|
143
159
|
def self.from_ewkb(ewkb)
|
144
160
|
factory = GeometryFactory::new
|
145
|
-
ewkb_parser= EWKBParser::new(factory)
|
161
|
+
ewkb_parser = EWKBParser::new(factory)
|
146
162
|
ewkb_parser.parse(ewkb)
|
147
163
|
factory.geometry
|
148
164
|
end
|
149
|
-
|
165
|
+
|
166
|
+
# Creates a geometry based on a HexEWKB string given.
|
150
167
|
def self.from_hex_ewkb(hexewkb)
|
151
168
|
factory = GeometryFactory::new
|
152
|
-
hexewkb_parser= HexEWKBParser::new(factory)
|
169
|
+
hexewkb_parser = HexEWKBParser::new(factory)
|
153
170
|
hexewkb_parser.parse(hexewkb)
|
154
171
|
factory.geometry
|
155
172
|
end
|
156
|
-
|
173
|
+
|
174
|
+
# Creates a geometry based on a EWKT string. Since WKT strings are a subset of EWKT, they are also valid.
|
157
175
|
def self.from_ewkt(ewkt)
|
158
176
|
factory = GeometryFactory::new
|
159
177
|
ewkt_parser= EWKTParser::new(factory)
|
@@ -161,13 +179,14 @@ module GeoRuby#:nodoc:
|
|
161
179
|
factory.geometry
|
162
180
|
end
|
163
181
|
|
164
|
-
#
|
182
|
+
# Creates a geometry based on the GeoRSS string given.
|
165
183
|
def self.from_georss(georss)
|
166
184
|
georss_parser= GeorssParser::new
|
167
185
|
georss_parser.parse(georss)
|
168
186
|
georss_parser.geometry
|
169
187
|
end
|
170
|
-
|
188
|
+
|
189
|
+
# sends back an array: The first element is the goemetry based on the GeoRSS string passed as argument. The second one is the GeoRSSTags (found only with the Simple format)
|
171
190
|
def self.from_georss_with_tags(georss)
|
172
191
|
georss_parser= GeorssParser::new
|
173
192
|
georss_parser.parse(georss,true)
|
@@ -180,7 +199,7 @@ module GeoRuby#:nodoc:
|
|
180
199
|
parser = KmlParser.new(factory)
|
181
200
|
parser.parse(kml)
|
182
201
|
end
|
183
|
-
|
202
|
+
|
184
203
|
# Some GeoJSON files do not include srid info, so
|
185
204
|
# we provide an optional parameter
|
186
205
|
def self.from_geojson(geojson, srid=DEFAULT_SRID)
|
@@ -63,8 +63,8 @@ module GeoRuby
|
|
63
63
|
if with_m
|
64
64
|
max_m, min_m = -Float::MAX, Float::MAX
|
65
65
|
each do |point|
|
66
|
-
max_m = point.m if point.m > max_m
|
67
|
-
min_m = point.m if point.m < min_m
|
66
|
+
max_m = point.m if point.m.to_f > max_m
|
67
|
+
min_m = point.m if point.m.to_f < min_m
|
68
68
|
end
|
69
69
|
[min_m,max_m]
|
70
70
|
else
|
@@ -3,14 +3,14 @@ require "geo_ruby/simple_features/geometry"
|
|
3
3
|
|
4
4
|
module GeoRuby
|
5
5
|
module SimpleFeatures
|
6
|
-
#Represents a point. It is in 3D if the Z coordinate is not +nil+.
|
6
|
+
# Represents a point. It is in 3D if the Z coordinate is not +nil+.
|
7
7
|
class Point < Geometry
|
8
8
|
DEG2RAD = 0.0174532925199433
|
9
9
|
HALFPI = 1.5707963267948966
|
10
10
|
attr_accessor :x,:y,:z,:m
|
11
11
|
attr_reader :r, :t # radium and theta
|
12
12
|
|
13
|
-
#if you prefer calling the coordinates lat and lon (or lng, for GeoKit compatibility)
|
13
|
+
# if you prefer calling the coordinates lat and lon (or lng, for GeoKit compatibility)
|
14
14
|
alias :lon :x
|
15
15
|
alias :lng :x
|
16
16
|
alias :lat :y
|
@@ -18,31 +18,31 @@ module GeoRuby
|
|
18
18
|
alias :tet :t
|
19
19
|
alias :tetha :t
|
20
20
|
|
21
|
-
def initialize(srid=DEFAULT_SRID,with_z=false,with_m=false)
|
22
|
-
super(srid,with_z,with_m)
|
21
|
+
def initialize(srid = DEFAULT_SRID, with_z = false, with_m = false)
|
22
|
+
super(srid, with_z, with_m)
|
23
23
|
@x = @y = 0.0
|
24
24
|
@z=0.0 #default value : meaningful if with_z
|
25
25
|
@m=0.0 #default value : meaningful if with_m
|
26
26
|
end
|
27
27
|
#sets all coordinates in one call. Use the +m+ accessor to set the m.
|
28
|
-
def set_x_y_z(x,y,z)
|
29
|
-
@x=x
|
30
|
-
@y=y
|
31
|
-
@z=z
|
28
|
+
def set_x_y_z(x, y, z)
|
29
|
+
@x = x && !x.is_a?(Numeric) ? x.to_f : x
|
30
|
+
@y = y && !y.is_a?(Numeric) ? y.to_f : y
|
31
|
+
@z = z && !z.is_a?(Numeric) ? z.to_f : z
|
32
32
|
self
|
33
33
|
end
|
34
34
|
alias :set_lon_lat_z :set_x_y_z
|
35
35
|
|
36
36
|
#sets all coordinates of a 2D point in one call
|
37
|
-
def set_x_y(x,y)
|
38
|
-
@x=x
|
39
|
-
@y=y
|
37
|
+
def set_x_y(x, y)
|
38
|
+
@x = x && !x.is_a?(Numeric) ? x.to_f : x
|
39
|
+
@y = y && !y.is_a?(Numeric) ? y.to_f : y
|
40
40
|
self
|
41
41
|
end
|
42
42
|
alias :set_lon_lat :set_x_y
|
43
43
|
|
44
|
-
#Return the distance between the 2D points (ie taking care only of the x and y coordinates), assuming
|
45
|
-
#the points are in projected coordinates. Euclidian distance in whatever unit the x and y ordinates are.
|
44
|
+
# Return the distance between the 2D points (ie taking care only of the x and y coordinates), assuming
|
45
|
+
# the points are in projected coordinates. Euclidian distance in whatever unit the x and y ordinates are.
|
46
46
|
def euclidian_distance(point)
|
47
47
|
Math.sqrt((point.x - x)**2 + (point.y - y)**2)
|
48
48
|
end
|
@@ -51,7 +51,7 @@ module GeoRuby
|
|
51
51
|
# with a radius of 6471000m
|
52
52
|
# Assumes x is the lon and y the lat, in degrees (Changed in version 1.1).
|
53
53
|
# The user has to make sure using this distance makes sense (ie she should be in latlon coordinates)
|
54
|
-
def spherical_distance(point,r=6370997.0)
|
54
|
+
def spherical_distance(point, r = 6370997.0)
|
55
55
|
dlat = (point.lat - lat) * DEG2RAD / 2
|
56
56
|
dlon = (point.lon - lon) * DEG2RAD / 2
|
57
57
|
|
@@ -60,10 +60,10 @@ module GeoRuby
|
|
60
60
|
r * c
|
61
61
|
end
|
62
62
|
|
63
|
-
#Ellipsoidal distance in m using Vincenty's formula. Lifted entirely from Chris Veness's code at http://www.movable-type.co.uk/scripts/LatLongVincenty.html and adapted for Ruby. Assumes the x and y are the lon and lat in degrees.
|
64
|
-
#a is the semi-major axis (equatorial radius) of the ellipsoid
|
65
|
-
#b is the semi-minor axis (polar radius) of the ellipsoid
|
66
|
-
#Their values by default are set to the ones of the WGS84 ellipsoid
|
63
|
+
# Ellipsoidal distance in m using Vincenty's formula. Lifted entirely from Chris Veness's code at http://www.movable-type.co.uk/scripts/LatLongVincenty.html and adapted for Ruby. Assumes the x and y are the lon and lat in degrees.
|
64
|
+
# a is the semi-major axis (equatorial radius) of the ellipsoid
|
65
|
+
# b is the semi-minor axis (polar radius) of the ellipsoid
|
66
|
+
# Their values by default are set to the ones of the WGS84 ellipsoid
|
67
67
|
def ellipsoidal_distance(point, a = 6378137.0, b = 6356752.3142)
|
68
68
|
f = (a-b) / a
|
69
69
|
l = (point.lon - lon) * DEG2RAD
|
@@ -132,7 +132,7 @@ module GeoRuby
|
|
132
132
|
Math.sqrt((@x - xx) ** 2 + (@y - yy) ** 2)
|
133
133
|
end
|
134
134
|
|
135
|
-
#Bearing from a point to another, in degrees.
|
135
|
+
# Bearing from a point to another, in degrees.
|
136
136
|
def bearing_to(other)
|
137
137
|
return 0 if self == other
|
138
138
|
a,b = other.x - self.x, other.y - self.y
|
@@ -140,7 +140,7 @@ module GeoRuby
|
|
140
140
|
a < 0 ? 360 - res : res
|
141
141
|
end
|
142
142
|
|
143
|
-
#Bearing from a point to another as symbols. (:n, :s, :sw, :ne...)
|
143
|
+
# Bearing from a point to another as symbols. (:n, :s, :sw, :ne...)
|
144
144
|
def bearing_text(other)
|
145
145
|
case bearing_to(other)
|
146
146
|
when 1..22 then :n
|
@@ -156,7 +156,7 @@ module GeoRuby
|
|
156
156
|
end
|
157
157
|
end
|
158
158
|
|
159
|
-
#Bounding box in 2D/3D. Returns an array of 2 points
|
159
|
+
# Bounding box in 2D/3D. Returns an array of 2 points
|
160
160
|
def bounding_box
|
161
161
|
unless with_z
|
162
162
|
[Point.from_x_y(@x,@y),Point.from_x_y(@x,@y)]
|
@@ -169,13 +169,13 @@ module GeoRuby
|
|
169
169
|
[@m,@m]
|
170
170
|
end
|
171
171
|
|
172
|
-
#
|
172
|
+
# Tests the equality of the position of points + m
|
173
173
|
def ==(other)
|
174
174
|
return false unless other.kind_of?(Point)
|
175
175
|
@x == other.x and @y == other.y and @z == other.z and @m == other.m
|
176
176
|
end
|
177
177
|
|
178
|
-
#
|
178
|
+
# Binary representation of a point. It lacks some headers to be a valid EWKB representation.
|
179
179
|
def binary_representation(allow_z=true,allow_m=true) #:nodoc:
|
180
180
|
bin_rep = [@x.to_f,@y.to_f].pack("EE")
|
181
181
|
bin_rep += [@z.to_f].pack("E") if @with_z and allow_z #Default value so no crash
|
@@ -183,12 +183,12 @@ module GeoRuby
|
|
183
183
|
bin_rep
|
184
184
|
end
|
185
185
|
|
186
|
-
#WKB geometry type of a point
|
186
|
+
# WKB geometry type of a point
|
187
187
|
def binary_geometry_type#:nodoc:
|
188
188
|
1
|
189
189
|
end
|
190
190
|
|
191
|
-
#
|
191
|
+
# Text representation of a point
|
192
192
|
def text_representation(allow_z=true,allow_m=true) #:nodoc:
|
193
193
|
tex_rep = "#{@x} #{@y}"
|
194
194
|
tex_rep += " #{@z}" if @with_z and allow_z
|
@@ -196,70 +196,91 @@ module GeoRuby
|
|
196
196
|
tex_rep
|
197
197
|
end
|
198
198
|
|
199
|
-
#WKT geometry type of a point
|
199
|
+
# WKT geometry type of a point
|
200
200
|
def text_geometry_type #:nodoc:
|
201
201
|
"POINT"
|
202
202
|
end
|
203
203
|
|
204
|
-
#georss simple representation
|
204
|
+
# georss simple representation
|
205
205
|
def georss_simple_representation(options) #:nodoc:
|
206
206
|
georss_ns = options[:georss_ns] || "georss"
|
207
207
|
geom_attr = options[:geom_attr]
|
208
208
|
"<#{georss_ns}:point#{geom_attr}>#{y} #{x}</#{georss_ns}:point>\n"
|
209
209
|
end
|
210
210
|
|
211
|
-
#georss w3c representation
|
211
|
+
# georss w3c representation
|
212
212
|
def georss_w3cgeo_representation(options) #:nodoc:
|
213
213
|
w3cgeo_ns = options[:w3cgeo_ns] || "geo"
|
214
214
|
"<#{w3cgeo_ns}:lat>#{y}</#{w3cgeo_ns}:lat>\n<#{w3cgeo_ns}:long>#{x}</#{w3cgeo_ns}:long>\n"
|
215
215
|
end
|
216
216
|
|
217
|
-
#georss gml representation
|
217
|
+
# georss gml representation
|
218
218
|
def georss_gml_representation(options) #:nodoc:
|
219
219
|
georss_ns = options[:georss_ns] || "georss"
|
220
220
|
gml_ns = options[:gml_ns] || "gml"
|
221
|
-
|
222
|
-
|
223
|
-
|
221
|
+
out = "<#{georss_ns}:where>\n<#{gml_ns}:Point>\n<#{gml_ns}:pos>"
|
222
|
+
out += "#{y} #{x}"
|
223
|
+
out += "</#{gml_ns}:pos>\n</#{gml_ns}:Point>\n</#{georss_ns}:where>\n"
|
224
224
|
end
|
225
225
|
|
226
|
-
#outputs the geometry in kml format : options are <tt>:id</tt>, <tt>:tesselate</tt>, <tt>:extrude</tt>,
|
227
|
-
|
228
|
-
#it won't be used by GE anyway: clampToGround is the default)
|
226
|
+
# outputs the geometry in kml format : options are <tt>:id</tt>, <tt>:tesselate</tt>, <tt>:extrude</tt>,
|
227
|
+
# <tt>:altitude_mode</tt>. If the altitude_mode option is not present, the Z (if present) will not be output (since
|
228
|
+
# it won't be used by GE anyway: clampToGround is the default)
|
229
229
|
def kml_representation(options = {}) #:nodoc:
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
end
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
230
|
+
out = "<Point#{options[:id_attr]}>\n"
|
231
|
+
out += options[:geom_data] if options[:geom_data]
|
232
|
+
out += "<coordinates>#{x},#{y}"
|
233
|
+
out += ",#{options[:fixed_z] || z ||0}" if options[:allow_z]
|
234
|
+
out += "</coordinates>\n"
|
235
|
+
out += "</Point>\n"
|
236
|
+
end
|
237
|
+
|
238
|
+
def html_representation(options = {})
|
239
|
+
options[:coord] = true if options[:coord].nil?
|
240
|
+
out = "<span class='geo'>"
|
241
|
+
out += "<abbr class='latitude' title='#{x}'>#{as_lat(options)}</abbr>"
|
242
|
+
out += "<abbr class='longitude' title='#{y}'>#{as_long(options)}</abbr>"
|
243
|
+
out += "</span>"
|
244
|
+
end
|
245
|
+
|
246
|
+
# Human representation of the geom, don't use directly, use:
|
247
|
+
# #as_lat, #as_long, #as_latlong
|
248
|
+
def human_representation(options = { }, g = { :x => x, :y => y })
|
249
|
+
g.map do |k, v|
|
250
|
+
deg = v.to_i.abs
|
251
|
+
min = (60 * (v.abs - deg)).to_i
|
252
|
+
labs = (v * 1000000).abs / 1000000
|
246
253
|
sec = ((((labs - labs.to_i) * 60) - ((labs - labs.to_i) * 60).to_i) * 100000) * 60 / 100000
|
247
|
-
str =
|
248
|
-
if
|
254
|
+
str = options[:full] ? "%.i°%.2i′%05.2f″" : "%.i°%.2i′%02.0f″"
|
255
|
+
if options[:coord]
|
249
256
|
out = str % [deg,min,sec]
|
250
|
-
|
251
|
-
out += l > 0 ? "N" : "S"
|
252
|
-
else
|
253
|
-
out += l > 0 ? "E" : "W"
|
254
|
-
end
|
255
|
-
val << out
|
257
|
+
out += k == :x ? v > 0 ? "N" : "S" : v > 0 ? "E" : "W"
|
256
258
|
else
|
257
|
-
|
259
|
+
str % [v.to_i, min, sec]
|
258
260
|
end
|
259
261
|
end
|
260
|
-
val.join(", ")
|
261
262
|
end
|
262
263
|
|
264
|
+
# Outputs the geometry coordinate in human format:
|
265
|
+
# 47°52′48″N
|
266
|
+
def as_lat(options = {})
|
267
|
+
human_representation(options, { x: x }).join
|
268
|
+
end
|
269
|
+
|
270
|
+
# Outputs the geometry coordinate in human format:
|
271
|
+
# -20°06′00W″
|
272
|
+
def as_long(options = {})
|
273
|
+
human_representation(options, { y: y }).join
|
274
|
+
end
|
275
|
+
alias :as_lng :as_long
|
276
|
+
|
277
|
+
# Outputs the geometry in coordinates format:
|
278
|
+
# 47°52′48″, -20°06′00″
|
279
|
+
def as_latlong(options = {})
|
280
|
+
human_representation(options).join(", ")
|
281
|
+
end
|
282
|
+
alias :as_ll :as_latlong
|
283
|
+
|
263
284
|
# Polar stuff
|
264
285
|
#
|
265
286
|
# http://www.engineeringtoolbox.com/converting-cartesian-polar-coordinates-d_1347.html
|
data/lib/geo_ruby/version.rb
CHANGED
data/lib/georuby.rb
ADDED
@@ -151,7 +151,7 @@ describe GeoRuby::GeorssParser do
|
|
151
151
|
geom.should == e
|
152
152
|
end
|
153
153
|
|
154
|
-
it "
|
154
|
+
it "reads KML" do
|
155
155
|
g = GeoRuby::SimpleFeatures::Geometry.from_kml("<Point><coordinates>45,12,25</coordinates></Point>")
|
156
156
|
g.should be_a GeoRuby::SimpleFeatures::Point
|
157
157
|
g.should == GeoRuby::SimpleFeatures::Point.from_x_y_z('45','12','25')
|
@@ -208,19 +208,19 @@ describe GeoRuby::GeorssParser do
|
|
208
208
|
g.length.should eql(3)
|
209
209
|
end
|
210
210
|
|
211
|
-
it "
|
211
|
+
it "does not raise type error if point geom data not provided" do
|
212
212
|
point = GeoRuby::SimpleFeatures::Point.from_coordinates([1.6,2.8],123)
|
213
|
-
lambda { point.kml_representation }.should_not raise_error
|
213
|
+
lambda { point.kml_representation }.should_not raise_error
|
214
214
|
end
|
215
215
|
|
216
|
-
it "
|
216
|
+
it "does not raise type error if polygon geom data not provided" do
|
217
217
|
polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256)
|
218
|
-
lambda { polygon.kml_representation }.should_not raise_error
|
218
|
+
lambda { polygon.kml_representation }.should_not raise_error
|
219
219
|
end
|
220
220
|
|
221
|
-
it "
|
221
|
+
it "does not raise type error if linestring geom data not provided" do
|
222
222
|
ls = GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)
|
223
|
-
lambda { ls.kml_representation }.should_not raise_error
|
223
|
+
lambda { ls.kml_representation }.should_not raise_error
|
224
224
|
end
|
225
225
|
|
226
226
|
end
|
data/spec/geo_ruby/kml_spec.rb
CHANGED
@@ -6,9 +6,8 @@ describe GeoRuby::KmlParser do
|
|
6
6
|
LINESTRING = "<LineString><coordinates>-122.365662,37.826988 -122.365202,37.826302 -122.364581,37.82655 -122.365038,37.827237</coordinates></LineString>"
|
7
7
|
LINEARRING = "<LinearRing><coordinates>-122.365662,37.826988 -122.365202,37.826302 -122.364581,37.82655 -122.365038,37.827237 -122.365662,37.826988</coordinates></LinearRing>"
|
8
8
|
POLYGON = "<Polygon><outerBoundaryIs><LinearRing><coordinates>-82.5961385808407,34.0134202383713 -82.6029437979289,34.0346366848087 -82.6603553035687,34.1083560439036 -82.7357807829899,34.1697961502507 -82.7425935601244,34.2055536194311 -82.3145921793097,34.4812209701586 -82.2758648198483,34.4347213073308 -82.2405017851073,34.4067761024174 -82.3327002190662,34.3417863447576 -82.2910826671599,34.2708004396966 -82.2497468801283,34.2261551348023 -82.2370438982521,34.1709424545969 -82.2569955519648,34.1119142196088 -82.3237086862075,34.0601294413679 -82.368425596693,34.0533120146082 -82.4455985300521,34.0562556252352 -82.4806178108032,34.0759686807282 -82.5334224196077,34.0620944842448 -82.5961385808407,34.0134202383713</coordinates></LinearRing></outerBoundaryIs></Polygon>"
|
9
|
-
COMPLEX_POLYGON = "<Polygon><outerBoundaryIs><LinearRing><coordinates>-122.366278,37.818844 -122.365248,37.819267 -122.
|
9
|
+
COMPLEX_POLYGON = "<Polygon><outerBoundaryIs><LinearRing><coordinates>-122.366278,37.818844 -122.365248,37.819267 -122.36564,37.819861 -122.366669,37.819429 -122.366278,37.818844</coordinates></LinearRing></outerBoundaryIs><innerBoundaryIs><LinearRing><coordinates>-122.366212,37.818977 -122.365424,37.819294 -122.365704,37.819731 -122.366488,37.819402 -122.366212,37.818977</coordinates></LinearRing></innerBoundaryIs></Polygon>"
|
10
10
|
MULTIGEOMETRY = "<MultiGeometry><Polygon><outerBoundaryIs><LinearRing><coordinates>-82.5961385808407,34.0134202383713 -82.6029437979289,34.0346366848087 -82.6603553035687,34.1083560439036 -82.7357807829899,34.1697961502507 -82.7425935601244,34.2055536194311 -82.3145921793097,34.4812209701586 -82.2758648198483,34.4347213073308 -82.2405017851073,34.4067761024174 -82.3327002190662,34.3417863447576 -82.2910826671599,34.2708004396966 -82.2497468801283,34.2261551348023 -82.2370438982521,34.1709424545969 -82.2569955519648,34.1119142196088 -82.3237086862075,34.0601294413679 -82.368425596693,34.0533120146082 -82.4455985300521,34.0562556252352 -82.4806178108032,34.0759686807282 -82.5334224196077,34.0620944842448 -82.5961385808407,34.0134202383713</coordinates></LinearRing></outerBoundaryIs></Polygon><Point><coordinates>-82.4898187291883,34.2473206042649</coordinates></Point></MultiGeometry>"
|
11
|
-
|
12
11
|
POINT3D = "<Point><coordinates>-82.4898187291883,34.2473206042649,5</coordinates></Point>"
|
13
12
|
LINESTRING3D = "<LineString><coordinates>-122.365662,37.826988,1 -122.365202,37.826302,2 -122.364581,37.82655,3 -122.365038,37.827237,4</coordinates></LineString>"
|
14
13
|
end
|
@@ -76,4 +75,24 @@ describe GeoRuby::KmlParser do
|
|
76
75
|
g.with_z.should eql(true)
|
77
76
|
# g.as_kml(:altitude_mode => "clampToGround").gsub(/\n/,'').should eql(LINESTRING3D)
|
78
77
|
end
|
79
|
-
|
78
|
+
|
79
|
+
it "should yield a geometries with functional bounding boxes" do
|
80
|
+
[LINESTRING, LINEARRING, POLYGON, COMPLEX_POLYGON, MULTIGEOMETRY, LINESTRING3D].each do |kml|
|
81
|
+
@kml_parser.parse(kml)
|
82
|
+
g = @factory.geometry
|
83
|
+
lambda {
|
84
|
+
g.bounding_box
|
85
|
+
}.should_not raise_error
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should yield a geometries with functional envelopes" do
|
90
|
+
[LINESTRING, LINEARRING, POLYGON, COMPLEX_POLYGON, MULTIGEOMETRY, LINESTRING3D].each do |kml|
|
91
|
+
@kml_parser.parse(kml)
|
92
|
+
g = @factory.geometry
|
93
|
+
lambda {
|
94
|
+
g.envelope.center
|
95
|
+
}.should_not raise_error
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# -*- coding: binary -*-
|
2
|
+
|
1
3
|
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
4
|
|
3
5
|
describe GeoRuby::SimpleFeatures::Geometry do
|
@@ -22,8 +24,14 @@ describe GeoRuby::SimpleFeatures::Geometry do
|
|
22
24
|
end
|
23
25
|
|
24
26
|
it "should output as_ewkb" do
|
25
|
-
subject.stub
|
26
|
-
subject.stub
|
27
|
+
subject.stub(:binary_geometry_type).and_return(1)
|
28
|
+
subject.stub(:binary_representation).and_return(1)
|
27
29
|
subject.as_ewkb.should eql("\001\001\000\000 \346\020\000\000\001")
|
28
30
|
end
|
31
|
+
|
32
|
+
it "should output as_ewkb (utf8 issue)" do
|
33
|
+
subject.stub(:binary_geometry_type).and_return(1)
|
34
|
+
subject.stub(:binary_representation).and_return(1)
|
35
|
+
subject.as_ewkb.should eql("\x01\x01\x00\x00 \xE6\x10\x00\x00\x01")
|
36
|
+
end
|
29
37
|
end
|
@@ -7,7 +7,7 @@ module LineSpecHelper
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def mock_point(x=1,y=2)
|
10
|
-
|
10
|
+
double(GeoRuby::SimpleFeatures::Point, :x => x, :y => y, :text_representation => "#{x} #{y}")
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -17,7 +17,7 @@ describe GeoRuby::SimpleFeatures::LineString do
|
|
17
17
|
|
18
18
|
describe "Instance Methods" do
|
19
19
|
|
20
|
-
let(:line) { GeoRuby::SimpleFeatures::LineString.from_points([
|
20
|
+
let(:line) { GeoRuby::SimpleFeatures::LineString.from_points([double(GeoRuby::SimpleFeatures::Point)]) }
|
21
21
|
|
22
22
|
it "should instantiate" do
|
23
23
|
violated unless line
|
@@ -203,9 +203,9 @@ describe GeoRuby::SimpleFeatures::LineString do
|
|
203
203
|
|
204
204
|
describe "> Distances..." do
|
205
205
|
before(:each) do
|
206
|
-
@p1 =
|
207
|
-
@p2 =
|
208
|
-
@p3 =
|
206
|
+
@p1 = double(GeoRuby::SimpleFeatures::Point)
|
207
|
+
@p2 = double(GeoRuby::SimpleFeatures::Point)
|
208
|
+
@p3 = double(GeoRuby::SimpleFeatures::Point)
|
209
209
|
@line = GeoRuby::SimpleFeatures::LineString.from_points([@p1,@p2,@p3])
|
210
210
|
end
|
211
211
|
|
@@ -13,6 +13,10 @@ describe GeoRuby::SimpleFeatures::Point do
|
|
13
13
|
point.should be_a_point
|
14
14
|
end
|
15
15
|
|
16
|
+
it "should have a text geometry type" do
|
17
|
+
point.text_geometry_type.should eq("POINT")
|
18
|
+
end
|
19
|
+
|
16
20
|
it "should have a very nice matcher" do
|
17
21
|
point.should be_a_point(0.0, 0.0)
|
18
22
|
end
|
@@ -98,6 +102,11 @@ describe GeoRuby::SimpleFeatures::Point do
|
|
98
102
|
point.z.should eql(-30)
|
99
103
|
end
|
100
104
|
|
105
|
+
it "should store correctly a 3d point" do
|
106
|
+
point = GeoRuby::SimpleFeatures::Point.from_x_y_z(-10,-20,-30)
|
107
|
+
point.to_coordinates.should eq([-10, -20, -30])
|
108
|
+
end
|
109
|
+
|
101
110
|
it "should instantiate a 3d(m) point" do
|
102
111
|
point = GeoRuby::SimpleFeatures::Point.from_x_y_m(10,20,30)
|
103
112
|
point.x.should eql(10)
|
@@ -115,6 +124,12 @@ describe GeoRuby::SimpleFeatures::Point do
|
|
115
124
|
point.srid.should eql(123)
|
116
125
|
end
|
117
126
|
|
127
|
+
it "should store correctly a 4d point" do
|
128
|
+
point = GeoRuby::SimpleFeatures::Point.from_x_y_z_m(-10,-20,-30, 1)
|
129
|
+
point.m.should eql(1)
|
130
|
+
point.to_coordinates.should eq([-10, -20, -30])
|
131
|
+
end
|
132
|
+
|
118
133
|
it "should instantiate a point from polar coordinates" do
|
119
134
|
point = GeoRuby::SimpleFeatures::Point.from_r_t(1.4142,45)
|
120
135
|
point.y.should be_within(0.1).of(1)
|
@@ -188,22 +203,46 @@ describe GeoRuby::SimpleFeatures::Point do
|
|
188
203
|
GeoRuby::SimpleFeatures::Point.from_x_y(47.88, -20.1).as_latlong.should eql("47°52′48″, -20°06′00″")
|
189
204
|
end
|
190
205
|
|
191
|
-
it "should print out nicely" do
|
206
|
+
it "should print out nicely latlong" do
|
192
207
|
GeoRuby::SimpleFeatures::Point.from_x_y(-20.78, 20.78).as_latlong(:full => true).should eql("-20°46′48.00″, 20°46′48.00″")
|
193
208
|
end
|
194
209
|
|
195
|
-
it "should print out nicely" do
|
210
|
+
it "should print out nicely latlong" do
|
196
211
|
GeoRuby::SimpleFeatures::Point.from_x_y(47.11, -20.2).as_latlong(:full => true).should eql("47°06′36.00″, -20°11′60.00″")
|
197
212
|
end
|
198
213
|
|
199
|
-
it "should print out nicely" do
|
214
|
+
it "should print out nicely latlong" do
|
200
215
|
GeoRuby::SimpleFeatures::Point.from_x_y(47.11, -20.2).as_latlong(:coord => true).should eql("47°06′36″N, 20°11′60″W")
|
201
216
|
end
|
202
217
|
|
203
|
-
it "should print out nicely" do
|
218
|
+
it "should print out nicely latlong" do
|
204
219
|
GeoRuby::SimpleFeatures::Point.from_x_y(-47.11, 20.2).as_latlong(:full => true,:coord => true).should eql("47°06′36.00″S, 20°11′60.00″E")
|
205
220
|
end
|
206
221
|
|
222
|
+
it "should print out nicely lat" do
|
223
|
+
GeoRuby::SimpleFeatures::Point.from_x_y(-47.11, 20.2).as_lat.should eql("-47°06′36″")
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should print out nicely lat with opts" do
|
227
|
+
GeoRuby::SimpleFeatures::Point.from_x_y(-47.11, 20.2).as_lat(:full => true).should eql("-47°06′36.00″")
|
228
|
+
end
|
229
|
+
|
230
|
+
it "should print out nicely lat with opts" do
|
231
|
+
GeoRuby::SimpleFeatures::Point.from_x_y(-47.11, 20.2).as_lat(:full => true,:coord => true).should eql("47°06′36.00″S")
|
232
|
+
end
|
233
|
+
|
234
|
+
it "should print out nicely long" do
|
235
|
+
GeoRuby::SimpleFeatures::Point.from_x_y(-47.11, 20.2).as_long.should eql("20°11′60″")
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should print out nicely long with opts" do
|
239
|
+
GeoRuby::SimpleFeatures::Point.from_x_y(-47.11, 20.2).as_long(:full => true).should eql("20°11′60.00″")
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should print out nicely long with opts" do
|
243
|
+
GeoRuby::SimpleFeatures::Point.from_x_y(-47.11, 20.2).as_long(:full => true,:coord => true).should eql("20°11′60.00″E")
|
244
|
+
end
|
245
|
+
|
207
246
|
end
|
208
247
|
|
209
248
|
describe " > Distance & Bearing" do
|
@@ -333,6 +372,18 @@ describe GeoRuby::SimpleFeatures::Point do
|
|
333
372
|
point.kml_representation.should eql("<Point>\n<coordinates>-11.2431,32.3141</coordinates>\n</Point>\n")
|
334
373
|
end
|
335
374
|
|
375
|
+
it "should print as html too" do
|
376
|
+
point.html_representation.should eql("<span class='geo'><abbr class='latitude' title='-11.2431'>11°14′35″S</abbr><abbr class='longitude' title='32.3141'>32°18′51″E</abbr></span>")
|
377
|
+
end
|
378
|
+
|
379
|
+
it "should print as html too with opts" do
|
380
|
+
point.html_representation(coord: false).should eql("<span class='geo'><abbr class='latitude' title='-11.2431'>-11°14′35″</abbr><abbr class='longitude' title='32.3141'>32°18′51″</abbr></span>")
|
381
|
+
end
|
382
|
+
|
383
|
+
it "should print as html too with opts" do
|
384
|
+
point.html_representation(full: true).should eql("<span class='geo'><abbr class='latitude' title='-11.2431'>11°14′35.16″S</abbr><abbr class='longitude' title='32.3141'>32°18′50.76″E</abbr></span>")
|
385
|
+
end
|
386
|
+
|
336
387
|
it "should print as georss" do
|
337
388
|
point.georss_simple_representation(:georss_ns => 'hey').should eql("<hey:point>32.3141 -11.2431</hey:point>\n")
|
338
389
|
end
|
@@ -349,6 +400,16 @@ describe GeoRuby::SimpleFeatures::Point do
|
|
349
400
|
point.theta_rad.should be_within(0.0001).of(5.04722003626982)
|
350
401
|
end
|
351
402
|
|
403
|
+
it "should print theta when x is zero y > 0" do
|
404
|
+
pt = GeoRuby::SimpleFeatures::Point.from_x_y(0.0, 32.3141)
|
405
|
+
pt.theta_rad.should be_within(0.0001).of(1.5707963267948966)
|
406
|
+
end
|
407
|
+
|
408
|
+
it "should print theta when x is zero y < 0" do
|
409
|
+
pt = GeoRuby::SimpleFeatures::Point.from_x_y(0.0, -32.3141)
|
410
|
+
pt.theta_rad.should be_within(0.0001).of(4.71238898038469)
|
411
|
+
end
|
412
|
+
|
352
413
|
it "should output as polar" do
|
353
414
|
point.as_polar.should be_instance_of(Array)
|
354
415
|
point.should have(2).as_polar #.length.should eql(2)
|
data/spec/spec_helper.rb
CHANGED
@@ -15,6 +15,11 @@ require 'geo_ruby/geojson'
|
|
15
15
|
require 'geo_ruby/georss'
|
16
16
|
require 'geo_ruby/kml'
|
17
17
|
|
18
|
+
if ENV["CI"]
|
19
|
+
require 'coveralls'
|
20
|
+
Coveralls.wear!
|
21
|
+
end
|
22
|
+
|
18
23
|
module GeorubyMatchers
|
19
24
|
|
20
25
|
class BeGeometric
|
@@ -63,4 +68,3 @@ end
|
|
63
68
|
RSpec.configure do |config|
|
64
69
|
config.include GeorubyMatchers
|
65
70
|
end
|
66
|
-
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: georuby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
5
|
-
prerelease:
|
4
|
+
version: 2.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Guilhem Vellut
|
@@ -12,88 +11,8 @@ authors:
|
|
12
11
|
autorequire:
|
13
12
|
bindir: bin
|
14
13
|
cert_chain: []
|
15
|
-
date:
|
16
|
-
dependencies:
|
17
|
-
- !ruby/object:Gem::Dependency
|
18
|
-
name: nokogiri
|
19
|
-
requirement: !ruby/object:Gem::Requirement
|
20
|
-
none: false
|
21
|
-
requirements:
|
22
|
-
- - ~>
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: 1.5.5
|
25
|
-
type: :development
|
26
|
-
prerelease: false
|
27
|
-
version_requirements: !ruby/object:Gem::Requirement
|
28
|
-
none: false
|
29
|
-
requirements:
|
30
|
-
- - ~>
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 1.5.5
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: dbf
|
35
|
-
requirement: !ruby/object:Gem::Requirement
|
36
|
-
none: false
|
37
|
-
requirements:
|
38
|
-
- - ! '>='
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 1.7.0
|
41
|
-
type: :development
|
42
|
-
prerelease: false
|
43
|
-
version_requirements: !ruby/object:Gem::Requirement
|
44
|
-
none: false
|
45
|
-
requirements:
|
46
|
-
- - ! '>='
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
version: 1.7.0
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: json
|
51
|
-
requirement: !ruby/object:Gem::Requirement
|
52
|
-
none: false
|
53
|
-
requirements:
|
54
|
-
- - ! '>='
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: 1.6.5
|
57
|
-
type: :development
|
58
|
-
prerelease: false
|
59
|
-
version_requirements: !ruby/object:Gem::Requirement
|
60
|
-
none: false
|
61
|
-
requirements:
|
62
|
-
- - ! '>='
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
version: 1.6.5
|
65
|
-
- !ruby/object:Gem::Dependency
|
66
|
-
name: rspec
|
67
|
-
requirement: !ruby/object:Gem::Requirement
|
68
|
-
none: false
|
69
|
-
requirements:
|
70
|
-
- - ! '>='
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
version: 2.3.0
|
73
|
-
type: :development
|
74
|
-
prerelease: false
|
75
|
-
version_requirements: !ruby/object:Gem::Requirement
|
76
|
-
none: false
|
77
|
-
requirements:
|
78
|
-
- - ! '>='
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
version: 2.3.0
|
81
|
-
- !ruby/object:Gem::Dependency
|
82
|
-
name: rake
|
83
|
-
requirement: !ruby/object:Gem::Requirement
|
84
|
-
none: false
|
85
|
-
requirements:
|
86
|
-
- - ! '>='
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version: '0'
|
89
|
-
type: :development
|
90
|
-
prerelease: false
|
91
|
-
version_requirements: !ruby/object:Gem::Requirement
|
92
|
-
none: false
|
93
|
-
requirements:
|
94
|
-
- - ! '>='
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
14
|
+
date: 2013-11-06 00:00:00.000000000 Z
|
15
|
+
dependencies: []
|
97
16
|
description: GeoRuby provides geometric data types from the OGC 'Simple Features'
|
98
17
|
specification.
|
99
18
|
email: x@nofxx.com
|
@@ -102,6 +21,7 @@ extensions: []
|
|
102
21
|
extra_rdoc_files: []
|
103
22
|
files:
|
104
23
|
- lib/geo_ruby.rb
|
24
|
+
- lib/georuby.rb
|
105
25
|
- lib/geo_ruby/geojson.rb
|
106
26
|
- lib/geo_ruby/gpx4r/gpx.rb
|
107
27
|
- lib/geo_ruby/gpx.rb
|
@@ -171,36 +91,30 @@ files:
|
|
171
91
|
- spec/geo_ruby/simple_features/linear_ring_spec.rb
|
172
92
|
- spec/geo_ruby/georss_spec.rb
|
173
93
|
- spec/geo_ruby/shp4r/shp_spec.rb
|
174
|
-
- README.
|
94
|
+
- README.md
|
175
95
|
- Rakefile
|
176
96
|
homepage: http://github.com/nofxx/georuby
|
177
|
-
licenses:
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata: {}
|
178
100
|
post_install_message:
|
179
101
|
rdoc_options: []
|
180
102
|
require_paths:
|
181
103
|
- lib
|
182
104
|
required_ruby_version: !ruby/object:Gem::Requirement
|
183
|
-
none: false
|
184
105
|
requirements:
|
185
|
-
- -
|
106
|
+
- - '>='
|
186
107
|
- !ruby/object:Gem::Version
|
187
108
|
version: '0'
|
188
|
-
segments:
|
189
|
-
- 0
|
190
|
-
hash: 4371088518288572487
|
191
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
192
|
-
none: false
|
193
110
|
requirements:
|
194
|
-
- -
|
111
|
+
- - '>='
|
195
112
|
- !ruby/object:Gem::Version
|
196
113
|
version: '0'
|
197
|
-
segments:
|
198
|
-
- 0
|
199
|
-
hash: 4371088518288572487
|
200
114
|
requirements: []
|
201
115
|
rubyforge_project:
|
202
|
-
rubygems_version:
|
116
|
+
rubygems_version: 2.0.7
|
203
117
|
signing_key:
|
204
|
-
specification_version:
|
118
|
+
specification_version: 4
|
205
119
|
summary: Ruby data holder for OGC Simple Features
|
206
120
|
test_files: []
|