geos-extensions 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/geos-extensions.gemspec +2 -2
- data/lib/active_record_extensions/connection_adapters/postgresql_adapter.rb +2 -0
- data/lib/active_record_extensions/geometry_columns.rb +24 -14
- data/lib/active_record_extensions/geospatial_scopes.rb +1 -1
- data/test/geometry_columns_test.rb +29 -1
- metadata +4 -4
data/Rakefile
CHANGED
data/geos-extensions.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{geos-extensions}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["J Smith"]
|
12
|
-
s.date = %q{2011-03-
|
12
|
+
s.date = %q{2011-03-17}
|
13
13
|
s.description = %q{Extensions for the GEOS library.}
|
14
14
|
s.email = %q{code@zoocasa.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -14,6 +14,8 @@ module ActiveRecord
|
|
14
14
|
class PostgreSQLAdapter < AbstractAdapter
|
15
15
|
# Returns the geometry columns for the table.
|
16
16
|
def geometry_columns(table_name, name = nil)
|
17
|
+
return [] if !table_exists?(table_name)
|
18
|
+
|
17
19
|
columns(table_name, name).select { |c| c.sql_type == 'geometry' }.collect do |c|
|
18
20
|
res = execute(
|
19
21
|
"SELECT * FROM geometry_columns WHERE f_table_name = #{quote(table_name)} AND f_geometry_column = #{quote(c.name)}",
|
@@ -41,6 +41,12 @@ module Geos
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
class CantConvertSRID < ::ActiveRecord::ActiveRecordError
|
45
|
+
def initialize(table_name, column, from_srid, to_srid)
|
46
|
+
super("Couldn't convert SRID for #{table_name}.#{column} from #{from_srid} to #{to_srid}")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
44
50
|
def self.included(base) #:nodoc:
|
45
51
|
base.extend(ClassMethods)
|
46
52
|
base.send(:include, Geos::ActiveRecord::GeospatialScopes)
|
@@ -122,26 +128,30 @@ module Geos
|
|
122
128
|
create_these.each do |k|
|
123
129
|
src, line = <<-EOF, __LINE__ + 1
|
124
130
|
def #{k.name}=(geom)
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
Geos.from_wkt(geom)
|
130
|
-
else
|
131
|
-
raise SRIDNotFound.new(self.class.table_name, #{k.name.inspect})
|
132
|
-
end
|
133
|
-
else
|
134
|
-
Geos.read(geom)
|
131
|
+
column_srid = self.class.srid_for(#{k.name.inspect})
|
132
|
+
|
133
|
+
if geom =~ /^SRID=default;/i
|
134
|
+
geom = geom.sub(/default/i, column_srid.to_s)
|
135
135
|
end
|
136
136
|
|
137
|
-
|
138
|
-
|
139
|
-
|
137
|
+
geos = Geos.read(geom)
|
138
|
+
|
139
|
+
geom_srid = if geos.srid == 0
|
140
|
+
-1
|
141
|
+
else
|
142
|
+
geos.srid
|
143
|
+
end
|
144
|
+
|
145
|
+
if column_srid != geom_srid
|
146
|
+
if column_srid == -1 || geom_srid == -1
|
147
|
+
geos.srid = column_srid
|
140
148
|
else
|
141
|
-
|
149
|
+
raise CantConvertSRID.new(self.class.table_name, #{k.name.inspect}, geom_srid, column_srid)
|
142
150
|
end
|
143
151
|
end
|
144
152
|
|
153
|
+
self['#{k.name}'] = geos.to_ewkb
|
154
|
+
|
145
155
|
GEOMETRY_COLUMN_OUTPUT_FORMATS.each do |f|
|
146
156
|
instance_variable_set("@#{k.name}_\#{f}", nil)
|
147
157
|
end
|
@@ -87,7 +87,7 @@ module Geos
|
|
87
87
|
column_srid = self.srid_for(options[:column])
|
88
88
|
|
89
89
|
geom = if args.first.is_a?(String) && args.first =~ /^SRID=default;/
|
90
|
-
args.first.sub(/default/,
|
90
|
+
args.first.sub(/default/, column_srid.to_s)
|
91
91
|
else
|
92
92
|
args.first
|
93
93
|
end
|
@@ -126,6 +126,35 @@ if ENV['TEST_ACTIVERECORD']
|
|
126
126
|
assert_saneness_of_point(foo.the_other_geom_geos)
|
127
127
|
end
|
128
128
|
|
129
|
+
def test_create_with_no_srid_converting_to_4326
|
130
|
+
foo = Foo.create!(
|
131
|
+
:name => 'test_ewkt_create_with_no_srid_converting_to_4326',
|
132
|
+
:the_other_geom => POINT_WKT
|
133
|
+
)
|
134
|
+
|
135
|
+
foo.reload
|
136
|
+
assert_saneness_of_point(foo.the_other_geom_geos)
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_create_with_no_srid_converting_to_minus_1
|
140
|
+
foo = Foo.create!(
|
141
|
+
:name => 'test_ewkt_create_with_no_srid_converting_to_minus_1',
|
142
|
+
:the_geom => POINT_EWKT
|
143
|
+
)
|
144
|
+
|
145
|
+
foo.reload
|
146
|
+
assert_saneness_of_point(foo.the_geom_geos)
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_create_with_converting_from_900913_to_4326
|
150
|
+
assert_raise(Geos::ActiveRecord::GeometryColumns::CantConvertSRID) do
|
151
|
+
foo = Foo.create!(
|
152
|
+
:name => 'test_create_with_converting_from_900913_to_4326',
|
153
|
+
:the_other_geom => "SRID=900913; #{POINT_WKT}"
|
154
|
+
)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
129
158
|
def test_ewkt_create_with_srid_default
|
130
159
|
foo = Foo.create!(
|
131
160
|
:name => 'test_ewkt_create_with_srid_default',
|
@@ -134,7 +163,6 @@ if ENV['TEST_ACTIVERECORD']
|
|
134
163
|
|
135
164
|
foo.reload
|
136
165
|
assert_saneness_of_point(foo.the_other_geom_geos)
|
137
|
-
foo.the_other_geom_geos
|
138
166
|
end
|
139
167
|
|
140
168
|
def test_ewkb_create
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geos-extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- J Smith
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-03-
|
18
|
+
date: 2011-03-17 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|