ar-postgis 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Documentation.rdoc +14 -14
- data/History.rdoc +4 -141
- data/README.rdoc +31 -32
- data/lib/active_record/connection_adapters/postgis_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/postgis_adapter/rails4/main_adapter.rb +1 -8
- data/lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_column.rb +4 -5
- data/lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_table_definition.rb +5 -1
- data/lib/active_record/connection_adapters/postgis_adapter/shared/common_adapter_methods.rb +4 -2
- data/lib/active_record/connection_adapters/postgis_adapter/version.rb +2 -2
- data/test/tc_ddl.rb +6 -30
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc965a00fa849a283ba134658b89e27b0f2ad410
|
4
|
+
data.tar.gz: 0944b98aab579e3c0daa8e30f58e87019191a666
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bd693e58711cadc4758efb4f003d72897904a38ca1a649303b5f7b7717ebe08cf9168dd994ec44b7d217165320df0b2ccea1b873a0e5cbea45f76e70538152a
|
7
|
+
data.tar.gz: 8ce9ffee24d1eca217f7a350d329915aac797627faf54ae1cc4edf45042c18171610b6b71243ec4a332c373adaabc8e5d405e7a26c8d66c651092c818232a607
|
data/Documentation.rdoc
CHANGED
@@ -6,7 +6,7 @@ This document provides basic how-to information that should help get you started
|
|
6
6
|
* How to set up and configure spatial columns and tables.
|
7
7
|
* How to read, write, and query spatial data.
|
8
8
|
|
9
|
-
This document is part of the distribution for the
|
9
|
+
This document is part of the distribution for the ar-postgis gem. For more information, please visit http://dazuma.github.com/activerecord-postgis-adapter.
|
10
10
|
|
11
11
|
== Installation and Configuration
|
12
12
|
|
@@ -25,13 +25,13 @@ However, older software versions can make for a more involved setup process, so
|
|
25
25
|
|
26
26
|
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.
|
27
27
|
|
28
|
-
To create a new Rails application using
|
28
|
+
To create a new Rails application using ar-postgis, start by using the postgresql adapter.
|
29
29
|
|
30
30
|
rails new my_app --database=postgresql
|
31
31
|
|
32
|
-
Next, add the
|
32
|
+
Next, add the ar-postgis gem to the Gemfile as follows:
|
33
33
|
|
34
|
-
gem '
|
34
|
+
gem 'ar-postgis'
|
35
35
|
|
36
36
|
We also recommend including the "squeel" gem, which comes in very useful for writing spatial queries. Then run <code>bundle install</code> to complete your bundle.
|
37
37
|
|
@@ -55,7 +55,7 @@ For more information, see the PostGIS documentation, or any relevant documentati
|
|
55
55
|
|
56
56
|
If you have an existing Rails app and an existing database that uses Postgres, and you want to add geospatial features, you should follow these steps.
|
57
57
|
|
58
|
-
First, add the
|
58
|
+
First, add the ar-postgis gem to the Gemfile, and update your bundle by running <code>bundle install</code>.
|
59
59
|
|
60
60
|
Next, modify your <code>config/database.yml</code> file to invoke the postgis adapter, as described above. At minimum, you will need to change the <code>adapter</code> field from "postgresql" to "postgis".
|
61
61
|
|
@@ -119,7 +119,7 @@ A spatial database is one that includes a set of data types, functions, tables,
|
|
119
119
|
|
120
120
|
PostGIS is a plugin for PostgreSQL that provides definitions for the objects you need to add to a database to enable geospatial capabilities.
|
121
121
|
|
122
|
-
When you create your Rails database as described above in the section on installation and configuration,
|
122
|
+
When you create your Rails database as described above in the section on installation and configuration, ar-postgis automatically invokes PostGIS to add the appropriate definitions to your database. You can determine whether your database includes the correct definitions by attempting to invoke the POSTGIS_VERSION function:
|
123
123
|
|
124
124
|
SELECT POSTGIS_VERSION(); # succeeds if PostGIS objects are present.
|
125
125
|
|
@@ -129,7 +129,7 @@ Standard spatial databases also include a table called <code>spatial_ref_sys</co
|
|
129
129
|
|
130
130
|
To store spatial data, you must create a column with a spatial type. PostGIS provides a variety of spatial types, including point, linestring, polygon, and different kinds of collections. These types are defined in a standard produced by the Open Geospatial Consortium. Furthermore, you can specify options indicating the coordinate system and number of coordinates for the values you are storing.
|
131
131
|
|
132
|
-
The
|
132
|
+
The ar-postgis extends \ActiveRecord's migration syntax to support these spatial types. The following example creates four spatial columns in a table:
|
133
133
|
|
134
134
|
create_table :my_spatial_table do |t|
|
135
135
|
t.column :shape1, :geometry
|
@@ -147,7 +147,7 @@ The fourth column, "lonlat", has the <code>point</code> type, and accepts only P
|
|
147
147
|
|
148
148
|
The fifth column, "lonlatheight", is a geographic (longitude/latitude) point that also includes a third "z" coordinate that can be used to store height information.
|
149
149
|
|
150
|
-
The following are the data types understood by PostGIS and exposed by
|
150
|
+
The following are the data types understood by PostGIS and exposed by ar-postgis:
|
151
151
|
|
152
152
|
* <tt>:geometry</tt> -- Any geometric type
|
153
153
|
* <tt>:point</tt> -- Point data
|
@@ -173,7 +173,7 @@ The adapter also extends the \ActiveRecord migration syntax for creating spatial
|
|
173
173
|
|
174
174
|
=== Configuring the \ActiveRecord class
|
175
175
|
|
176
|
-
\ActiveRecord's usefulness stems from the way it automatically configures classes based on the database structure and schema. If a column in the database has an integer type, \ActiveRecord automatically casts the data to a Ruby Integer. In the same way, the
|
176
|
+
\ActiveRecord's usefulness stems from the way it automatically configures classes based on the database structure and schema. If a column in the database has an integer type, \ActiveRecord automatically casts the data to a Ruby Integer. In the same way, the ar-postgis automatically casts spatial data to a corresponding RGeo data type.
|
177
177
|
|
178
178
|
However, RGeo offers more "flexibility" in its type system than can be interpreted solely from analyzing the database column. For example, you can configure RGeo objects to exhibit certain behaviors related to their serialization, validation, coordinate system, or computation. These settings are embodied in the RGeo "factory" associated with the object.
|
179
179
|
|
@@ -198,7 +198,7 @@ Here are some examples, given the spatial table defined above:
|
|
198
198
|
|
199
199
|
end
|
200
200
|
|
201
|
-
The <code>rgeo_factory_generator</code> attribute and <code>set_rgeo_factory_for_column</code> method are actually implemented (and documented) in the "rgeo-activerecord" gem, which is a dependency of the
|
201
|
+
The <code>rgeo_factory_generator</code> attribute and <code>set_rgeo_factory_for_column</code> method are actually implemented (and documented) in the "rgeo-activerecord" gem, which is a dependency of the ar-postgis.
|
202
202
|
|
203
203
|
=== Schema Dump and Reload
|
204
204
|
|
@@ -206,7 +206,7 @@ The presence of geospatial data in a database causes some issues with \ActiveRec
|
|
206
206
|
|
207
207
|
Because of this, we recommend the following.
|
208
208
|
|
209
|
-
* Install the PostGIS definitions in a separate schema called "postgis" (as described in the recommended installation procedure above). The
|
209
|
+
* Install the PostGIS definitions in a separate schema called "postgis" (as described in the recommended installation procedure above). The ar-postgis will ignore a schema called "postgis" when dumping the schema, thus omitting the clutter.
|
210
210
|
|
211
211
|
* Set the \ActiveRecord schema format to <code>:ruby</code>, _not_ <code>:sql</code>. The former emits higher level commands that can be interpreted correctly to reproduce the schema. The latter, however, emits low level SQL, which loses information such as the fact that AddGeometryColumn() was originally used to generate a column. Executing a <code>:sql</code> format schema dump will _not_ correctly reproduce the schema.
|
212
212
|
|
@@ -231,7 +231,7 @@ The RGeo factory for the value is determined by how you configured the \ActiveRe
|
|
231
231
|
|
232
232
|
factory = p.factory # returns a spherical factory
|
233
233
|
|
234
|
-
You can set a spatial attribute by providing an RGeo geometry object, or by providing the WKT string representation of the geometry. If a string is provided, the
|
234
|
+
You can set a spatial attribute by providing an RGeo geometry object, or by providing the WKT string representation of the geometry. If a string is provided, the ar-postgis will attempt to parse it as WKT and set the value accordingly.
|
235
235
|
|
236
236
|
record.lonlat = 'POINT(-122, 47)' # sets the value to the given point
|
237
237
|
|
@@ -239,7 +239,7 @@ If the WKT parsing fails, the value currently will be silently set to nil. In th
|
|
239
239
|
|
240
240
|
record.lonlat = 'POINT(x)' # sets the value to nil
|
241
241
|
|
242
|
-
If you set the value to an RGeo object, the factory needs to match the factory for the attribute. If the factories do not match,
|
242
|
+
If you set the value to an RGeo object, the factory needs to match the factory for the attribute. If the factories do not match, ar-postgis will attempt to cast the value to the correct factory.
|
243
243
|
|
244
244
|
p2 = factory.point(-122, 47) # p2 is a point in a spherical factory
|
245
245
|
record.lonlat = p2 # sets the value to the given point
|
@@ -289,4 +289,4 @@ Note that bounding box queries make sense only in a projected coordinate system;
|
|
289
289
|
|
290
290
|
== License
|
291
291
|
|
292
|
-
https://github.com/
|
292
|
+
https://github.com/ar-postgis/ar-postgis/LICENSE.txt
|
data/History.rdoc
CHANGED
@@ -1,147 +1,10 @@
|
|
1
1
|
=== 0.7.0
|
2
2
|
|
3
|
+
* Rename gem to ar-postgis
|
3
4
|
* Require ruby 2.0
|
4
|
-
* Require ActiveRecord 4.
|
5
|
+
* Require ActiveRecord 4.1
|
5
6
|
* Drop JRuby support
|
6
7
|
|
7
|
-
===
|
8
|
+
=== activerecord-postgis-adapter
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
=== 0.6.4 / 2013-05-28
|
12
|
-
|
13
|
-
* Fixed a crash with array conversions in Rails 4. (Contributed by Christopher Bull)
|
14
|
-
* The gis setup task was broken in any Rails other than 3.2.x. Fixed (I think). (Reports by Rupert de Guzman and slbug)
|
15
|
-
* Raise a more useful exception for the (as yet) unsupported combination of Rails 4 and JRuby.
|
16
|
-
|
17
|
-
=== 0.6.3 / 2013-05-04
|
18
|
-
|
19
|
-
* Several fixes for compatibility with changes to Rails 4.0.0 rc1. (Reports by slbug and Victor Costan)
|
20
|
-
* Rails 3 rake tasks properly set PGUSER when appropriate. (Pull request by Mitin Pavel)
|
21
|
-
* Fixed a nil exception on some Rails 4 migrations. (Pull request by ivanfoong and Victor Costan)
|
22
|
-
|
23
|
-
=== 0.6.2 / 2013-03-08
|
24
|
-
|
25
|
-
* The PostGIS setup now properly connects as the superuser. (Reported by Adam Trilling)
|
26
|
-
* Fix database setup rake tasks under jruby/jdbc adapter. (Pull request by Nick Muerdter)
|
27
|
-
* Drop table no longer tries to modify the geometry_columns view under PostGIS 2.0.
|
28
|
-
* The Rakefile is now compatible with RubyGems 2.0.
|
29
|
-
|
30
|
-
=== 0.6.1 / 2013-02-28
|
31
|
-
|
32
|
-
* Fixed some gem loading issues.
|
33
|
-
|
34
|
-
=== 0.6.0 / 2013-02-28
|
35
|
-
|
36
|
-
* Experimental support for the recently released Rails 4.0 beta.
|
37
|
-
* Documentation improvements.
|
38
|
-
|
39
|
-
=== 0.5.1 / 2013-02-04
|
40
|
-
|
41
|
-
* Database creation properly treats geometry_columns as a view when setting owner. (Pull request by hendrikstier)
|
42
|
-
* Provide rake db:gis:setup task. (Pull request by Cody Russell)
|
43
|
-
* Modifications for compatibility with postgres_ext. (Pull request by legendetm)
|
44
|
-
* SpatialTableDefinition properly subclasses the Postgres-specific table definition class, if available. (Pull request by Joe Noon)
|
45
|
-
* Database creation script no longer fails if the username includes weird characters. (Contributed by Toms Mikoss)
|
46
|
-
* Updates for compatibility with jdbc-postgres 9.2.1002.1
|
47
|
-
|
48
|
-
=== 0.5.0 / 2012-12-12
|
49
|
-
|
50
|
-
Thanks to the many who have submitted pull requests. A bunch of them are in this release. Special thanks to Nick Muerdter, who succeeded in porting the adapter to work with the JDBC Postgres adapter in JRuby, and also got Travis up and running for the project.
|
51
|
-
|
52
|
-
* Add JRuby compatibility with the activerecord-jdbcpostgresql-adapter gem. (Pull request by Nick Muerdter)
|
53
|
-
* Allow WKT to be to be specified as a string-like object rather than having to be a String. (Pull request by Bryan Larsen)
|
54
|
-
* Ignore postgis_topology tables 'layer' and 'topology' in rake db:schema:dump. (Pull request by Greg Phillips)
|
55
|
-
* Create schemas specified in schema_search_path only if they don't exist. (Pull request by legendetm)
|
56
|
-
* Force the postgis_topology extension be created in the topology schema. (Pull request by Dimitri Roche)
|
57
|
-
* Specifically set the ownership of the postgis related tables to the regular user. (Pull request by corneverbruggen)
|
58
|
-
* The gemspec no longer includes the timestamp in the version, so that bundler can pull from github. (Reported by corneverbruggen)
|
59
|
-
* Update tests for PostGIS 2.0 compatibility.
|
60
|
-
* Travis-CI integration. (Pull request by Nick Muerdter)
|
61
|
-
* Add a missing srid in the Readme. (Pull request by gouthamvel)
|
62
|
-
* Readme clarifies that BoundingBox objects can be used in a query only for projected coordinate systems. (Reported by Tee Parham)
|
63
|
-
* Update URLs to point to new website.
|
64
|
-
|
65
|
-
=== 0.4.3 / 2012-04-13
|
66
|
-
|
67
|
-
* Rake tasks failed on Rails 3.0.x because of an issue with rgeo-activerecord pre-0.4.5. Now we require the fixed version.
|
68
|
-
|
69
|
-
=== 0.4.2 / 2012-04-12
|
70
|
-
|
71
|
-
* Support the db:structure:load rake task in recent versions of Rails.
|
72
|
-
* Support installing PostGIS via the PostgreSQL extension mechanism (requires at least PostGIS 2.0 and PostgreSQL 9.1).
|
73
|
-
* Support bounding boxes in queries (useful for "window" queries such as finding objects to display in a map region).
|
74
|
-
* Fix some issues determine the correct default value for spatial columns.
|
75
|
-
|
76
|
-
=== 0.4.1 / 2012-02-22
|
77
|
-
|
78
|
-
* Some compatibility fixes for Rails 3.2. (Reported by Ryan Williams with implementation help from Radek Paviensky.)
|
79
|
-
* Now requires rgeo-activerecord 0.4.3.
|
80
|
-
|
81
|
-
=== 0.4.0 / 2011-08-15
|
82
|
-
|
83
|
-
* Various fixes for Rails 3.1 compatibility.
|
84
|
-
* Now requires rgeo-activerecord 0.4.0.
|
85
|
-
* INCOMPATIBLE CHANGE: simple queries (e.g. MyClass.where(:latlon => my_point)) use an objective rather than spatial equality test. Earlier versions transformed this form to use st_equals, but now if you need to test for spatial equality, you'll need to call st_equals explicitly. I'm still evaluating which direction we want to go with this in the future, but we may be stuck with the current behavior because the hack required to transform these queries to use spatial equality was egregious and broke in Rails 3.1 with no clear workaround.
|
86
|
-
|
87
|
-
=== 0.3.6 / 2011-06-21
|
88
|
-
|
89
|
-
* Require latest rgeo-activerecord to get some fixes.
|
90
|
-
* Note PostgreSQL 9 requirement in the README. (Reported by Samuel Cochran)
|
91
|
-
* Now doesn't throw exceptions if an RGeo cast fails when setting an attribute.
|
92
|
-
|
93
|
-
=== 0.3.5 / 2011-04-12
|
94
|
-
|
95
|
-
* The .gemspec was missing the databases.rake file. Fixed.
|
96
|
-
|
97
|
-
=== 0.3.4 / 2011-04-11
|
98
|
-
|
99
|
-
* A .gemspec file is now available for gem building and bundler git integration.
|
100
|
-
|
101
|
-
=== 0.3.3 / 2011-02-28
|
102
|
-
|
103
|
-
* INCOMPATIBLE CHANGE: the default SRID for non-geography columns is now -1, rather than 4326. (Geography columns still default to 4326.)
|
104
|
-
* 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)
|
105
|
-
* Now requires rgeo-activerecord 0.3.1 (which brings a critical fix involving declaring multiple spatial columns in a migration).
|
106
|
-
|
107
|
-
=== 0.3.2 / 2011-02-11
|
108
|
-
|
109
|
-
* 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.
|
110
|
-
* Database creation tasks automatically create all schemas listed in the schema search path.
|
111
|
-
|
112
|
-
=== 0.3.1 / 2011-02-01
|
113
|
-
|
114
|
-
* Fixed a syntax error that prevented the adapter from loading on Ruby 1.8. Whoops. (Reported by miguelperez)
|
115
|
-
|
116
|
-
=== 0.3.0 / 2011-01-26
|
117
|
-
|
118
|
-
* Reworked type and constraint handling, which should result in a large number of bug fixes, especially related to schema dumps.
|
119
|
-
* Experimental support for complex spatial queries. (Requires Arel 2.1, which is expected to be released with Rails 3.1.)
|
120
|
-
* The path to the Railtie is now different (see the README), though a compatibility wrapper has been left in the old location.
|
121
|
-
* Getting index information from the ActiveRecord class now properly recognizes spatial-ness.
|
122
|
-
* Reorganized the code a bit for better clarity.
|
123
|
-
|
124
|
-
=== 0.2.3 / 2011-01-06
|
125
|
-
|
126
|
-
* Many of ActiveRecord's rake tasks weren't working because they need to know about every adapter explicitly. I hesitate to call this "fixed" since I see it as a problem in ActiveRecord, but we now at least have a workaround so the rake tasks will run properly. (Reported by Tad Thorley.)
|
127
|
-
* Dumping schema.rb now omits the PostGIS internal tables.
|
128
|
-
* Added a new configuration parameter pointing to the script directory, for rake db:create.
|
129
|
-
* If the "postgis" schema is included in the schema search path, it is used as a container for the PostGIS internal definitions when running rake db:create. Furthermore, that schema is omitted when dumping the structure.sql. This should eliminate all the PostGIS internal cruft from SQL structure dumps, and also eliminate the errors that would appear when rebuilding a test database because the PostGIS internals would get applied twice.
|
130
|
-
|
131
|
-
=== 0.2.2 / 2010-12-27
|
132
|
-
|
133
|
-
* Support for basic spatial equality queries. e.g. constructs such as:
|
134
|
-
MyClass.where(:geom_column => factory.point(1, 2))
|
135
|
-
MyClass.where(:geom_column => 'POINT(1 2)')
|
136
|
-
* Fixed an exception when adding spatial columns where the column name is specified as a symbol.
|
137
|
-
|
138
|
-
=== 0.2.1 / 2010-12-15
|
139
|
-
|
140
|
-
* Provides meta-information to RGeo 0.2.2 or later to support access to PostGIS's spatial reference system table.
|
141
|
-
|
142
|
-
=== 0.2.0 / 2010-12-07
|
143
|
-
|
144
|
-
* Initial public alpha release. Spun activerecord-postgis-adapter off from the core rgeo gem.
|
145
|
-
* You can now set the factory for a specific column by name.
|
146
|
-
|
147
|
-
For earlier history, see the History file for the rgeo gem.
|
10
|
+
see https://github.com/dazuma/activerecord-postgis-adapter for previous history
|
data/README.rdoc
CHANGED
@@ -1,22 +1,29 @@
|
|
1
1
|
== PostGIS \ActiveRecord Adapter
|
2
2
|
|
3
|
-
The
|
3
|
+
The ar-postgis gem provides access to features of the PostGIS geospatial database from \ActiveRecord.
|
4
|
+
Technically, it extends the standard postgresql adapter to provide support for the spatial data types and features
|
5
|
+
added by the PostGIS extension. It uses the {RGeo}[http://github.com/dazuma/rgeo] library to represent spatial data
|
6
|
+
in Ruby.
|
4
7
|
|
5
8
|
Original project: https://github.com/dazuma/activerecord-postgis-adapter/
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
This is a brief summary covering how to use activerecord-postgis-adapter. For full documentation, see Documentation.rdoc.
|
10
|
+
For full documentation, see Documentation.rdoc.
|
10
11
|
|
11
12
|
=== Features
|
12
13
|
|
13
|
-
The adapter provides three basic capabilities
|
14
|
+
The adapter provides three basic capabilities:
|
14
15
|
|
15
|
-
First, it provides *spatial migrations*. It extends the \ActiveRecord migration syntax to support creating
|
16
|
+
First, it provides *spatial migrations*. It extends the \ActiveRecord migration syntax to support creating
|
17
|
+
spatially-typed columns and spatial indexes. You can control the various PostGIS-provided attributes such as srid,
|
18
|
+
dimension, and geographic vs geometric math.
|
16
19
|
|
17
|
-
Second, it recognizes spatial types and casts them properly to RGeo geometry objects. The adapter can configure these
|
20
|
+
Second, it recognizes spatial types and casts them properly to RGeo geometry objects. The adapter can configure these
|
21
|
+
objects automatically based on the srid and dimension in the database table, or you can tell it to convert the data to
|
22
|
+
a different form. You can also set attribute data using WKT format.
|
18
23
|
|
19
|
-
Third, it lets you include simple spatial data in queries. WKT format data and RGeo objects can be embedded in where
|
24
|
+
Third, it lets you include simple spatial data in queries. WKT format data and RGeo objects can be embedded in where
|
25
|
+
clauses. If you include the Squeel gem, the adapter also supports advanced queries utilizing the standard SQL spatial
|
26
|
+
function set.
|
20
27
|
|
21
28
|
=== Requirements
|
22
29
|
|
@@ -24,25 +31,27 @@ The adapter has the following requirements.
|
|
24
31
|
|
25
32
|
* Ruby 2.0.0 or later.
|
26
33
|
* PostgreSQL 9.0 or later.
|
27
|
-
* PostGIS 2.0
|
34
|
+
* PostGIS 2.0 or later.
|
28
35
|
* ActiveRecord 4.0.2 or later.
|
29
|
-
* rgeo and rgeo-
|
30
|
-
|
31
|
-
=== Installation and Configuration
|
36
|
+
* rgeo and rgeo-ar.
|
32
37
|
|
33
|
-
|
38
|
+
=== Install
|
34
39
|
|
35
|
-
|
40
|
+
Add it to your Gemfile:
|
36
41
|
|
37
|
-
|
42
|
+
gem 'ar-postgis'
|
38
43
|
|
39
|
-
|
44
|
+
or install it as a gem:
|
40
45
|
|
41
|
-
gem install
|
46
|
+
gem install ar-postgis
|
42
47
|
|
43
|
-
Please note that this adapter uses the rgeo gem, which may have additional dependencies. Please see the \README
|
48
|
+
Please note that this adapter uses the rgeo gem, which may have additional dependencies. Please see the \README
|
49
|
+
documentation for rgeo for more information.
|
44
50
|
|
45
|
-
Once you have installed the adapter, you'll need to edit your config/database.yml to call for it. At minimum, this
|
51
|
+
Once you have installed the adapter, you'll need to edit your config/database.yml to call for it. At minimum, this
|
52
|
+
means changing the adapter name from "postgresql" to "postgis". It may also require other settings to ensure that
|
53
|
+
other functions (such as rake test) continue to work as expected. We recommend reading the Configuration section
|
54
|
+
in the Documentation.rdoc file carefully before starting to use this adapter.
|
46
55
|
|
47
56
|
== Development and Support
|
48
57
|
|
@@ -50,27 +59,17 @@ Original project info:
|
|
50
59
|
|
51
60
|
\Documentation is available at http://dazuma.github.com/activerecord-postgis-adapter/rdoc
|
52
61
|
|
53
|
-
Source code is hosted on Github at http://github.com/dazuma/activerecord-postgis-adapter
|
54
|
-
|
55
|
-
Contributions are welcome. Fork the project on Github.
|
56
|
-
|
57
|
-
Report bugs on Github issues at http://github.org/dazuma/activerecord-postgis-adapter/issues
|
58
|
-
|
59
62
|
Support available on the rgeo-users google group at http://groups.google.com/group/rgeo-users
|
60
63
|
|
61
|
-
Contact the author at dazuma at gmail dot com.
|
62
|
-
|
63
64
|
== Acknowledgments
|
64
65
|
|
65
|
-
The PostGIS Adapter and its supporting libraries (including RGeo)
|
66
|
+
The PostGIS Adapter and its supporting libraries (including RGeo) were originally
|
66
67
|
written by Daniel Azuma (http://www.daniel-azuma.com).
|
67
68
|
|
68
|
-
Development
|
69
|
+
Development was supported by Pirq. (http://pirq.com).
|
69
70
|
|
70
71
|
This adapter implementation owes some debt to the spatial_adapter plugin
|
71
|
-
(http://github.com/fragility/spatial_adapter).
|
72
|
-
different design decisions for this adapter, studying the spatial_adapter
|
73
|
-
source gave us a head start on the implementation.
|
72
|
+
(http://github.com/fragility/spatial_adapter).
|
74
73
|
|
75
74
|
== License
|
76
75
|
|
@@ -112,13 +112,6 @@ module ActiveRecord # :nodoc:
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
-
def drop_table(table_name_, *options_)
|
116
|
-
if postgis_lib_version.to_s.split('.').first.to_i == 1
|
117
|
-
execute("DELETE from geometry_columns where f_table_name='#{quote_string(table_name_.to_s)}'")
|
118
|
-
end
|
119
|
-
super
|
120
|
-
end
|
121
|
-
|
122
115
|
def add_column(table_name_, column_name_, type_, options_={})
|
123
116
|
table_name_ = table_name_.to_s
|
124
117
|
column_name_ = column_name_.to_s
|
@@ -134,7 +127,7 @@ module ActiveRecord # :nodoc:
|
|
134
127
|
type_ = (options_[:type] || info_[:type] || type_).to_s.gsub('_', '').upcase
|
135
128
|
has_z_ = options_[:has_z]
|
136
129
|
has_m_ = options_[:has_m]
|
137
|
-
srid_ = (options_[:srid] ||
|
130
|
+
srid_ = (options_[:srid] || PostGISAdapter::DEFAULT_SRID).to_i
|
138
131
|
if options_[:geographic]
|
139
132
|
type_ << 'Z' if has_z_
|
140
133
|
type_ << 'M' if has_m_
|
@@ -11,14 +11,13 @@ module ActiveRecord # :nodoc:
|
|
11
11
|
def initialize(factory_settings_, table_name_, name_, default_, oid_type_, sql_type_=nil, null_=true, opts_=nil)
|
12
12
|
@factory_settings = factory_settings_
|
13
13
|
@table_name = table_name_
|
14
|
-
@geographic = sql_type_ =~ /geography/i
|
14
|
+
@geographic = !!(sql_type_ =~ /geography/i)
|
15
15
|
if opts_
|
16
16
|
# This case comes from an entry in the geometry_columns table
|
17
|
-
@geometric_type = ::RGeo::ActiveRecord.geometric_type_from_name(opts_[:type]) ||
|
18
|
-
::RGeo::Feature::Geometry
|
17
|
+
@geometric_type = ::RGeo::ActiveRecord.geometric_type_from_name(opts_[:type]) || ::RGeo::Feature::Geometry
|
19
18
|
@srid = opts_[:srid].to_i
|
20
|
-
@has_z = opts_[:has_z]
|
21
|
-
@has_m = opts_[:has_m]
|
19
|
+
@has_z = !!opts_[:has_z]
|
20
|
+
@has_m = !!opts_[:has_m]
|
22
21
|
elsif @geographic
|
23
22
|
# Geographic type information is embedded in the SQL type
|
24
23
|
@geometric_type = ::RGeo::Feature::Geometry
|
@@ -5,6 +5,9 @@ module ActiveRecord # :nodoc:
|
|
5
5
|
:geography => {:type => 'geometry', :geographic => true}
|
6
6
|
)
|
7
7
|
|
8
|
+
# http://postgis.17.x6.nabble.com/Default-SRID-td5001115.html
|
9
|
+
DEFAULT_SRID = 0
|
10
|
+
|
8
11
|
module CommonAdapterMethods # :nodoc:
|
9
12
|
def set_rgeo_factory_settings(factory_settings_)
|
10
13
|
@rgeo_factory_settings = factory_settings_
|
@@ -22,9 +25,8 @@ module ActiveRecord # :nodoc:
|
|
22
25
|
@postgis_lib_version ||= select_value("SELECT PostGIS_Lib_Version()")
|
23
26
|
end
|
24
27
|
|
25
|
-
# http://postgis.17.x6.nabble.com/Default-SRID-td5001115.html
|
26
28
|
def default_srid
|
27
|
-
|
29
|
+
DEFAULT_SRID
|
28
30
|
end
|
29
31
|
|
30
32
|
def srs_database_columns
|
data/test/tc_ddl.rb
CHANGED
@@ -1,21 +1,16 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
2
|
require 'rgeo/active_record/adapter_test_helper'
|
3
3
|
|
4
|
-
|
5
4
|
module RGeo
|
6
5
|
module ActiveRecord # :nodoc:
|
7
6
|
module PostGISAdapter # :nodoc:
|
8
7
|
module Tests # :nodoc:
|
9
|
-
|
10
8
|
class TestDDL < ::MiniTest::Test # :nodoc:
|
11
|
-
|
12
9
|
DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database.yml'
|
13
10
|
OVERRIDE_DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database_local.yml'
|
14
11
|
include AdapterTestHelper
|
15
12
|
|
16
13
|
define_test_methods do
|
17
|
-
|
18
|
-
|
19
14
|
def test_create_simple_geometry
|
20
15
|
klass_ = create_ar_class
|
21
16
|
klass_.connection.create_table(:spatial_test) do |t_|
|
@@ -26,13 +21,12 @@ module RGeo
|
|
26
21
|
assert_equal(::RGeo::Feature::Geometry, col_.geometric_type)
|
27
22
|
assert_equal(true, col_.has_spatial_constraints?)
|
28
23
|
assert_equal(false, col_.geographic?)
|
29
|
-
assert_equal(
|
24
|
+
assert_equal(0, col_.srid)
|
30
25
|
assert(klass_.cached_attributes.include?('latlon'))
|
31
26
|
klass_.connection.drop_table(:spatial_test)
|
32
27
|
assert_equal(0, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
33
28
|
end
|
34
29
|
|
35
|
-
|
36
30
|
# no_constraints no longer supported in PostGIS 2.0
|
37
31
|
def _test_create_no_constraints_geometry
|
38
32
|
klass_ = create_ar_class
|
@@ -50,7 +44,6 @@ module RGeo
|
|
50
44
|
assert_equal(0, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
51
45
|
end
|
52
46
|
|
53
|
-
|
54
47
|
def test_create_simple_geography
|
55
48
|
klass_ = create_ar_class
|
56
49
|
klass_.connection.create_table(:spatial_test) do |t_|
|
@@ -65,7 +58,6 @@ module RGeo
|
|
65
58
|
assert_equal(0, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
66
59
|
end
|
67
60
|
|
68
|
-
|
69
61
|
def test_create_point_geometry
|
70
62
|
klass_ = create_ar_class
|
71
63
|
klass_.connection.create_table(:spatial_test) do |t_|
|
@@ -75,7 +67,6 @@ module RGeo
|
|
75
67
|
assert(klass_.cached_attributes.include?('latlon'))
|
76
68
|
end
|
77
69
|
|
78
|
-
|
79
70
|
def test_create_geometry_with_index
|
80
71
|
klass_ = create_ar_class
|
81
72
|
klass_.connection.create_table(:spatial_test) do |t_|
|
@@ -87,7 +78,6 @@ module RGeo
|
|
87
78
|
assert(klass_.connection.indexes(:spatial_test).last.spatial)
|
88
79
|
end
|
89
80
|
|
90
|
-
|
91
81
|
def test_add_geometry_column
|
92
82
|
klass_ = create_ar_class
|
93
83
|
klass_.connection.create_table(:spatial_test) do |t_|
|
@@ -100,7 +90,7 @@ module RGeo
|
|
100
90
|
assert_equal(2, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
101
91
|
cols_ = klass_.columns
|
102
92
|
assert_equal(::RGeo::Feature::Geometry, cols_[-3].geometric_type)
|
103
|
-
assert_equal(
|
93
|
+
assert_equal(0, cols_[-3].srid)
|
104
94
|
assert_equal(true, cols_[-3].has_spatial_constraints?)
|
105
95
|
assert_equal(::RGeo::Feature::Point, cols_[-2].geometric_type)
|
106
96
|
assert_equal(4326, cols_[-2].srid)
|
@@ -110,7 +100,6 @@ module RGeo
|
|
110
100
|
assert_equal(false, cols_[-1].has_spatial_constraints?)
|
111
101
|
end
|
112
102
|
|
113
|
-
|
114
103
|
# no_constraints no longer supported in PostGIS 2.0
|
115
104
|
def _test_add_no_constraints_geometry_column
|
116
105
|
klass_ = create_ar_class
|
@@ -124,7 +113,7 @@ module RGeo
|
|
124
113
|
assert_equal(1, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
125
114
|
cols_ = klass_.columns
|
126
115
|
assert_equal(::RGeo::Feature::Geometry, cols_[-3].geometric_type)
|
127
|
-
assert_equal(
|
116
|
+
assert_equal(0, cols_[-3].srid)
|
128
117
|
assert_equal(true, cols_[-3].has_spatial_constraints?)
|
129
118
|
assert_equal(::RGeo::Feature::Geometry, cols_[-2].geometric_type)
|
130
119
|
assert_nil(cols_[-2].srid)
|
@@ -134,7 +123,6 @@ module RGeo
|
|
134
123
|
assert_equal(false, cols_[-1].has_spatial_constraints?)
|
135
124
|
end
|
136
125
|
|
137
|
-
|
138
126
|
def test_add_geography_column
|
139
127
|
klass_ = create_ar_class
|
140
128
|
klass_.connection.create_table(:spatial_test) do |t_|
|
@@ -147,7 +135,7 @@ module RGeo
|
|
147
135
|
assert_equal(1, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
148
136
|
cols_ = klass_.columns
|
149
137
|
assert_equal(::RGeo::Feature::Geometry, cols_[-3].geometric_type)
|
150
|
-
assert_equal(
|
138
|
+
assert_equal(0, cols_[-3].srid)
|
151
139
|
assert_equal(true, cols_[-3].has_spatial_constraints?)
|
152
140
|
assert_equal(::RGeo::Feature::Point, cols_[-2].geometric_type)
|
153
141
|
assert_equal(4326, cols_[-2].srid)
|
@@ -157,7 +145,6 @@ module RGeo
|
|
157
145
|
assert_equal(false, cols_[-1].has_spatial_constraints?)
|
158
146
|
end
|
159
147
|
|
160
|
-
|
161
148
|
def test_drop_geometry_column
|
162
149
|
klass_ = create_ar_class
|
163
150
|
klass_.connection.create_table(:spatial_test) do |t_|
|
@@ -171,11 +158,10 @@ module RGeo
|
|
171
158
|
cols_ = klass_.columns
|
172
159
|
assert_equal(::RGeo::Feature::Geometry, cols_[-1].geometric_type)
|
173
160
|
assert_equal('latlon', cols_[-1].name)
|
174
|
-
assert_equal(
|
161
|
+
assert_equal(0, cols_[-1].srid)
|
175
162
|
assert_equal(false, cols_[-1].geographic?)
|
176
163
|
end
|
177
164
|
|
178
|
-
|
179
165
|
def test_drop_geography_column
|
180
166
|
klass_ = create_ar_class
|
181
167
|
klass_.connection.create_table(:spatial_test) do |t_|
|
@@ -196,7 +182,6 @@ module RGeo
|
|
196
182
|
assert_equal(false, cols_[-2].geographic?)
|
197
183
|
end
|
198
184
|
|
199
|
-
|
200
185
|
def test_create_simple_geometry_using_shortcut
|
201
186
|
klass_ = create_ar_class
|
202
187
|
klass_.connection.create_table(:spatial_test) do |t_|
|
@@ -206,13 +191,12 @@ module RGeo
|
|
206
191
|
col_ = klass_.columns.last
|
207
192
|
assert_equal(::RGeo::Feature::Geometry, col_.geometric_type)
|
208
193
|
assert_equal(false, col_.geographic?)
|
209
|
-
assert_equal(
|
194
|
+
assert_equal(0, col_.srid)
|
210
195
|
assert(klass_.cached_attributes.include?('latlon'))
|
211
196
|
klass_.connection.drop_table(:spatial_test)
|
212
197
|
assert_equal(0, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
213
198
|
end
|
214
199
|
|
215
|
-
|
216
200
|
# no_constraints no longer supported in PostGIS 2.0
|
217
201
|
def _test_create_no_constraints_geometry_using_shortcut
|
218
202
|
klass_ = create_ar_class
|
@@ -229,11 +213,9 @@ module RGeo
|
|
229
213
|
assert_equal(0, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
230
214
|
end
|
231
215
|
|
232
|
-
|
233
216
|
def test_create_simple_geography_using_shortcut
|
234
217
|
klass_ = create_ar_class
|
235
218
|
klass_.connection.create_table(:spatial_test) do |t_|
|
236
|
-
# t_.method_missing(:geometry, 'latlon', :geographic => true)
|
237
219
|
t_.geometry 'latlon', :geographic => true
|
238
220
|
end
|
239
221
|
col_ = klass_.columns.last
|
@@ -244,7 +226,6 @@ module RGeo
|
|
244
226
|
assert_equal(0, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
245
227
|
end
|
246
228
|
|
247
|
-
|
248
229
|
def test_create_point_geometry_using_shortcut
|
249
230
|
klass_ = create_ar_class
|
250
231
|
klass_.connection.create_table(:spatial_test) do |t_|
|
@@ -254,7 +235,6 @@ module RGeo
|
|
254
235
|
assert(klass_.cached_attributes.include?('latlon'))
|
255
236
|
end
|
256
237
|
|
257
|
-
|
258
238
|
def test_create_geometry_with_options
|
259
239
|
klass_ = create_ar_class
|
260
240
|
klass_.connection.create_table(:spatial_test) do |t_|
|
@@ -273,7 +253,6 @@ module RGeo
|
|
273
253
|
assert_equal(0, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
274
254
|
end
|
275
255
|
|
276
|
-
|
277
256
|
def test_create_geometry_using_limit
|
278
257
|
klass_ = create_ar_class
|
279
258
|
klass_.connection.create_table(:spatial_test) do |t_|
|
@@ -292,11 +271,8 @@ module RGeo
|
|
292
271
|
assert_equal(0, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
293
272
|
end
|
294
273
|
|
295
|
-
|
296
274
|
end
|
297
|
-
|
298
275
|
end
|
299
|
-
|
300
276
|
end
|
301
277
|
end
|
302
278
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ar-postgis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Azuma, Tee Parham
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|