activerecord-postgis-adapter 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +7 -1
- data/README.rdoc +24 -12
- data/Version +1 -1
- data/lib/active_record/connection_adapters/postgis_adapter/main_adapter.rb +27 -20
- data/lib/active_record/connection_adapters/postgis_adapter/spatial_column.rb +46 -13
- data/lib/active_record/connection_adapters/postgis_adapter/spatial_table_definition.rb +16 -8
- data/test/tc_basic.rb +23 -0
- data/test/tc_ddl.rb +69 -5
- metadata +4 -4
data/History.rdoc
CHANGED
@@ -1,6 +1,12 @@
|
|
1
|
+
=== 0.3.3 / 2011-02-28
|
2
|
+
|
3
|
+
* INCOMPATIBLE CHANGE: the default SRID for non-geography columns is now -1, rather than 4326. (Geography columns still default to 4326.)
|
4
|
+
* It is now possible to create a spatial column without a corresponding entry in the geometry_columns table, and the adapter now handles this case properly. (Reported by Pirmin Kalberer)
|
5
|
+
* Now requires rgeo-activerecord 0.3.1 (which brings a critical fix involving declaring multiple spatial columns in a migration).
|
6
|
+
|
1
7
|
=== 0.3.2 / 2011-02-11
|
2
8
|
|
3
|
-
* You can now specify a separate "database creation" superuser so your normal
|
9
|
+
* You can now specify a separate "database creation" superuser role so your normal PostgreSQL login role doesn't need superuser privileges when running database creation tasks.
|
4
10
|
* Database creation tasks automatically create all schemas listed in the schema search path.
|
5
11
|
|
6
12
|
=== 0.3.1 / 2011-02-01
|
data/README.rdoc
CHANGED
@@ -14,8 +14,20 @@ the pg gem.
|
|
14
14
|
First, this adapter extends the migration syntax to support creating
|
15
15
|
spatial columns and indexes. To create a spatial column, use the
|
16
16
|
<tt>:geometry</tt> type, or any of the OGC spatial types such as
|
17
|
-
<tt>:point</tt> or <tt>:line_string</tt
|
18
|
-
|
17
|
+
<tt>:point</tt> or <tt>:line_string</tt> to set a geometry type
|
18
|
+
constraint. You may also provide any of the following options:
|
19
|
+
|
20
|
+
* <tt>:geographic</tt> -- If set to true, create a PostGIS geography
|
21
|
+
column; otherwise create a geometry column. Default is false.
|
22
|
+
* <tt>:srid</tt> -- Set a SRID constraint for the column. Default is 4326
|
23
|
+
for a geography column, or -1 for a geometry column. Note that PostGIS
|
24
|
+
currently (as of version 1.5.2) requires geography columns to have SRID
|
25
|
+
4326, so this constraint is of limited use for geography columns.
|
26
|
+
* <tt>:has_z</tt> -- Specify that objects in this column include a Z
|
27
|
+
coordinate. Default is false.
|
28
|
+
* <tt>:has_m</tt> -- Specify that objects in this column include an M
|
29
|
+
coordinate. Default is false.
|
30
|
+
|
19
31
|
To create a spatial index, set the <tt>:spatial</tt> option to true when
|
20
32
|
creating the index.
|
21
33
|
|
@@ -40,7 +52,7 @@ format, which the adapter will automatically convert to geometry objects.
|
|
40
52
|
Spatial objects in RGeo are tied to a factory that specifies the
|
41
53
|
coordinate system as well as other behaviors of the object. You must
|
42
54
|
therefore specify a factory for each spatial column (attribute) in your
|
43
|
-
ActiveRecord class. You can either set an explicit factory for a specific
|
55
|
+
\ActiveRecord class. You can either set an explicit factory for a specific
|
44
56
|
column, or provide a factory generator that will yield the appropriate
|
45
57
|
factory for the table's spatial columns based on their types. For the
|
46
58
|
former, call the <tt>set_rgeo_factory_for_column</tt> class method on your
|
@@ -100,10 +112,10 @@ This adapter has the following requirements:
|
|
100
112
|
|
101
113
|
* Ruby 1.8.7 or later. Ruby 1.9.2 or later preferred.
|
102
114
|
* PostGIS 1.5 or later.
|
115
|
+
* pg gem 0.10 or later.
|
103
116
|
* \ActiveRecord 3.0.3 or later. Earlier versions will not work.
|
104
117
|
* rgeo gem 0.2.4 or later.
|
105
|
-
* rgeo-activerecord gem 0.3.
|
106
|
-
* pg gem 0.10 or later.
|
118
|
+
* rgeo-activerecord gem 0.3.1 or later.
|
107
119
|
|
108
120
|
Install this adapter as a gem:
|
109
121
|
|
@@ -151,13 +163,13 @@ Generally, therefore, this parameter is required at least for the test
|
|
151
163
|
database, which is usually automatically created by the rake tasks.
|
152
164
|
|
153
165
|
The <i>su_username</i> and <i>su_password</i> parameters are provided as
|
154
|
-
optional parameters. If present, they specify an auxiliary
|
155
|
-
that will be used for two functions:
|
166
|
+
optional parameters. If present, they specify an auxiliary PostgreSQL role
|
167
|
+
that must have superuser privileges, and will be used for two functions:
|
156
168
|
|
157
169
|
* Creation of the database. This is so the main database user that you
|
158
170
|
specify doesn't need superuser or createdb privileges.
|
159
171
|
* Installation of the PostGIS definitions, if requested by the presence
|
160
|
-
of <i>script_dir</i>. This process normally requires a
|
172
|
+
of <i>script_dir</i>. This process normally requires a PostgreSQL role
|
161
173
|
with superuser privileges, so again if you don't want your main database
|
162
174
|
user to have superuser, you can perform this one-time procedure using
|
163
175
|
this alternate user.
|
@@ -198,11 +210,11 @@ To deal with these issues, we recommend the following technique:
|
|
198
210
|
The PostGIS Adapter responds to this special name by sandboxing the
|
199
211
|
PostGIS definitions into it when rake db:create is run, and it omits
|
200
212
|
this schema when running SQL structure dumps.
|
201
|
-
* Provide a separate <i>su_username</i> and <i>su_password</i>
|
202
|
-
your database, and make sure that
|
203
|
-
privilege. This will cause the PostGIS Adapter to log in as that
|
213
|
+
* Provide a separate <i>su_username</i> and <i>su_password</i> role for
|
214
|
+
your database, and make sure that separate role has the SUPERUSER
|
215
|
+
privilege. This will cause the PostGIS Adapter to log in as that role
|
204
216
|
when creating the database, since the PostGIS definition installation
|
205
|
-
requires SUPERUSER. Alternately, you can give the normal database
|
217
|
+
requires SUPERUSER. Alternately, you can give the normal database role
|
206
218
|
SUPERUSER privilege, which may be okay for a private development
|
207
219
|
database. These are used only by <tt>rake db:create</tt> so you can
|
208
220
|
remove them from your database.yml for your staging or production
|
data/Version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.3
|
@@ -108,7 +108,7 @@ module ActiveRecord
|
|
108
108
|
|
109
109
|
# Get index type by joining with pg_am.
|
110
110
|
result_ = query(<<-SQL, name_)
|
111
|
-
SELECT
|
111
|
+
SELECT DISTINCT i.relname, d.indisunique, d.indkey, t.oid, am.amname
|
112
112
|
FROM pg_class t, pg_class i, pg_index d, pg_am am
|
113
113
|
WHERE i.relkind = 'i'
|
114
114
|
AND d.indexrelid = i.oid
|
@@ -129,10 +129,10 @@ module ActiveRecord
|
|
129
129
|
|
130
130
|
columns_ = query(<<-SQL, "Columns for index #{row_[0]} on #{table_name_}").inject({}){ |h_, r_| h_[r_[0]] = [r_[1], r_[2]]; h_ }
|
131
131
|
SELECT a.attnum, a.attname, t.typname
|
132
|
-
|
132
|
+
FROM pg_attribute a, pg_type t
|
133
133
|
WHERE a.attrelid = #{oid_}
|
134
|
-
|
135
|
-
|
134
|
+
AND a.attnum IN (#{indkey_.join(",")})
|
135
|
+
AND a.atttypid = t.oid
|
136
136
|
SQL
|
137
137
|
|
138
138
|
spatial_ = indtype_ == 'gist' && columns_.size == 1 && (columns_.values.first[1] == 'geometry' || columns_.values.first[1] == 'geography')
|
@@ -180,23 +180,30 @@ module ActiveRecord
|
|
180
180
|
table_name_ = table_name_.to_s
|
181
181
|
if (info_ = spatial_column_constructor(type_.to_sym))
|
182
182
|
limit_ = options_[:limit]
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
if options_[:geographic]
|
189
|
-
type_ << 'Z' if has_z_
|
190
|
-
type_ << 'M' if has_m_
|
191
|
-
execute("ALTER TABLE #{quote_table_name(table_name_)} ADD COLUMN #{quote_column_name(column_name_)} GEOGRAPHY(#{type_},#{srid_})")
|
192
|
-
change_column_default(table_name_, column_name_, options_[:default]) if options_include_default?(options_)
|
193
|
-
change_column_null(table_name_, column_name_, false, options_[:default]) if options_[:null] == false
|
183
|
+
if type_.to_s == 'geometry' &&
|
184
|
+
(options_[:no_constraints] || limit_.is_a?(::Hash) && limit_[:no_constraints])
|
185
|
+
then
|
186
|
+
options_.delete(:limit)
|
187
|
+
super
|
194
188
|
else
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
189
|
+
options_.merge!(limit_) if limit_.is_a?(::Hash)
|
190
|
+
type_ = (options_[:type] || info_[:type] || type_).to_s.gsub('_', '').upcase
|
191
|
+
has_z_ = options_[:has_z]
|
192
|
+
has_m_ = options_[:has_m]
|
193
|
+
srid_ = (options_[:srid] || -1).to_i
|
194
|
+
if options_[:geographic]
|
195
|
+
type_ << 'Z' if has_z_
|
196
|
+
type_ << 'M' if has_m_
|
197
|
+
execute("ALTER TABLE #{quote_table_name(table_name_)} ADD COLUMN #{quote_column_name(column_name_)} GEOGRAPHY(#{type_},#{srid_})")
|
198
|
+
change_column_default(table_name_, column_name_, options_[:default]) if options_include_default?(options_)
|
199
|
+
change_column_null(table_name_, column_name_, false, options_[:default]) if options_[:null] == false
|
200
|
+
else
|
201
|
+
type_ = "#{type_}M" if has_m_ && !has_z_
|
202
|
+
dimensions_ = 2
|
203
|
+
dimensions_ += 1 if has_z_
|
204
|
+
dimensions_ += 1 if has_m_
|
205
|
+
execute("SELECT AddGeometryColumn('#{quote_string(table_name_)}', '#{quote_string(column_name_.to_s)}', #{srid_}, '#{quote_string(type_)}', #{dimensions_})")
|
206
|
+
end
|
200
207
|
end
|
201
208
|
else
|
202
209
|
super
|
@@ -50,11 +50,14 @@ module ActiveRecord
|
|
50
50
|
super(name_, default_, sql_type_, null_)
|
51
51
|
@geographic = sql_type_ =~ /geography/i ? true : false
|
52
52
|
if opts_
|
53
|
-
|
53
|
+
# This case comes from an entry in the geometry_columns table
|
54
|
+
@geometric_type = ::RGeo::ActiveRecord.geometric_type_from_name(opts_[:type]) ||
|
55
|
+
::RGeo::Feature::Geometry
|
54
56
|
@srid = opts_[:srid].to_i
|
55
|
-
@has_z = opts_[:has_z]
|
56
|
-
@has_m = opts_[:has_m]
|
57
|
+
@has_z = opts_[:has_z] ? true : false
|
58
|
+
@has_m = opts_[:has_m] ? true : false
|
57
59
|
elsif @geographic
|
60
|
+
# Geographic type information is embedded in the SQL type
|
58
61
|
@geometric_type = ::RGeo::Feature::Geometry
|
59
62
|
@srid = 4326
|
60
63
|
@has_z = @has_m = false
|
@@ -71,15 +74,23 @@ module ActiveRecord
|
|
71
74
|
end
|
72
75
|
end
|
73
76
|
end
|
77
|
+
elsif type == :spatial
|
78
|
+
# Just in case there is a geometry column with no geometry_columns entry.
|
79
|
+
@geometric_type = ::RGeo::Feature::Geometry
|
80
|
+
@srid = @has_z = @has_m = nil
|
74
81
|
else
|
75
|
-
|
76
|
-
@srid =
|
82
|
+
# Non-spatial column
|
83
|
+
@geometric_type = @has_z = @has_m = @srid = nil
|
77
84
|
end
|
78
85
|
if type == :spatial
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
86
|
+
if @srid
|
87
|
+
@limit = {:srid => @srid, :type => @geometric_type.type_name.underscore}
|
88
|
+
@limit[:has_z] = true if @has_z
|
89
|
+
@limit[:has_m] = true if @has_m
|
90
|
+
@limit[:geographic] = true if @geographic
|
91
|
+
else
|
92
|
+
@limit = {:no_constraints => true}
|
93
|
+
end
|
83
94
|
end
|
84
95
|
@ar_class = ::ActiveRecord::Base
|
85
96
|
end
|
@@ -106,18 +117,34 @@ module ActiveRecord
|
|
106
117
|
end
|
107
118
|
|
108
119
|
|
120
|
+
def has_spatial_constraints?
|
121
|
+
!@srid.nil?
|
122
|
+
end
|
123
|
+
|
124
|
+
|
109
125
|
def klass
|
110
126
|
type == :spatial ? ::RGeo::Feature::Geometry : super
|
111
127
|
end
|
112
128
|
|
113
129
|
|
114
130
|
def type_cast(value_)
|
115
|
-
type == :spatial
|
131
|
+
if type == :spatial
|
132
|
+
SpatialColumn.convert_to_geometry(value_, @ar_class, name, @geographic,
|
133
|
+
@srid, @has_z, @has_m)
|
134
|
+
else
|
135
|
+
super
|
136
|
+
end
|
116
137
|
end
|
117
138
|
|
118
139
|
|
119
140
|
def type_cast_code(var_name_)
|
120
|
-
type == :spatial
|
141
|
+
if type == :spatial
|
142
|
+
"::ActiveRecord::ConnectionAdapters::PostGISAdapter::SpatialColumn.convert_to_geometry("+
|
143
|
+
"#{var_name_}, self.class, #{name.inspect}, #{@geographic ? 'true' : 'false'}, "+
|
144
|
+
"#{@srid.inspect}, #{@has_z ? 'true' : 'false'}, #{@has_m ? 'true' : 'false'})"
|
145
|
+
else
|
146
|
+
super
|
147
|
+
end
|
121
148
|
end
|
122
149
|
|
123
150
|
|
@@ -130,15 +157,21 @@ module ActiveRecord
|
|
130
157
|
|
131
158
|
|
132
159
|
def self.convert_to_geometry(input_, ar_class_, column_, geographic_, srid_, has_z_, has_m_)
|
160
|
+
if srid_
|
161
|
+
constraints_ = {:geographic => geographic_, :has_z_coordinate => has_z_,
|
162
|
+
:has_m_coordinate => has_m_, :srid => srid_}
|
163
|
+
else
|
164
|
+
constraints_ = nil
|
165
|
+
end
|
133
166
|
case input_
|
134
167
|
when ::RGeo::Feature::Geometry
|
135
|
-
factory_ = ar_class_.rgeo_factory_for_column(column_,
|
168
|
+
factory_ = ar_class_.rgeo_factory_for_column(column_, constraints_)
|
136
169
|
::RGeo::Feature.cast(input_, factory_)
|
137
170
|
when ::String
|
138
171
|
if input_.length == 0
|
139
172
|
nil
|
140
173
|
else
|
141
|
-
factory_ = ar_class_.rgeo_factory_for_column(column_,
|
174
|
+
factory_ = ar_class_.rgeo_factory_for_column(column_, constraints_)
|
142
175
|
marker_ = input_[0,1]
|
143
176
|
if marker_ == "\x00" || marker_ == "\x01"
|
144
177
|
::RGeo::WKRep::WKBParser.new(factory_, :support_ewkb => true).parse(input_) rescue nil
|
@@ -47,8 +47,16 @@ module ActiveRecord
|
|
47
47
|
|
48
48
|
def column(name_, type_, options_={})
|
49
49
|
if (info_ = @base.spatial_column_constructor(type_.to_sym))
|
50
|
-
options_[:type]
|
51
|
-
type_
|
50
|
+
type_ = options_[:type] || info_[:type] || type_
|
51
|
+
if type_.to_s == 'geometry' &&
|
52
|
+
(options_[:no_constraints] ||
|
53
|
+
options_[:limit].is_a?(::Hash) && options_[:limit][:no_constraints])
|
54
|
+
then
|
55
|
+
options_.delete(:limit)
|
56
|
+
else
|
57
|
+
options_[:type] = type_
|
58
|
+
type_ = :spatial
|
59
|
+
end
|
52
60
|
end
|
53
61
|
super(name_, type_, options_)
|
54
62
|
if type_ == :spatial
|
@@ -57,7 +65,7 @@ module ActiveRecord
|
|
57
65
|
options_.merge!(col_.limit) if col_.limit.is_a?(::Hash)
|
58
66
|
col_.set_spatial_type(options_[:type])
|
59
67
|
col_.set_geographic(options_[:geographic])
|
60
|
-
col_.set_srid(
|
68
|
+
col_.set_srid(options_[:srid])
|
61
69
|
col_.set_has_z(options_[:has_z])
|
62
70
|
col_.set_has_m(options_[:has_m])
|
63
71
|
end
|
@@ -78,23 +86,23 @@ module ActiveRecord
|
|
78
86
|
module SpatialColumnDefinitionMethods
|
79
87
|
|
80
88
|
def spatial_type
|
81
|
-
|
89
|
+
@spatial_type
|
82
90
|
end
|
83
91
|
|
84
92
|
def geographic?
|
85
|
-
|
93
|
+
@geographic
|
86
94
|
end
|
87
95
|
|
88
96
|
def srid
|
89
|
-
|
97
|
+
@srid ? @srid.to_i : (geographic? ? 4326 : -1)
|
90
98
|
end
|
91
99
|
|
92
100
|
def has_z?
|
93
|
-
|
101
|
+
@has_z
|
94
102
|
end
|
95
103
|
|
96
104
|
def has_m?
|
97
|
-
|
105
|
+
@has_m
|
98
106
|
end
|
99
107
|
|
100
108
|
def set_geographic(value_)
|
data/test/tc_basic.rb
CHANGED
@@ -61,6 +61,10 @@ module RGeo
|
|
61
61
|
klass_.connection.create_table(:spatial_test) do |t_|
|
62
62
|
t_.column 'latlon', :point, :srid => 4326, :geographic => true
|
63
63
|
end
|
64
|
+
when :no_constraints
|
65
|
+
klass_.connection.create_table(:spatial_test) do |t_|
|
66
|
+
t_.column 'geo', :geometry, :no_constraints => true
|
67
|
+
end
|
64
68
|
end
|
65
69
|
klass_
|
66
70
|
end
|
@@ -159,6 +163,25 @@ module RGeo
|
|
159
163
|
end
|
160
164
|
|
161
165
|
|
166
|
+
def test_save_and_load_no_constraints
|
167
|
+
klass_ = populate_ar_class(:no_constraints)
|
168
|
+
factory1_ = ::RGeo::Cartesian.preferred_factory(:srid => 3785)
|
169
|
+
factory2_ = ::RGeo::Cartesian.preferred_factory(:srid => 2000)
|
170
|
+
obj_ = klass_.new
|
171
|
+
obj_.geo = factory1_.point(1, 2)
|
172
|
+
obj_.save!
|
173
|
+
id_ = obj_.id
|
174
|
+
obj2_ = klass_.find(id_)
|
175
|
+
assert_equal(factory1_.point(1, 2), obj2_.geo)
|
176
|
+
assert_equal(3785, obj2_.geo.srid)
|
177
|
+
obj2_.geo = factory2_.point(3, 4)
|
178
|
+
obj2_.save!
|
179
|
+
obj3_ = klass_.find(id_)
|
180
|
+
assert_equal(factory2_.point(3,4), obj3_.geo)
|
181
|
+
assert_equal(2000, obj3_.geo.srid)
|
182
|
+
end
|
183
|
+
|
184
|
+
|
162
185
|
end
|
163
186
|
|
164
187
|
end
|
data/test/tc_ddl.rb
CHANGED
@@ -58,14 +58,32 @@ module RGeo
|
|
58
58
|
assert_equal(1, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
59
59
|
col_ = klass_.columns.last
|
60
60
|
assert_equal(::RGeo::Feature::Geometry, col_.geometric_type)
|
61
|
+
assert_equal(true, col_.has_spatial_constraints?)
|
61
62
|
assert_equal(false, col_.geographic?)
|
62
|
-
assert_equal(
|
63
|
+
assert_equal(-1, col_.srid)
|
63
64
|
assert(klass_.cached_attributes.include?('latlon'))
|
64
65
|
klass_.connection.drop_table(:spatial_test)
|
65
66
|
assert_equal(0, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
66
67
|
end
|
67
68
|
|
68
69
|
|
70
|
+
def test_create_no_constraints_geometry
|
71
|
+
klass_ = create_ar_class
|
72
|
+
klass_.connection.create_table(:spatial_test) do |t_|
|
73
|
+
t_.column 'geom', :geometry, :limit => {:no_constraints => true}
|
74
|
+
end
|
75
|
+
assert_equal(0, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
76
|
+
col_ = klass_.columns.last
|
77
|
+
assert_equal(::RGeo::Feature::Geometry, col_.geometric_type)
|
78
|
+
assert_equal(false, col_.geographic?)
|
79
|
+
assert_equal(false, col_.has_spatial_constraints?)
|
80
|
+
assert_nil(col_.srid)
|
81
|
+
assert(klass_.cached_attributes.include?('geom'))
|
82
|
+
klass_.connection.drop_table(:spatial_test)
|
83
|
+
assert_equal(0, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
84
|
+
end
|
85
|
+
|
86
|
+
|
69
87
|
def test_create_simple_geography
|
70
88
|
klass_ = create_ar_class
|
71
89
|
klass_.connection.create_table(:spatial_test) do |t_|
|
@@ -73,6 +91,7 @@ module RGeo
|
|
73
91
|
end
|
74
92
|
col_ = klass_.columns.last
|
75
93
|
assert_equal(::RGeo::Feature::Geometry, col_.geometric_type)
|
94
|
+
assert_equal(true, col_.has_spatial_constraints?)
|
76
95
|
assert_equal(true, col_.geographic?)
|
77
96
|
assert_equal(4326, col_.srid)
|
78
97
|
assert(klass_.cached_attributes.include?('latlon'))
|
@@ -114,11 +133,37 @@ module RGeo
|
|
114
133
|
assert_equal(2, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
115
134
|
cols_ = klass_.columns
|
116
135
|
assert_equal(::RGeo::Feature::Geometry, cols_[-3].geometric_type)
|
117
|
-
assert_equal(
|
136
|
+
assert_equal(-1, cols_[-3].srid)
|
137
|
+
assert_equal(true, cols_[-3].has_spatial_constraints?)
|
118
138
|
assert_equal(::RGeo::Feature::Point, cols_[-2].geometric_type)
|
119
139
|
assert_equal(4326, cols_[-2].srid)
|
120
140
|
assert_equal(false, cols_[-2].geographic?)
|
141
|
+
assert_equal(true, cols_[-2].has_spatial_constraints?)
|
142
|
+
assert_nil(cols_[-1].geometric_type)
|
143
|
+
assert_equal(false, cols_[-1].has_spatial_constraints?)
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
def test_add_no_constraints_geometry_column
|
148
|
+
klass_ = create_ar_class
|
149
|
+
klass_.connection.create_table(:spatial_test) do |t_|
|
150
|
+
t_.column('latlon', :geometry)
|
151
|
+
end
|
152
|
+
klass_.connection.change_table(:spatial_test) do |t_|
|
153
|
+
t_.column('geom2', :geometry, :no_constraints => true)
|
154
|
+
t_.column('name', :string)
|
155
|
+
end
|
156
|
+
assert_equal(1, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
157
|
+
cols_ = klass_.columns
|
158
|
+
assert_equal(::RGeo::Feature::Geometry, cols_[-3].geometric_type)
|
159
|
+
assert_equal(-1, cols_[-3].srid)
|
160
|
+
assert_equal(true, cols_[-3].has_spatial_constraints?)
|
161
|
+
assert_equal(::RGeo::Feature::Geometry, cols_[-2].geometric_type)
|
162
|
+
assert_nil(cols_[-2].srid)
|
163
|
+
assert_equal(false, cols_[-2].geographic?)
|
164
|
+
assert_equal(false, cols_[-2].has_spatial_constraints?)
|
121
165
|
assert_nil(cols_[-1].geometric_type)
|
166
|
+
assert_equal(false, cols_[-1].has_spatial_constraints?)
|
122
167
|
end
|
123
168
|
|
124
169
|
|
@@ -134,11 +179,14 @@ module RGeo
|
|
134
179
|
assert_equal(1, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
135
180
|
cols_ = klass_.columns
|
136
181
|
assert_equal(::RGeo::Feature::Geometry, cols_[-3].geometric_type)
|
137
|
-
assert_equal(
|
182
|
+
assert_equal(-1, cols_[-3].srid)
|
183
|
+
assert_equal(true, cols_[-3].has_spatial_constraints?)
|
138
184
|
assert_equal(::RGeo::Feature::Point, cols_[-2].geometric_type)
|
139
185
|
assert_equal(4326, cols_[-2].srid)
|
140
186
|
assert_equal(true, cols_[-2].geographic?)
|
187
|
+
assert_equal(true, cols_[-2].has_spatial_constraints?)
|
141
188
|
assert_nil(cols_[-1].geometric_type)
|
189
|
+
assert_equal(false, cols_[-1].has_spatial_constraints?)
|
142
190
|
end
|
143
191
|
|
144
192
|
|
@@ -155,7 +203,7 @@ module RGeo
|
|
155
203
|
cols_ = klass_.columns
|
156
204
|
assert_equal(::RGeo::Feature::Geometry, cols_[-1].geometric_type)
|
157
205
|
assert_equal('latlon', cols_[-1].name)
|
158
|
-
assert_equal(
|
206
|
+
assert_equal(-1, cols_[-1].srid)
|
159
207
|
assert_equal(false, cols_[-1].geographic?)
|
160
208
|
end
|
161
209
|
|
@@ -190,13 +238,29 @@ module RGeo
|
|
190
238
|
col_ = klass_.columns.last
|
191
239
|
assert_equal(::RGeo::Feature::Geometry, col_.geometric_type)
|
192
240
|
assert_equal(false, col_.geographic?)
|
193
|
-
assert_equal(
|
241
|
+
assert_equal(-1, col_.srid)
|
194
242
|
assert(klass_.cached_attributes.include?('latlon'))
|
195
243
|
klass_.connection.drop_table(:spatial_test)
|
196
244
|
assert_equal(0, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
197
245
|
end
|
198
246
|
|
199
247
|
|
248
|
+
def test_create_no_constraints_geometry_using_shortcut
|
249
|
+
klass_ = create_ar_class
|
250
|
+
klass_.connection.create_table(:spatial_test) do |t_|
|
251
|
+
t_.spatial 'geom', :no_constraints => true
|
252
|
+
end
|
253
|
+
assert_equal(0, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
254
|
+
col_ = klass_.columns.last
|
255
|
+
assert_equal(::RGeo::Feature::Geometry, col_.geometric_type)
|
256
|
+
assert_equal(false, col_.geographic?)
|
257
|
+
assert_nil(col_.srid)
|
258
|
+
assert(klass_.cached_attributes.include?('geom'))
|
259
|
+
klass_.connection.drop_table(:spatial_test)
|
260
|
+
assert_equal(0, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
261
|
+
end
|
262
|
+
|
263
|
+
|
200
264
|
def test_create_simple_geography_using_shortcut
|
201
265
|
klass_ = create_ar_class
|
202
266
|
klass_.connection.create_table(:spatial_test) do |t_|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: activerecord-postgis-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.3.
|
5
|
+
version: 0.3.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Daniel Azuma
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-02-
|
13
|
+
date: 2011-02-28 00:00:00 -08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
requirements:
|
22
22
|
- - ~>
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version: 0.3.
|
24
|
+
version: 0.3.1
|
25
25
|
type: :runtime
|
26
26
|
version_requirements: *id001
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
84
|
requirements: []
|
85
85
|
|
86
86
|
rubyforge_project: virtuoso
|
87
|
-
rubygems_version: 1.5.
|
87
|
+
rubygems_version: 1.5.3
|
88
88
|
signing_key:
|
89
89
|
specification_version: 3
|
90
90
|
summary: An ActiveRecord adapter for PostGIS, based on RGeo.
|