geos-extensions 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/geos-extensions.gemspec +5 -2
- data/lib/geos/active_record_extensions/spatial_columns.rb +0 -5
- data/lib/geos/extensions/version.rb +1 -1
- data/lib/geos_extensions.rb +42 -22
- data/test/reader_tests.rb +33 -0
- data/test/test_helper.rb +1 -1
- data/test/writer_tests.rb +20 -0
- metadata +2 -18
data/geos-extensions.gemspec
CHANGED
@@ -21,9 +21,12 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.require_paths = ["lib"]
|
22
22
|
|
23
23
|
s.add_dependency("activerecord", [">= 2.3"])
|
24
|
-
s.add_dependency("ffi", ["~> 1.0.0"])
|
25
24
|
s.add_dependency("ffi-geos", ["~> 0.0.4"])
|
26
|
-
|
25
|
+
if RUBY_PLATFORM == "java"
|
26
|
+
s.add_dependency("activerecord-jdbcpostgresql-adapter")
|
27
|
+
else
|
28
|
+
s.add_dependency("pg")
|
29
|
+
end
|
27
30
|
s.add_dependency("rdoc")
|
28
31
|
s.add_dependency("rake", ["~> 0.9"])
|
29
32
|
end
|
@@ -162,11 +162,6 @@ module Geos
|
|
162
162
|
# You can specify which spatial columns you want to apply
|
163
163
|
# these accessors using the :only and :except options.
|
164
164
|
def create_spatial_column_accessors!(options = nil)
|
165
|
-
options = {
|
166
|
-
:geometry_columns => true,
|
167
|
-
:geography_columns => true
|
168
|
-
}
|
169
|
-
|
170
165
|
create_these = []
|
171
166
|
|
172
167
|
if options.nil?
|
data/lib/geos_extensions.rb
CHANGED
@@ -63,13 +63,17 @@ module Geos
|
|
63
63
|
|
64
64
|
# Returns some kind of Geometry object from the given WKB in
|
65
65
|
# binary.
|
66
|
-
def self.from_wkb_bin(wkb)
|
67
|
-
self.wkb_reader_singleton.read(wkb)
|
66
|
+
def self.from_wkb_bin(wkb, options = {})
|
67
|
+
geom = self.wkb_reader_singleton.read(wkb)
|
68
|
+
geom.srid = options[:srid].to_i if options[:srid]
|
69
|
+
geom
|
68
70
|
end
|
69
71
|
|
70
72
|
# Returns some kind of Geometry object from the given WKB in hex.
|
71
|
-
def self.from_wkb(wkb)
|
72
|
-
self.wkb_reader_singleton.read_hex(wkb)
|
73
|
+
def self.from_wkb(wkb, options = {})
|
74
|
+
geom = self.wkb_reader_singleton.read_hex(wkb)
|
75
|
+
geom.srid = options[:srid].to_i if options[:srid]
|
76
|
+
geom
|
73
77
|
end
|
74
78
|
|
75
79
|
# Tries its best to return a Geometry object.
|
@@ -78,15 +82,15 @@ module Geos
|
|
78
82
|
when Geos::Geometry
|
79
83
|
geom
|
80
84
|
when REGEXP_WKT
|
81
|
-
Geos.from_wkt(geom)
|
85
|
+
Geos.from_wkt(geom, options)
|
82
86
|
when REGEXP_WKB_HEX
|
83
|
-
Geos.from_wkb(geom)
|
87
|
+
Geos.from_wkb(geom, options)
|
84
88
|
when REGEXP_G_LAT_LNG_BOUNDS, REGEXP_G_LAT_LNG
|
85
89
|
Geos.from_g_lat_lng(geom, options)
|
86
90
|
when REGEXP_BOX2D
|
87
91
|
Geos.from_box2d(geom)
|
88
92
|
when String
|
89
|
-
Geos.from_wkb(geom.unpack('H*').first.upcase)
|
93
|
+
Geos.from_wkb(geom.unpack('H*').first.upcase, options)
|
90
94
|
when nil
|
91
95
|
nil
|
92
96
|
else
|
@@ -102,10 +106,10 @@ module Geos
|
|
102
106
|
|
103
107
|
# Returns some kind of Geometry object from the given WKT. This method
|
104
108
|
# will also accept PostGIS-style EWKT and its various enhancements.
|
105
|
-
def self.from_wkt(wkt)
|
109
|
+
def self.from_wkt(wkt, options = {})
|
106
110
|
srid, raw_wkt = wkt.scan(REGEXP_WKT).first
|
107
111
|
geom = self.wkt_reader_singleton.read(raw_wkt.upcase)
|
108
|
-
geom.srid = srid.to_i if srid
|
112
|
+
geom.srid = (options[:srid] || srid).to_i if options[:srid] || srid
|
109
113
|
geom
|
110
114
|
end
|
111
115
|
|
@@ -236,7 +240,17 @@ module Geos
|
|
236
240
|
end
|
237
241
|
|
238
242
|
ret = ''
|
239
|
-
|
243
|
+
|
244
|
+
if options[:include_srid]
|
245
|
+
srid = if options[:srid]
|
246
|
+
options[:srid]
|
247
|
+
else
|
248
|
+
self.srid
|
249
|
+
end
|
250
|
+
|
251
|
+
ret << "SRID=#{srid};"
|
252
|
+
end
|
253
|
+
|
240
254
|
ret << writer.write(self, *args)
|
241
255
|
ret
|
242
256
|
end
|
@@ -454,9 +468,11 @@ module Geos
|
|
454
468
|
|
455
469
|
|
456
470
|
class Point
|
457
|
-
|
458
|
-
|
459
|
-
|
471
|
+
unless method_defined?(:y)
|
472
|
+
# Returns the Y coordinate of the Point.
|
473
|
+
def y
|
474
|
+
self.to_a[1]
|
475
|
+
end
|
460
476
|
end
|
461
477
|
|
462
478
|
%w{
|
@@ -467,9 +483,11 @@ module Geos
|
|
467
483
|
EOF
|
468
484
|
end
|
469
485
|
|
470
|
-
|
471
|
-
|
472
|
-
|
486
|
+
unless method_defined?(:x)
|
487
|
+
# Returns the X coordinate of the Point.
|
488
|
+
def x
|
489
|
+
self.to_a[0]
|
490
|
+
end
|
473
491
|
end
|
474
492
|
|
475
493
|
%w{
|
@@ -480,12 +498,14 @@ module Geos
|
|
480
498
|
EOF
|
481
499
|
end
|
482
500
|
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
self.
|
487
|
-
|
488
|
-
|
501
|
+
unless method_defined?(:z)
|
502
|
+
# Returns the Z coordinate of the Point.
|
503
|
+
def z
|
504
|
+
if self.has_z?
|
505
|
+
self.to_a[2]
|
506
|
+
else
|
507
|
+
nil
|
508
|
+
end
|
489
509
|
end
|
490
510
|
end
|
491
511
|
|
data/test/reader_tests.rb
CHANGED
@@ -13,6 +13,17 @@ class GeosReaderTests < Test::Unit::TestCase
|
|
13
13
|
assert_saneness_of_polygon(polygon)
|
14
14
|
end
|
15
15
|
|
16
|
+
def test_from_wkb_bin_with_srid_option
|
17
|
+
point = Geos.from_wkb_bin(POINT_EWKB_BIN, :srid => 900913)
|
18
|
+
polygon = Geos.from_wkb_bin(POLYGON_EWKB_BIN, :srid => 900913)
|
19
|
+
|
20
|
+
assert_saneness_of_point(point)
|
21
|
+
assert_saneness_of_polygon(polygon)
|
22
|
+
|
23
|
+
assert_equal(900913, point.srid)
|
24
|
+
assert_equal(900913, polygon.srid)
|
25
|
+
end
|
26
|
+
|
16
27
|
def test_from_wkb
|
17
28
|
point = Geos.from_wkb(POINT_WKB)
|
18
29
|
polygon = Geos.from_wkb(POLYGON_WKB)
|
@@ -21,6 +32,17 @@ class GeosReaderTests < Test::Unit::TestCase
|
|
21
32
|
assert_saneness_of_polygon(polygon)
|
22
33
|
end
|
23
34
|
|
35
|
+
def test_from_wkb_with_srid_option
|
36
|
+
point = Geos.from_wkb(POINT_EWKB, :srid => 900913)
|
37
|
+
polygon = Geos.from_wkb(POLYGON_EWKB, :srid => 900913)
|
38
|
+
|
39
|
+
assert_saneness_of_point(point)
|
40
|
+
assert_saneness_of_polygon(polygon)
|
41
|
+
|
42
|
+
assert_equal(900913, point.srid)
|
43
|
+
assert_equal(900913, polygon.srid)
|
44
|
+
end
|
45
|
+
|
24
46
|
def test_from_wkt
|
25
47
|
point = Geos.from_wkt(POINT_WKT)
|
26
48
|
polygon = Geos.from_wkt(POLYGON_WKT)
|
@@ -29,6 +51,17 @@ class GeosReaderTests < Test::Unit::TestCase
|
|
29
51
|
assert_saneness_of_polygon(polygon)
|
30
52
|
end
|
31
53
|
|
54
|
+
def test_from_wkt_with_srid_option
|
55
|
+
point = Geos.from_wkt(POINT_EWKT, :srid => 900913)
|
56
|
+
polygon = Geos.from_wkt(POLYGON_EWKT, :srid => 900913)
|
57
|
+
|
58
|
+
assert_saneness_of_point(point)
|
59
|
+
assert_saneness_of_polygon(polygon)
|
60
|
+
|
61
|
+
assert_equal(900913, point.srid)
|
62
|
+
assert_equal(900913, polygon.srid)
|
63
|
+
end
|
64
|
+
|
32
65
|
def test_from_ewkb_bin
|
33
66
|
point = Geos.from_wkb_bin(POINT_EWKB_BIN)
|
34
67
|
polygon = Geos.from_wkb_bin(POLYGON_EWKB_BIN)
|
data/test/test_helper.rb
CHANGED
@@ -37,7 +37,7 @@ if defined?(Geos::FFIGeos)
|
|
37
37
|
end
|
38
38
|
|
39
39
|
if ENV['TEST_ACTIVERECORD'] || defined?(IRB)
|
40
|
-
ActiveRecord::Base.logger = Logger.new("debug.log")
|
40
|
+
ActiveRecord::Base.logger = Logger.new("debug.log") if ENV['ENABLE_LOGGER']
|
41
41
|
ActiveRecord::Base.configurations = {
|
42
42
|
'arunit' => {}
|
43
43
|
}
|
data/test/writer_tests.rb
CHANGED
@@ -56,6 +56,26 @@ class GeosWriterTests < Test::Unit::TestCase
|
|
56
56
|
assert_in_delta(10.01, lat, 0.000001)
|
57
57
|
end
|
58
58
|
|
59
|
+
def test_to_ewkt_with_srid_option
|
60
|
+
if @point.to_ewkt(:srid => 900913) =~ /^SRID=900913;\s*POINT\s*\((\d+\.\d+)\s*(\d+\.\d+)\)$/
|
61
|
+
lng, lat = $1.to_f, $2.to_f
|
62
|
+
end
|
63
|
+
|
64
|
+
assert_in_delta(10.00, lng, 0.000001)
|
65
|
+
assert_in_delta(10.01, lat, 0.000001)
|
66
|
+
|
67
|
+
assert_equal(4326, @point.srid)
|
68
|
+
|
69
|
+
if @point.to_ewkt(:srid => :default) =~ /^SRID=default;\s*POINT\s*\((\d+\.\d+)\s*(\d+\.\d+)\)$/
|
70
|
+
lng, lat = $1.to_f, $2.to_f
|
71
|
+
end
|
72
|
+
|
73
|
+
assert_in_delta(10.00, lng, 0.000001)
|
74
|
+
assert_in_delta(10.01, lat, 0.000001)
|
75
|
+
|
76
|
+
assert_equal(4326, @point.srid)
|
77
|
+
end
|
78
|
+
|
59
79
|
def test_to_flickr_bbox
|
60
80
|
assert_equal('0.0,0.0,5.0,5.0', @polygon.to_flickr_bbox)
|
61
81
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geos-extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -27,22 +27,6 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '2.3'
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: ffi
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ~>
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: 1.0.0
|
38
|
-
type: :runtime
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 1.0.0
|
46
30
|
- !ruby/object:Gem::Dependency
|
47
31
|
name: ffi-geos
|
48
32
|
requirement: !ruby/object:Gem::Requirement
|