activerecord-postgis-adapter 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Documentation.rdoc +4 -4
- data/History.rdoc +6 -0
- data/Version +1 -1
- data/lib/active_record/connection_adapters/postgis_adapter.rb +2 -0
- data/lib/active_record/connection_adapters/postgis_adapter/rails3/databases.rake +11 -9
- data/lib/active_record/connection_adapters/postgis_adapter/rails3/main_adapter.rb +2 -52
- data/lib/active_record/connection_adapters/postgis_adapter/rails4/main_adapter.rb +11 -62
- data/lib/active_record/connection_adapters/postgis_adapter/rails4/postgis_database_tasks.rb +1 -1
- data/lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_column.rb +4 -4
- data/lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_table_definition.rb +33 -16
- data/lib/active_record/connection_adapters/postgis_adapter/shared/common_adapter_methods.rb +122 -0
- data/test/tc_tasks.rb +81 -1
- metadata +24 -13
- checksums.yaml +0 -7
data/Documentation.rdoc
CHANGED
@@ -12,7 +12,7 @@ This document is part of the distribution for the activerecord-postgis-adapter g
|
|
12
12
|
|
13
13
|
=== General Installation Considerations
|
14
14
|
|
15
|
-
Generally, we recommend starting with the latest versions of Ruby, Rails, PostgreSQL, and PostGIS. As of this writing, those are Ruby
|
15
|
+
Generally, we recommend starting with the latest versions of Ruby, Rails, PostgreSQL, and PostGIS. As of this writing, those are Ruby 2.0.0, Rails 3.2, PostgreSQL 9.2, and PostGIS 2.0. If you cannot upgrade, the minimum supported configuration is the following:
|
16
16
|
|
17
17
|
* Ruby 1.8.7
|
18
18
|
* Rails 3.0.3
|
@@ -21,10 +21,10 @@ Generally, we recommend starting with the latest versions of Ruby, Rails, Postgr
|
|
21
21
|
|
22
22
|
However, older software versions can make for a more involved setup process, so we recommend using the latest available if possible.
|
23
23
|
|
24
|
-
As of this writing, Rails 4.0.0
|
24
|
+
As of this writing, Rails 4.0.0 release candidate 1 has just been released. This version of activerecord-postgis-adapter does support Rails 4, but because the software is still pre-release, the usual caveats apply. If you are running Rails 4, you must be on the release candidate or later; the beta 1 release is not supported.
|
25
|
+
|
26
|
+
JRuby and the JDBC Postgres Adapter is supported. But, as of this writing, the JDBC adapters themselves are not yet compatible with Rails 4.
|
25
27
|
|
26
|
-
JRuby and the JDBC Postgres Adapter is supported. (But, as of this writing, the JDBC adapters themselves are not yet compatible with Rails 4.)
|
27
|
-
|
28
28
|
=== Creating a Spatial Rails App
|
29
29
|
|
30
30
|
This section covers starting a new Rails application from scratch. If you need to add geospatial capabilities to an existing Rails application (i.e. you need to convert a non-spatial database to a spatial database), see the section on "Upgrading a Database With Spatial Features" below.
|
data/History.rdoc
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
=== 0.6.3 / 2013-05-04
|
2
|
+
|
3
|
+
* Several fixes for compatibility with changes to Rails 4.0.0 rc1. (Reports by slbug and Victor Costan)
|
4
|
+
* Rails 3 rake tasks properly set PGUSER when appropriate. (Pull request by Mitin Pavel)
|
5
|
+
* Fixed a nil exception on some Rails 4 migrations. (Pull request by ivanfoong and Victor Costan)
|
6
|
+
|
1
7
|
=== 0.6.2 / 2013-03-08
|
2
8
|
|
3
9
|
* The PostGIS setup now properly connects as the superuser. (Reported by Adam Trilling)
|
data/Version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.3
|
@@ -66,6 +66,7 @@ require 'rgeo/active_record'
|
|
66
66
|
case ::ActiveRecord::VERSION::MAJOR
|
67
67
|
when 3
|
68
68
|
require 'active_record/connection_adapters/postgis_adapter/shared/version.rb'
|
69
|
+
require 'active_record/connection_adapters/postgis_adapter/shared/common_adapter_methods.rb'
|
69
70
|
require 'active_record/connection_adapters/postgis_adapter/rails3/main_adapter.rb'
|
70
71
|
require 'active_record/connection_adapters/postgis_adapter/rails3/spatial_table_definition.rb'
|
71
72
|
require 'active_record/connection_adapters/postgis_adapter/rails3/spatial_column.rb'
|
@@ -74,6 +75,7 @@ when 3
|
|
74
75
|
require 'active_record/connection_adapters/postgis_adapter/rails3/create_connection'
|
75
76
|
when 4
|
76
77
|
require 'active_record/connection_adapters/postgis_adapter/shared/version.rb'
|
78
|
+
require 'active_record/connection_adapters/postgis_adapter/shared/common_adapter_methods.rb'
|
77
79
|
require 'active_record/connection_adapters/postgis_adapter/rails4/main_adapter.rb'
|
78
80
|
require 'active_record/connection_adapters/postgis_adapter/rails4/spatial_table_definition.rb'
|
79
81
|
require 'active_record/connection_adapters/postgis_adapter/rails4/spatial_column.rb'
|
@@ -175,6 +175,14 @@ def drop_database(config_)
|
|
175
175
|
end
|
176
176
|
|
177
177
|
|
178
|
+
def set_psql_env(config_)
|
179
|
+
::ENV['PGHOST'] = config_["host"] if config_["host"]
|
180
|
+
::ENV['PGPORT'] = config_["port"].to_s if config_["port"]
|
181
|
+
::ENV['PGPASSWORD'] = config_["password"].to_s if config_["password"]
|
182
|
+
::ENV['PGUSER'] = config_["username"].to_s if config_["username"]
|
183
|
+
end
|
184
|
+
|
185
|
+
|
178
186
|
::RGeo::ActiveRecord::TaskHacker.modify('db:charset', nil, 'postgis') do |config_|
|
179
187
|
::ActiveRecord::Base.establish_connection(config_)
|
180
188
|
puts(::ActiveRecord::Base.connection.encoding)
|
@@ -182,9 +190,7 @@ end
|
|
182
190
|
|
183
191
|
|
184
192
|
::RGeo::ActiveRecord::TaskHacker.modify('db:structure:dump', nil, 'postgis') do |config_|
|
185
|
-
|
186
|
-
::ENV['PGPORT'] = config_["port"].to_s if config_["port"]
|
187
|
-
::ENV['PGPASSWORD'] = config_["password"].to_s if config_["password"]
|
193
|
+
set_psql_env(config_)
|
188
194
|
filename_ = ::File.join(::Rails.root, "db/#{::Rails.env}_structure.sql")
|
189
195
|
search_path_ = config_["schema_search_path"].to_s.strip
|
190
196
|
search_path_ = search_path_.split(",").map{ |sp_| sp_.strip }
|
@@ -197,18 +203,14 @@ end
|
|
197
203
|
|
198
204
|
|
199
205
|
::RGeo::ActiveRecord::TaskHacker.modify('db:structure:load', nil, 'postgis') do |config_|
|
200
|
-
|
201
|
-
::ENV['PGPORT'] = config_["port"].to_s if config_["port"]
|
202
|
-
::ENV['PGPASSWORD'] = config_["password"].to_s if config_["password"]
|
206
|
+
set_psql_env(config_)
|
203
207
|
filename_ = ::File.join(::Rails.root, "db/#{::Rails.env}_structure.sql")
|
204
208
|
`psql -f #{filename_} #{config_["database"]}`
|
205
209
|
end
|
206
210
|
|
207
211
|
|
208
212
|
::RGeo::ActiveRecord::TaskHacker.modify('db:test:clone_structure', 'test', 'postgis') do |config_|
|
209
|
-
|
210
|
-
::ENV['PGPORT'] = config_["port"].to_s if config_["port"]
|
211
|
-
::ENV['PGPASSWORD'] = config_["password"].to_s if config_["password"]
|
213
|
+
set_psql_env(config_)
|
212
214
|
`psql -U "#{config_["username"]}" -f #{::Rails.root}/db/#{::Rails.env}_structure.sql #{config_["database"]}`
|
213
215
|
end
|
214
216
|
|
@@ -44,13 +44,6 @@ module ActiveRecord # :nodoc:
|
|
44
44
|
class MainAdapter < PostgreSQLAdapter # :nodoc:
|
45
45
|
|
46
46
|
|
47
|
-
SPATIAL_COLUMN_CONSTRUCTORS = ::RGeo::ActiveRecord::DEFAULT_SPATIAL_COLUMN_CONSTRUCTORS.merge(
|
48
|
-
:geography => {:type => 'geometry', :geographic => true}
|
49
|
-
)
|
50
|
-
|
51
|
-
@@native_database_types = nil
|
52
|
-
|
53
|
-
|
54
47
|
def initialize(*args_)
|
55
48
|
super
|
56
49
|
# Rails 3.2 way of defining the visitor: do so in the constructor
|
@@ -60,59 +53,16 @@ module ActiveRecord # :nodoc:
|
|
60
53
|
end
|
61
54
|
|
62
55
|
|
63
|
-
|
64
|
-
@rgeo_factory_settings = factory_settings_
|
65
|
-
end
|
66
|
-
|
67
|
-
|
68
|
-
def adapter_name
|
69
|
-
PostGISAdapter::ADAPTER_NAME
|
70
|
-
end
|
56
|
+
include PostGISAdapter::CommonAdapterMethods
|
71
57
|
|
72
58
|
|
73
|
-
|
74
|
-
SPATIAL_COLUMN_CONSTRUCTORS[name_]
|
75
|
-
end
|
76
|
-
|
59
|
+
@@native_database_types = nil
|
77
60
|
|
78
61
|
def native_database_types
|
79
62
|
@@native_database_types ||= super.merge(:spatial => {:name => 'geometry'})
|
80
63
|
end
|
81
64
|
|
82
65
|
|
83
|
-
def postgis_lib_version
|
84
|
-
unless defined?(@postgis_lib_version)
|
85
|
-
@postgis_lib_version = select_value("SELECT PostGIS_Lib_Version()") rescue nil
|
86
|
-
end
|
87
|
-
@postgis_lib_version
|
88
|
-
end
|
89
|
-
|
90
|
-
|
91
|
-
def srs_database_columns
|
92
|
-
{:srtext_column => 'srtext', :proj4text_column => 'proj4text', :auth_name_column => 'auth_name', :auth_srid_column => 'auth_srid'}
|
93
|
-
end
|
94
|
-
|
95
|
-
|
96
|
-
def quote(value_, column_=nil)
|
97
|
-
if ::RGeo::Feature::Geometry.check_type(value_)
|
98
|
-
"'#{::RGeo::WKRep::WKBGenerator.new(:hex_format => true, :type_format => :ewkb, :emit_ewkb_srid => true).generate(value_)}'"
|
99
|
-
elsif value_.is_a?(::RGeo::Cartesian::BoundingBox)
|
100
|
-
"'#{value_.min_x},#{value_.min_y},#{value_.max_x},#{value_.max_y}'::box"
|
101
|
-
else
|
102
|
-
super
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
|
107
|
-
def type_cast(value_, column_)
|
108
|
-
if ::RGeo::Feature::Geometry.check_type(value_)
|
109
|
-
::RGeo::WKRep::WKBGenerator.new(:hex_format => true, :type_format => :ewkb, :emit_ewkb_srid => true).generate(value_)
|
110
|
-
else
|
111
|
-
super
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
|
116
66
|
def columns(table_name_, name_=nil)
|
117
67
|
# FULL REPLACEMENT. RE-CHECK ON NEW VERSIONS.
|
118
68
|
# We needed to return a spatial column subclass.
|
@@ -44,75 +44,23 @@ module ActiveRecord # :nodoc:
|
|
44
44
|
class MainAdapter < PostgreSQLAdapter # :nodoc:
|
45
45
|
|
46
46
|
|
47
|
-
SPATIAL_COLUMN_CONSTRUCTORS = ::RGeo::ActiveRecord::DEFAULT_SPATIAL_COLUMN_CONSTRUCTORS.merge(
|
48
|
-
:geography => {:type => 'geometry', :geographic => true}
|
49
|
-
)
|
50
|
-
|
51
|
-
@@native_database_types = nil
|
52
|
-
|
53
|
-
|
54
|
-
# Overridden to change the visitor
|
55
|
-
|
56
47
|
def initialize(*args_)
|
48
|
+
# Overridden to change the visitor
|
57
49
|
super
|
58
50
|
@visitor = ::Arel::Visitors::PostGIS.new(self)
|
59
51
|
end
|
60
52
|
|
61
53
|
|
62
|
-
|
63
|
-
@rgeo_factory_settings = factory_settings_
|
64
|
-
end
|
65
|
-
|
66
|
-
|
67
|
-
def adapter_name
|
68
|
-
PostGISAdapter::ADAPTER_NAME
|
69
|
-
end
|
70
|
-
|
71
|
-
|
72
|
-
def spatial_column_constructor(name_)
|
73
|
-
SPATIAL_COLUMN_CONSTRUCTORS[name_]
|
74
|
-
end
|
54
|
+
include PostGISAdapter::CommonAdapterMethods
|
75
55
|
|
76
56
|
|
77
|
-
|
57
|
+
@@native_database_types = nil
|
78
58
|
|
79
59
|
def native_database_types
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
def postgis_lib_version
|
85
|
-
unless defined?(@postgis_lib_version)
|
86
|
-
@postgis_lib_version = select_value("SELECT PostGIS_Lib_Version()") rescue nil
|
87
|
-
end
|
88
|
-
@postgis_lib_version
|
89
|
-
end
|
90
|
-
|
91
|
-
|
92
|
-
def srs_database_columns
|
93
|
-
{:srtext_column => 'srtext', :proj4text_column => 'proj4text', :auth_name_column => 'auth_name', :auth_srid_column => 'auth_srid'}
|
94
|
-
end
|
95
|
-
|
96
|
-
|
97
|
-
def quote(value_, column_=nil)
|
98
|
-
# Overridden to recognize geometry types
|
99
|
-
if ::RGeo::Feature::Geometry.check_type(value_)
|
100
|
-
"'#{::RGeo::WKRep::WKBGenerator.new(:hex_format => true, :type_format => :ewkb, :emit_ewkb_srid => true).generate(value_)}'"
|
101
|
-
elsif value_.is_a?(::RGeo::Cartesian::BoundingBox)
|
102
|
-
"'#{value_.min_x},#{value_.min_y},#{value_.max_x},#{value_.max_y}'::box"
|
103
|
-
else
|
104
|
-
super
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
|
109
|
-
def type_cast(value_, column_, array_member_=false)
|
110
|
-
# Overridden to recognize geometry types
|
111
|
-
if ::RGeo::Feature::Geometry.check_type(value_)
|
112
|
-
::RGeo::WKRep::WKBGenerator.new(:hex_format => true, :type_format => :ewkb, :emit_ewkb_srid => true).generate(value_)
|
113
|
-
else
|
114
|
-
super
|
115
|
-
end
|
60
|
+
# Overridden to add the :spatial type
|
61
|
+
@@native_database_types ||= super.merge(
|
62
|
+
:spatial => {:name => 'geometry'},
|
63
|
+
:geography => {:name => 'geography'})
|
116
64
|
end
|
117
65
|
|
118
66
|
|
@@ -187,9 +135,9 @@ module ActiveRecord # :nodoc:
|
|
187
135
|
end
|
188
136
|
|
189
137
|
|
190
|
-
def
|
191
|
-
# Override to create a spatial table definition
|
192
|
-
|
138
|
+
def create_table_definition(name_, temporary_, options_)
|
139
|
+
# Override to create a spatial table definition (post-4.0.0.beta1)
|
140
|
+
PostGISAdapter::TableDefinition.new(native_database_types, name_, temporary_, options_, self)
|
193
141
|
end
|
194
142
|
|
195
143
|
|
@@ -273,6 +221,7 @@ module ActiveRecord # :nodoc:
|
|
273
221
|
def add_index(table_name_, column_name_, options_={})
|
274
222
|
# FULL REPLACEMENT. RE-CHECK ON NEW VERSIONS.
|
275
223
|
# We have to fully-replace because of the gist_clause.
|
224
|
+
options_ ||= {}
|
276
225
|
gist_clause_ = options_.delete(:spatial) ? ' USING GIST' : ''
|
277
226
|
index_name_, index_type_, index_columns_, index_options_ = add_index_options(table_name_, column_name_, options_)
|
278
227
|
execute "CREATE #{index_type_} INDEX #{quote_column_name(index_name_)} ON #{quote_table_name(table_name_)}#{gist_clause_} (#{index_columns_})#{index_options_}"
|
@@ -82,7 +82,7 @@ module ActiveRecord # :nodoc:
|
|
82
82
|
@geometric_type = @has_z = @has_m = @srid = nil
|
83
83
|
end
|
84
84
|
super(name_, default_, oid_type_, sql_type_, null_)
|
85
|
-
if
|
85
|
+
if spatial?
|
86
86
|
if @srid
|
87
87
|
@limit = {:srid => @srid, :type => @geometric_type.type_name.underscore}
|
88
88
|
@limit[:has_z] = true if @has_z
|
@@ -107,7 +107,7 @@ module ActiveRecord # :nodoc:
|
|
107
107
|
|
108
108
|
|
109
109
|
def spatial?
|
110
|
-
type == :spatial
|
110
|
+
type == :spatial || type == :geography
|
111
111
|
end
|
112
112
|
|
113
113
|
|
@@ -117,12 +117,12 @@ module ActiveRecord # :nodoc:
|
|
117
117
|
|
118
118
|
|
119
119
|
def klass
|
120
|
-
|
120
|
+
spatial? ? ::RGeo::Feature::Geometry : super
|
121
121
|
end
|
122
122
|
|
123
123
|
|
124
124
|
def type_cast(value_)
|
125
|
-
if
|
125
|
+
if spatial?
|
126
126
|
SpatialColumn.convert_to_geometry(value_, @factory_settings, @table_name, name,
|
127
127
|
@geographic, @srid, @has_z, @has_m)
|
128
128
|
else
|
data/lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_table_definition.rb
CHANGED
@@ -41,7 +41,13 @@ module ActiveRecord # :nodoc:
|
|
41
41
|
module PostGISAdapter # :nodoc:
|
42
42
|
|
43
43
|
|
44
|
-
class
|
44
|
+
class TableDefinition < ConnectionAdapters::PostgreSQLAdapter::TableDefinition # :nodoc:
|
45
|
+
|
46
|
+
def initialize(types_, name_, temporary_, options_, base_)
|
47
|
+
@base = base_
|
48
|
+
@spatial_columns_hash = {}
|
49
|
+
super(types_, name_, temporary_, options_)
|
50
|
+
end
|
45
51
|
|
46
52
|
def column(name_, type_, options_={})
|
47
53
|
if (info_ = @base.spatial_column_constructor(type_.to_sym))
|
@@ -56,32 +62,50 @@ module ActiveRecord # :nodoc:
|
|
56
62
|
type_ = :spatial
|
57
63
|
end
|
58
64
|
end
|
59
|
-
super(name_, type_, options_)
|
60
65
|
if type_ == :spatial
|
61
|
-
|
62
|
-
|
63
|
-
|
66
|
+
if (limit_ = options_.delete(:limit))
|
67
|
+
options_.merge!(limit_) if limit_.is_a?(::Hash)
|
68
|
+
end
|
69
|
+
if options_[:geographic]
|
70
|
+
type_ = :geography
|
71
|
+
spatial_type_ = (options_[:type] || 'geometry').to_s.upcase.gsub('_', '')
|
72
|
+
spatial_type_ << 'Z' if options_[:has_z]
|
73
|
+
spatial_type_ << 'M' if options_[:has_m]
|
74
|
+
options_[:limit] = "#{spatial_type_},#{options_[:srid] || 4326}"
|
75
|
+
end
|
76
|
+
name_ = name_.to_s
|
77
|
+
if primary_key_column_name == name_
|
78
|
+
raise ArgumentError, "you can't redefine the primary key column '#{name_}'. To define a custom primary key, pass { id: false } to create_table."
|
79
|
+
end
|
80
|
+
col_ = new_column_definition(name_, type_, options_)
|
64
81
|
col_.set_spatial_type(options_[:type])
|
65
82
|
col_.set_geographic(options_[:geographic])
|
66
83
|
col_.set_srid(options_[:srid])
|
67
84
|
col_.set_has_z(options_[:has_z])
|
68
85
|
col_.set_has_m(options_[:has_m])
|
86
|
+
(col_.geographic? ? @columns_hash : @spatial_columns_hash)[name_] = col_
|
87
|
+
else
|
88
|
+
super(name_, type_, options_)
|
69
89
|
end
|
70
90
|
self
|
71
91
|
end
|
72
92
|
|
73
|
-
def
|
74
|
-
|
93
|
+
def create_column_definition(name_, type_)
|
94
|
+
if type_ == :spatial || type_ == :geography
|
95
|
+
PostGISAdapter::ColumnDefinition.new(name_, type_)
|
96
|
+
else
|
97
|
+
super
|
98
|
+
end
|
75
99
|
end
|
76
100
|
|
77
101
|
def non_geographic_spatial_columns
|
78
|
-
@
|
102
|
+
@spatial_columns_hash.values
|
79
103
|
end
|
80
104
|
|
81
105
|
end
|
82
106
|
|
83
107
|
|
84
|
-
|
108
|
+
class ColumnDefinition < ConnectionAdapters::ColumnDefinition # :nodoc:
|
85
109
|
|
86
110
|
def spatial_type
|
87
111
|
@spatial_type
|
@@ -123,13 +147,6 @@ module ActiveRecord # :nodoc:
|
|
123
147
|
@has_m = value_ ? true : false
|
124
148
|
end
|
125
149
|
|
126
|
-
def sql_type
|
127
|
-
type_ = spatial_type.upcase.gsub('_', '')
|
128
|
-
type_ << 'Z' if has_z?
|
129
|
-
type_ << 'M' if has_m?
|
130
|
-
"GEOGRAPHY(#{type_},#{srid})"
|
131
|
-
end
|
132
|
-
|
133
150
|
end
|
134
151
|
|
135
152
|
|
@@ -0,0 +1,122 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# PostGIS adapter for ActiveRecord
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
# Copyright 2010-2012 Daniel Azuma
|
7
|
+
#
|
8
|
+
# All rights reserved.
|
9
|
+
#
|
10
|
+
# Redistribution and use in source and binary forms, with or without
|
11
|
+
# modification, are permitted provided that the following conditions are met:
|
12
|
+
#
|
13
|
+
# * Redistributions of source code must retain the above copyright notice,
|
14
|
+
# this list of conditions and the following disclaimer.
|
15
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
16
|
+
# this list of conditions and the following disclaimer in the documentation
|
17
|
+
# and/or other materials provided with the distribution.
|
18
|
+
# * Neither the name of the copyright holder, nor the names of any other
|
19
|
+
# contributors to this software, may be used to endorse or promote products
|
20
|
+
# derived from this software without specific prior written permission.
|
21
|
+
#
|
22
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
25
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
26
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
27
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
33
|
+
# -----------------------------------------------------------------------------
|
34
|
+
;
|
35
|
+
|
36
|
+
|
37
|
+
module ActiveRecord # :nodoc:
|
38
|
+
|
39
|
+
module ConnectionAdapters # :nodoc:
|
40
|
+
|
41
|
+
module PostGISAdapter # :nodoc:
|
42
|
+
|
43
|
+
|
44
|
+
SPATIAL_COLUMN_CONSTRUCTORS = ::RGeo::ActiveRecord::DEFAULT_SPATIAL_COLUMN_CONSTRUCTORS.merge(
|
45
|
+
:geography => {:type => 'geometry', :geographic => true}
|
46
|
+
)
|
47
|
+
|
48
|
+
|
49
|
+
module CommonAdapterMethods # :nodoc:
|
50
|
+
|
51
|
+
|
52
|
+
def set_rgeo_factory_settings(factory_settings_)
|
53
|
+
@rgeo_factory_settings = factory_settings_
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
def adapter_name
|
58
|
+
PostGISAdapter::ADAPTER_NAME
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
def spatial_column_constructor(name_)
|
63
|
+
PostGISAdapter::SPATIAL_COLUMN_CONSTRUCTORS[name_]
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
def postgis_lib_version
|
68
|
+
unless defined?(@postgis_lib_version)
|
69
|
+
@postgis_lib_version = select_value("SELECT PostGIS_Lib_Version()") rescue nil
|
70
|
+
end
|
71
|
+
@postgis_lib_version
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
def default_srid
|
76
|
+
unless defined?(@default_srid)
|
77
|
+
case postgis_lib_version
|
78
|
+
when nil
|
79
|
+
@default_srid = nil
|
80
|
+
when /^1/
|
81
|
+
@default_srid = -1
|
82
|
+
else
|
83
|
+
@default_srid = 0
|
84
|
+
end
|
85
|
+
end
|
86
|
+
@default_srid
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
def srs_database_columns
|
91
|
+
{:srtext_column => 'srtext', :proj4text_column => 'proj4text', :auth_name_column => 'auth_name', :auth_srid_column => 'auth_srid'}
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
def quote(value_, column_=nil)
|
96
|
+
if ::RGeo::Feature::Geometry.check_type(value_)
|
97
|
+
"'#{::RGeo::WKRep::WKBGenerator.new(:hex_format => true, :type_format => :ewkb, :emit_ewkb_srid => true).generate(value_)}'"
|
98
|
+
elsif value_.is_a?(::RGeo::Cartesian::BoundingBox)
|
99
|
+
"'#{value_.min_x},#{value_.min_y},#{value_.max_x},#{value_.max_y}'::box"
|
100
|
+
else
|
101
|
+
super
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
def type_cast(value_, column_)
|
107
|
+
if ::RGeo::Feature::Geometry.check_type(value_)
|
108
|
+
::RGeo::WKRep::WKBGenerator.new(:hex_format => true, :type_format => :ewkb, :emit_ewkb_srid => true).generate(value_)
|
109
|
+
else
|
110
|
+
super
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
data/test/tc_tasks.rb
CHANGED
@@ -86,7 +86,7 @@ module RGeo
|
|
86
86
|
end
|
87
87
|
|
88
88
|
|
89
|
-
def
|
89
|
+
def test_empty_sql_dump
|
90
90
|
unless defined?(::ActiveRecord::ConnectionAdapters::PostGISAdapter::PostGISDatabaseTasks)
|
91
91
|
skip('No task tests for Rails 3')
|
92
92
|
end
|
@@ -100,6 +100,86 @@ module RGeo
|
|
100
100
|
end
|
101
101
|
|
102
102
|
|
103
|
+
def test_basic_geography_sql_dump
|
104
|
+
unless defined?(::ActiveRecord::ConnectionAdapters::PostGISAdapter::PostGISDatabaseTasks)
|
105
|
+
skip('No task tests for Rails 3')
|
106
|
+
end
|
107
|
+
filename_ = ::File.expand_path('../tmp/tmp.sql', ::File.dirname(__FILE__))
|
108
|
+
::FileUtils.rm_f(filename_)
|
109
|
+
::FileUtils.mkdir_p(::File.dirname(filename_))
|
110
|
+
::ActiveRecord::Tasks::DatabaseTasks.create(TestTasks.new_database_config.merge('schema_search_path' => 'public,postgis'))
|
111
|
+
::ActiveRecord::Base.connection.create_table(:spatial_test) do |t_|
|
112
|
+
t_.point "latlon", :geographic => true
|
113
|
+
end
|
114
|
+
::ActiveRecord::Tasks::DatabaseTasks.structure_dump(TestTasks.new_database_config, filename_)
|
115
|
+
data_ = ::File.read(filename_)
|
116
|
+
assert(data_.index('latlon postgis.geography(Point,4326)'))
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
def test_empty_schema_dump
|
121
|
+
unless defined?(::ActiveRecord::ConnectionAdapters::PostGISAdapter::PostGISDatabaseTasks)
|
122
|
+
skip('No task tests for Rails 3')
|
123
|
+
end
|
124
|
+
filename_ = ::File.expand_path('../tmp/tmp.rb', ::File.dirname(__FILE__))
|
125
|
+
::FileUtils.rm_f(filename_)
|
126
|
+
::FileUtils.mkdir_p(::File.dirname(filename_))
|
127
|
+
::ActiveRecord::Tasks::DatabaseTasks.create(TestTasks.new_database_config.merge('schema_search_path' => 'public,postgis'))
|
128
|
+
require 'active_record/schema_dumper'
|
129
|
+
::File.open(filename_, "w:utf-8") do |file_|
|
130
|
+
::ActiveRecord::SchemaDumper.dump(::ActiveRecord::Base.connection, file_)
|
131
|
+
end
|
132
|
+
data_ = ::File.read(filename_)
|
133
|
+
assert(data_.index('ActiveRecord::Schema'))
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
def test_basic_geometry_schema_dump
|
138
|
+
unless defined?(::ActiveRecord::ConnectionAdapters::PostGISAdapter::PostGISDatabaseTasks)
|
139
|
+
skip('No task tests for Rails 3')
|
140
|
+
end
|
141
|
+
filename_ = ::File.expand_path('../tmp/tmp.rb', ::File.dirname(__FILE__))
|
142
|
+
::FileUtils.rm_f(filename_)
|
143
|
+
::FileUtils.mkdir_p(::File.dirname(filename_))
|
144
|
+
::ActiveRecord::Tasks::DatabaseTasks.create(TestTasks.new_database_config.merge('schema_search_path' => 'public,postgis'))
|
145
|
+
conn_ = ::ActiveRecord::Base.connection
|
146
|
+
conn_.create_table(:spatial_test) do |t_|
|
147
|
+
t_.geometry 'object1'
|
148
|
+
t_.spatial "object2", :limit => {:srid=>conn_.default_srid, :type=>"geometry"}
|
149
|
+
end
|
150
|
+
require 'active_record/schema_dumper'
|
151
|
+
::File.open(filename_, "w:utf-8") do |file_|
|
152
|
+
::ActiveRecord::SchemaDumper.dump(conn_, file_)
|
153
|
+
end
|
154
|
+
data_ = ::File.read(filename_)
|
155
|
+
assert(data_.index("t.spatial \"object1\", limit: {:srid=>#{conn_.default_srid}, :type=>\"geometry\"}"))
|
156
|
+
assert(data_.index("t.spatial \"object2\", limit: {:srid=>#{conn_.default_srid}, :type=>\"geometry\"}"))
|
157
|
+
end
|
158
|
+
|
159
|
+
|
160
|
+
def test_basic_geography_schema_dump
|
161
|
+
unless defined?(::ActiveRecord::ConnectionAdapters::PostGISAdapter::PostGISDatabaseTasks)
|
162
|
+
skip('No task tests for Rails 3')
|
163
|
+
end
|
164
|
+
filename_ = ::File.expand_path('../tmp/tmp.rb', ::File.dirname(__FILE__))
|
165
|
+
::FileUtils.rm_f(filename_)
|
166
|
+
::FileUtils.mkdir_p(::File.dirname(filename_))
|
167
|
+
::ActiveRecord::Tasks::DatabaseTasks.create(TestTasks.new_database_config.merge('schema_search_path' => 'public,postgis'))
|
168
|
+
conn_ = ::ActiveRecord::Base.connection
|
169
|
+
conn_.create_table(:spatial_test) do |t_|
|
170
|
+
t_.point "latlon1", :geographic => true
|
171
|
+
t_.spatial "latlon2", :limit => {:srid=>4326, :type=>"point", :geographic=>true}
|
172
|
+
end
|
173
|
+
require 'active_record/schema_dumper'
|
174
|
+
::File.open(filename_, "w:utf-8") do |file_|
|
175
|
+
::ActiveRecord::SchemaDumper.dump(conn_, file_)
|
176
|
+
end
|
177
|
+
data_ = ::File.read(filename_)
|
178
|
+
assert(data_.index('t.spatial "latlon1", limit: {:srid=>4326, :type=>"point", :geographic=>true}'))
|
179
|
+
assert(data_.index('t.spatial "latlon2", limit: {:srid=>4326, :type=>"point", :geographic=>true}'))
|
180
|
+
end
|
181
|
+
|
182
|
+
|
103
183
|
end
|
104
184
|
|
105
185
|
end
|
metadata
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-postgis-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Daniel Azuma
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2013-
|
12
|
+
date: 2013-05-04 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rgeo-activerecord
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
19
|
- - ~>
|
18
20
|
- !ruby/object:Gem::Version
|
@@ -20,6 +22,7 @@ dependencies:
|
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
27
|
- - ~>
|
25
28
|
- !ruby/object:Gem::Version
|
@@ -27,43 +30,49 @@ dependencies:
|
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: rake
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
|
-
- - '>='
|
35
|
+
- - ! '>='
|
32
36
|
- !ruby/object:Gem::Version
|
33
37
|
version: '0'
|
34
38
|
type: :development
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
|
-
- - '>='
|
43
|
+
- - ! '>='
|
39
44
|
- !ruby/object:Gem::Version
|
40
45
|
version: '0'
|
41
46
|
- !ruby/object:Gem::Dependency
|
42
47
|
name: minitest
|
43
48
|
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
44
50
|
requirements:
|
45
|
-
- - '>='
|
51
|
+
- - ! '>='
|
46
52
|
- !ruby/object:Gem::Version
|
47
53
|
version: '0'
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
51
58
|
requirements:
|
52
|
-
- - '>='
|
59
|
+
- - ! '>='
|
53
60
|
- !ruby/object:Gem::Version
|
54
61
|
version: '0'
|
55
62
|
- !ruby/object:Gem::Dependency
|
56
63
|
name: rdoc
|
57
64
|
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
58
66
|
requirements:
|
59
|
-
- - '>='
|
67
|
+
- - ! '>='
|
60
68
|
- !ruby/object:Gem::Version
|
61
69
|
version: '0'
|
62
70
|
type: :development
|
63
71
|
prerelease: false
|
64
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
65
74
|
requirements:
|
66
|
-
- - '>='
|
75
|
+
- - ! '>='
|
67
76
|
- !ruby/object:Gem::Version
|
68
77
|
version: '0'
|
69
78
|
description: This is an ActiveRecord connection adapter for PostGIS. It is based on
|
@@ -88,6 +97,7 @@ files:
|
|
88
97
|
- lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_table_definition.rb
|
89
98
|
- lib/active_record/connection_adapters/postgis_adapter/railtie.rb
|
90
99
|
- lib/active_record/connection_adapters/postgis_adapter/shared/arel_tosql.rb
|
100
|
+
- lib/active_record/connection_adapters/postgis_adapter/shared/common_adapter_methods.rb
|
91
101
|
- lib/active_record/connection_adapters/postgis_adapter/shared/jdbc_compat.rb
|
92
102
|
- lib/active_record/connection_adapters/postgis_adapter/shared/railtie.rb
|
93
103
|
- lib/active_record/connection_adapters/postgis_adapter/shared/setup.rb
|
@@ -110,26 +120,27 @@ files:
|
|
110
120
|
homepage: http://dazuma.github.com/activerecord-postgis-adapter
|
111
121
|
licenses:
|
112
122
|
- BSD
|
113
|
-
metadata: {}
|
114
123
|
post_install_message:
|
115
124
|
rdoc_options: []
|
116
125
|
require_paths:
|
117
126
|
- lib
|
118
127
|
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
119
129
|
requirements:
|
120
|
-
- - '>='
|
130
|
+
- - ! '>='
|
121
131
|
- !ruby/object:Gem::Version
|
122
132
|
version: 1.8.7
|
123
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
none: false
|
124
135
|
requirements:
|
125
|
-
- - '>'
|
136
|
+
- - ! '>'
|
126
137
|
- !ruby/object:Gem::Version
|
127
138
|
version: 1.3.1
|
128
139
|
requirements: []
|
129
140
|
rubyforge_project: virtuoso
|
130
|
-
rubygems_version:
|
141
|
+
rubygems_version: 1.8.25
|
131
142
|
signing_key:
|
132
|
-
specification_version:
|
143
|
+
specification_version: 3
|
133
144
|
summary: An ActiveRecord adapter for PostGIS, based on RGeo.
|
134
145
|
test_files:
|
135
146
|
- test/tc_basic.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 13b719128d29998b594c6b5824d977cbd9c613fe
|
4
|
-
data.tar.gz: aff10c325efe668907b5cceab815f86b621679a8
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 7129620feb197a400636bc4b5b563229041a03558bd6d095eca6c72c4ba12a52849919198907eeb8e65fa7c07e00fb34759afcacd528078e68ec78cba5e0f793
|
7
|
-
data.tar.gz: f4d7459e39bc259aaaa00d7a9eca3adfa1b36809ff017db983f7d01df366ffe9a3eb8f4e3299e931a48e6bf72e5a714c003b6fd684b2d247fb7a2e4d97170fb4
|