activerecord-postgis-adapter 0.4.0 → 0.4.1
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/History.rdoc +5 -0
- data/README.rdoc +4 -4
- data/Version +1 -1
- data/lib/active_record/connection_adapters/postgis_adapter.rb +25 -25
- data/lib/active_record/connection_adapters/postgis_adapter/arel_tosql.rb +15 -15
- data/lib/active_record/connection_adapters/postgis_adapter/databases.rake +11 -11
- data/lib/active_record/connection_adapters/postgis_adapter/main_adapter.rb +70 -61
- data/lib/active_record/connection_adapters/postgis_adapter/railtie.rb +17 -17
- data/lib/active_record/connection_adapters/postgis_adapter/spatial_column.rb +44 -39
- data/lib/active_record/connection_adapters/postgis_adapter/spatial_table_definition.rb +33 -33
- data/lib/active_record/connection_adapters/postgis_adapter/version.rb +16 -16
- data/lib/rgeo/active_record/postgis_adapter/railtie.rb +7 -7
- data/test/tc_basic.rb +38 -38
- data/test/tc_ddl.rb +46 -46
- data/test/tc_spatial_queries.rb +32 -32
- metadata +36 -40
@@ -1,15 +1,15 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# Railtie for PostGIS adapter
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010 Daniel Azuma
|
7
|
-
#
|
6
|
+
# Copyright 2010-2012 Daniel Azuma
|
7
|
+
#
|
8
8
|
# All rights reserved.
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# Redistribution and use in source and binary forms, with or without
|
11
11
|
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# * Redistributions of source code must retain the above copyright notice,
|
14
14
|
# this list of conditions and the following disclaimer.
|
15
15
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
@@ -18,7 +18,7 @@
|
|
18
18
|
# * Neither the name of the copyright holder, nor the names of any other
|
19
19
|
# contributors to this software, may be used to endorse or promote products
|
20
20
|
# derived from this software without specific prior written permission.
|
21
|
-
#
|
21
|
+
#
|
22
22
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
23
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
24
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
@@ -40,25 +40,25 @@ require 'rails/railtie'
|
|
40
40
|
# :stopdoc:
|
41
41
|
|
42
42
|
module ActiveRecord
|
43
|
-
|
43
|
+
|
44
44
|
module ConnectionAdapters
|
45
|
-
|
45
|
+
|
46
46
|
module PostGISAdapter
|
47
|
-
|
48
|
-
|
47
|
+
|
48
|
+
|
49
49
|
class Railtie < ::Rails::Railtie
|
50
|
-
|
50
|
+
|
51
51
|
rake_tasks do
|
52
52
|
load ::File.expand_path('databases.rake', ::File.dirname(__FILE__))
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
end
|
56
|
-
|
57
|
-
|
56
|
+
|
57
|
+
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
end
|
63
63
|
|
64
64
|
# :startdoc:
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# PostGIS adapter for ActiveRecord
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010 Daniel Azuma
|
7
|
-
#
|
6
|
+
# Copyright 2010-2012 Daniel Azuma
|
7
|
+
#
|
8
8
|
# All rights reserved.
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# Redistribution and use in source and binary forms, with or without
|
11
11
|
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# * Redistributions of source code must retain the above copyright notice,
|
14
14
|
# this list of conditions and the following disclaimer.
|
15
15
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
@@ -18,7 +18,7 @@
|
|
18
18
|
# * Neither the name of the copyright holder, nor the names of any other
|
19
19
|
# contributors to this software, may be used to endorse or promote products
|
20
20
|
# derived from this software without specific prior written permission.
|
21
|
-
#
|
21
|
+
#
|
22
22
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
23
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
24
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
@@ -37,15 +37,18 @@
|
|
37
37
|
# :stopdoc:
|
38
38
|
|
39
39
|
module ActiveRecord
|
40
|
-
|
40
|
+
|
41
41
|
module ConnectionAdapters
|
42
|
-
|
42
|
+
|
43
43
|
module PostGISAdapter
|
44
|
-
|
45
|
-
|
44
|
+
|
45
|
+
|
46
46
|
class SpatialColumn < ConnectionAdapters::PostgreSQLColumn
|
47
|
-
|
48
|
-
|
47
|
+
|
48
|
+
|
49
|
+
FACTORY_SETTINGS_CACHE = {}
|
50
|
+
|
51
|
+
|
49
52
|
def initialize(factory_settings_, table_name_, name_, default_, sql_type_=nil, null_=true, opts_=nil)
|
50
53
|
@factory_settings = factory_settings_
|
51
54
|
@table_name = table_name_
|
@@ -94,35 +97,36 @@ module ActiveRecord
|
|
94
97
|
@limit = {:no_constraints => true}
|
95
98
|
end
|
96
99
|
end
|
100
|
+
FACTORY_SETTINGS_CACHE[factory_settings_.object_id] = factory_settings_
|
97
101
|
end
|
98
|
-
|
99
|
-
|
102
|
+
|
103
|
+
|
100
104
|
attr_reader :geographic
|
101
105
|
attr_reader :srid
|
102
106
|
attr_reader :geometric_type
|
103
107
|
attr_reader :has_z
|
104
108
|
attr_reader :has_m
|
105
|
-
|
109
|
+
|
106
110
|
alias_method :geographic?, :geographic
|
107
111
|
alias_method :has_z?, :has_z
|
108
112
|
alias_method :has_m?, :has_m
|
109
|
-
|
110
|
-
|
113
|
+
|
114
|
+
|
111
115
|
def spatial?
|
112
116
|
type == :spatial
|
113
117
|
end
|
114
|
-
|
115
|
-
|
118
|
+
|
119
|
+
|
116
120
|
def has_spatial_constraints?
|
117
121
|
!@srid.nil?
|
118
122
|
end
|
119
|
-
|
120
|
-
|
123
|
+
|
124
|
+
|
121
125
|
def klass
|
122
126
|
type == :spatial ? ::RGeo::Feature::Geometry : super
|
123
127
|
end
|
124
|
-
|
125
|
-
|
128
|
+
|
129
|
+
|
126
130
|
def type_cast(value_)
|
127
131
|
if type == :spatial
|
128
132
|
SpatialColumn.convert_to_geometry(value_, @factory_settings, @table_name, name,
|
@@ -131,28 +135,29 @@ module ActiveRecord
|
|
131
135
|
super
|
132
136
|
end
|
133
137
|
end
|
134
|
-
|
135
|
-
|
138
|
+
|
139
|
+
|
136
140
|
def type_cast_code(var_name_)
|
137
141
|
if type == :spatial
|
138
142
|
"::ActiveRecord::ConnectionAdapters::PostGISAdapter::SpatialColumn.convert_to_geometry("+
|
139
|
-
"#{var_name_},
|
143
|
+
"#{var_name_}, ::ActiveRecord::ConnectionAdapters::PostGISAdapter::SpatialColumn::"+
|
144
|
+
"FACTORY_SETTINGS_CACHE[#{@factory_settings.object_id}], #{@table_name.inspect}, "+
|
140
145
|
"#{name.inspect}, #{@geographic ? 'true' : 'false'}, #{@srid.inspect}, "+
|
141
146
|
"#{@has_z ? 'true' : 'false'}, #{@has_m ? 'true' : 'false'})"
|
142
147
|
else
|
143
148
|
super
|
144
149
|
end
|
145
150
|
end
|
146
|
-
|
147
|
-
|
151
|
+
|
152
|
+
|
148
153
|
private
|
149
|
-
|
150
|
-
|
154
|
+
|
155
|
+
|
151
156
|
def simplified_type(sql_type_)
|
152
157
|
sql_type_ =~ /geography|geometry|point|linestring|polygon/i ? :spatial : super
|
153
158
|
end
|
154
|
-
|
155
|
-
|
159
|
+
|
160
|
+
|
156
161
|
def self.convert_to_geometry(input_, factory_settings_, table_name_, column_, geographic_, srid_, has_z_, has_m_)
|
157
162
|
if srid_
|
158
163
|
constraints_ = {:geographic => geographic_, :has_z_coordinate => has_z_,
|
@@ -180,15 +185,15 @@ module ActiveRecord
|
|
180
185
|
nil
|
181
186
|
end
|
182
187
|
end
|
183
|
-
|
184
|
-
|
188
|
+
|
189
|
+
|
185
190
|
end
|
186
|
-
|
187
|
-
|
191
|
+
|
192
|
+
|
188
193
|
end
|
189
|
-
|
194
|
+
|
190
195
|
end
|
191
|
-
|
196
|
+
|
192
197
|
end
|
193
198
|
|
194
199
|
# :startdoc:
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# PostGIS adapter for ActiveRecord
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010 Daniel Azuma
|
7
|
-
#
|
6
|
+
# Copyright 2010-2012 Daniel Azuma
|
7
|
+
#
|
8
8
|
# All rights reserved.
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# Redistribution and use in source and binary forms, with or without
|
11
11
|
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# * Redistributions of source code must retain the above copyright notice,
|
14
14
|
# this list of conditions and the following disclaimer.
|
15
15
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
@@ -18,7 +18,7 @@
|
|
18
18
|
# * Neither the name of the copyright holder, nor the names of any other
|
19
19
|
# contributors to this software, may be used to endorse or promote products
|
20
20
|
# derived from this software without specific prior written permission.
|
21
|
-
#
|
21
|
+
#
|
22
22
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
23
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
24
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
@@ -37,14 +37,14 @@
|
|
37
37
|
# :stopdoc:
|
38
38
|
|
39
39
|
module ActiveRecord
|
40
|
-
|
40
|
+
|
41
41
|
module ConnectionAdapters
|
42
|
-
|
42
|
+
|
43
43
|
module PostGISAdapter
|
44
|
-
|
45
|
-
|
44
|
+
|
45
|
+
|
46
46
|
class SpatialTableDefinition < ConnectionAdapters::TableDefinition
|
47
|
-
|
47
|
+
|
48
48
|
def column(name_, type_, options_={})
|
49
49
|
if (info_ = @base.spatial_column_constructor(type_.to_sym))
|
50
50
|
type_ = options_[:type] || info_[:type] || type_
|
@@ -71,74 +71,74 @@ module ActiveRecord
|
|
71
71
|
end
|
72
72
|
self
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
def to_sql
|
76
76
|
@columns.find_all{ |c_| !c_.respond_to?(:geographic?) || c_.geographic? }.map{ |c_| c_.to_sql } * ', '
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
def non_geographic_spatial_columns
|
80
80
|
@columns.find_all{ |c_| c_.respond_to?(:geographic?) && !c_.geographic? }
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
end
|
84
|
-
|
85
|
-
|
84
|
+
|
85
|
+
|
86
86
|
module SpatialColumnDefinitionMethods
|
87
|
-
|
87
|
+
|
88
88
|
def spatial_type
|
89
89
|
@spatial_type
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
def geographic?
|
93
93
|
@geographic
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
def srid
|
97
97
|
@srid ? @srid.to_i : (geographic? ? 4326 : -1)
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
def has_z?
|
101
101
|
@has_z
|
102
102
|
end
|
103
|
-
|
103
|
+
|
104
104
|
def has_m?
|
105
105
|
@has_m
|
106
106
|
end
|
107
|
-
|
107
|
+
|
108
108
|
def set_geographic(value_)
|
109
109
|
@geographic = value_ ? true : false
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
def set_spatial_type(value_)
|
113
113
|
@spatial_type = value_.to_s
|
114
114
|
end
|
115
|
-
|
115
|
+
|
116
116
|
def set_srid(value_)
|
117
117
|
@srid = value_
|
118
118
|
end
|
119
|
-
|
119
|
+
|
120
120
|
def set_has_z(value_)
|
121
121
|
@has_z = value_ ? true : false
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
def set_has_m(value_)
|
125
125
|
@has_m = value_ ? true : false
|
126
126
|
end
|
127
|
-
|
127
|
+
|
128
128
|
def sql_type
|
129
129
|
type_ = spatial_type.upcase.gsub('_', '')
|
130
130
|
type_ << 'Z' if has_z?
|
131
131
|
type_ << 'M' if has_m?
|
132
132
|
"GEOGRAPHY(#{type_},#{srid})"
|
133
133
|
end
|
134
|
-
|
134
|
+
|
135
135
|
end
|
136
|
-
|
137
|
-
|
136
|
+
|
137
|
+
|
138
138
|
end
|
139
|
-
|
139
|
+
|
140
140
|
end
|
141
|
-
|
141
|
+
|
142
142
|
end
|
143
143
|
|
144
144
|
# :startdoc:
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# PostGIS adapter for ActiveRecord
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010 Daniel Azuma
|
7
|
-
#
|
6
|
+
# Copyright 2010-2012 Daniel Azuma
|
7
|
+
#
|
8
8
|
# All rights reserved.
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# Redistribution and use in source and binary forms, with or without
|
11
11
|
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# * Redistributions of source code must retain the above copyright notice,
|
14
14
|
# this list of conditions and the following disclaimer.
|
15
15
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
@@ -18,7 +18,7 @@
|
|
18
18
|
# * Neither the name of the copyright holder, nor the names of any other
|
19
19
|
# contributors to this software, may be used to endorse or promote products
|
20
20
|
# derived from this software without specific prior written permission.
|
21
|
-
#
|
21
|
+
#
|
22
22
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
23
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
24
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
@@ -41,22 +41,22 @@ end
|
|
41
41
|
|
42
42
|
|
43
43
|
module ActiveRecord
|
44
|
-
|
44
|
+
|
45
45
|
module ConnectionAdapters
|
46
|
-
|
46
|
+
|
47
47
|
module PostGISAdapter
|
48
|
-
|
49
|
-
|
48
|
+
|
49
|
+
|
50
50
|
# Current version of PostGISAdapter as a frozen string
|
51
51
|
VERSION_STRING = ::File.read(::File.dirname(__FILE__)+'/../../../../Version').strip.freeze
|
52
|
-
|
52
|
+
|
53
53
|
# Current version of PostGISAdapter as a Versionomy object, if the
|
54
54
|
# Versionomy gem is available; otherwise equal to VERSION_STRING.
|
55
55
|
VERSION = defined?(::Versionomy) ? ::Versionomy.parse(VERSION_STRING) : VERSION_STRING
|
56
|
-
|
57
|
-
|
56
|
+
|
57
|
+
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# Railtie for PostGIS adapter
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010 Daniel Azuma
|
7
|
-
#
|
6
|
+
# Copyright 2010-2012 Daniel Azuma
|
7
|
+
#
|
8
8
|
# All rights reserved.
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# Redistribution and use in source and binary forms, with or without
|
11
11
|
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# * Redistributions of source code must retain the above copyright notice,
|
14
14
|
# this list of conditions and the following disclaimer.
|
15
15
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
@@ -18,7 +18,7 @@
|
|
18
18
|
# * Neither the name of the copyright holder, nor the names of any other
|
19
19
|
# contributors to this software, may be used to endorse or promote products
|
20
20
|
# derived from this software without specific prior written permission.
|
21
|
-
#
|
21
|
+
#
|
22
22
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
23
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
24
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|