activerecord-postgis 0.5.0 → 0.6.0
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.
- checksums.yaml +4 -4
- data/README.md +27 -29
- data/activerecord-postgis.gemspec +3 -2
- data/lib/active_record/connection_adapters/postgis/database_statements.rb +14 -0
- data/lib/active_record/connection_adapters/postgis/railtie.rb +13 -0
- data/lib/active_record/connection_adapters/postgis/version.rb +1 -1
- data/lib/active_record/connection_adapters/postgis.rb +81 -82
- data/lib/activerecord-postgis.rb +2 -0
- metadata +23 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 86b0a720bdf3520ba032d20033a4259e1875bd37ec97e9e517b0b1b1ac647e40
|
|
4
|
+
data.tar.gz: 4c2ff56e23a305ad149fb61b9f84d8742675e62358f80c4cd8708a488c7b3f67
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1a3849e3b5f56491964affeaac36f53317bc6fe1d77557067171b00197b0af5675b5aa090250efe9d083f51bf94e531b2965ed97802e704f4969e3e840cf4485
|
|
7
|
+
data.tar.gz: a4d2916514e25e89fd722567cddd90fe96bbda946c3de5c110018f6d20ad2b3e395049a5c4960bec1d565d03824340b22ed7c8f1bce92f3bbad4f5e6c1fabbba
|
data/README.md
CHANGED
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
|
|
7
7
|
This is the **next-generation PostGIS adapter** that brings PostGIS support to Rails the right way:
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
- **Use standard `postgres://` URLs** - No custom adapter names, no special configuration
|
|
10
|
+
- **No monkey patching** - Clean extensions using Rails 8.1 patterns
|
|
11
|
+
- **No obscure hacks** - Transparent, well-documented implementation
|
|
12
|
+
- **Latest APIs** - Built for Rails 8.1+ and Ruby 3.3+
|
|
13
|
+
- **Zero configuration** - Just add the gem and it works
|
|
14
14
|
|
|
15
15
|
Unlike legacy PostGIS adapters that require custom database URLs, special configurations, and complex setup, this gem **extends the existing PostgreSQL adapter** seamlessly. Your database configuration stays clean and standard.
|
|
16
16
|
|
|
@@ -53,7 +53,7 @@ development:
|
|
|
53
53
|
Create spatial columns using PostGIS types:
|
|
54
54
|
|
|
55
55
|
```ruby
|
|
56
|
-
class CreateLocations < ActiveRecord::Migration[8.
|
|
56
|
+
class CreateLocations < ActiveRecord::Migration[8.1]
|
|
57
57
|
def change
|
|
58
58
|
create_table :locations do |t|
|
|
59
59
|
t.st_point :coordinates, srid: 4326
|
|
@@ -81,14 +81,14 @@ Location.where("ST_Distance(coordinates, ?) < ?", point, 1000)
|
|
|
81
81
|
|
|
82
82
|
# Using parameterized queries (automatically quoted)
|
|
83
83
|
locations_nearby = Location.where(
|
|
84
|
-
"ST_DWithin(coordinates, ?, ?)",
|
|
85
|
-
point,
|
|
84
|
+
"ST_DWithin(coordinates, ?, ?)",
|
|
85
|
+
point,
|
|
86
86
|
1000 # meters
|
|
87
87
|
)
|
|
88
88
|
|
|
89
89
|
# Complex spatial queries
|
|
90
90
|
parks_in_city = Park.where(
|
|
91
|
-
"ST_Within(boundary, ?)",
|
|
91
|
+
"ST_Within(boundary, ?)",
|
|
92
92
|
city_polygon
|
|
93
93
|
)
|
|
94
94
|
```
|
|
@@ -186,28 +186,28 @@ class LocationTest < ActiveSupport::TestCase
|
|
|
186
186
|
point1 = create_point(-5.9, 35.8)
|
|
187
187
|
point2 = create_point(-5.91, 35.81)
|
|
188
188
|
polygon = create_test_polygon
|
|
189
|
-
|
|
189
|
+
|
|
190
190
|
location = Location.create!(coordinates: point1, boundary: polygon)
|
|
191
|
-
|
|
191
|
+
|
|
192
192
|
# Traditional assertions
|
|
193
193
|
assert_spatial_equal point1, location.coordinates
|
|
194
194
|
assert_within_distance point1, point2, 200 # meters
|
|
195
195
|
assert_contains polygon, point1
|
|
196
|
-
|
|
196
|
+
|
|
197
197
|
# New chainable syntax (recommended)
|
|
198
198
|
assert_spatial_column(location.coordinates)
|
|
199
199
|
.has_srid(4326)
|
|
200
200
|
.is_type(:point)
|
|
201
201
|
.is_geographic
|
|
202
|
-
|
|
202
|
+
|
|
203
203
|
assert_spatial_column(location.boundary)
|
|
204
204
|
.is_type(:polygon)
|
|
205
205
|
.has_srid(4326)
|
|
206
206
|
end
|
|
207
|
-
|
|
207
|
+
|
|
208
208
|
def test_3d_geometry
|
|
209
209
|
point_3d = create_point(1.0, 2.0, srid: 4326, z: 10.0)
|
|
210
|
-
|
|
210
|
+
|
|
211
211
|
assert_spatial_column(point_3d)
|
|
212
212
|
.has_z
|
|
213
213
|
.has_srid(4326)
|
|
@@ -237,7 +237,7 @@ end
|
|
|
237
237
|
|
|
238
238
|
**Geometry Factories:**
|
|
239
239
|
- `create_point(x, y, srid: 4326)` - Create test points
|
|
240
|
-
- `create_test_polygon(srid: 4326)` - Create test polygons
|
|
240
|
+
- `create_test_polygon(srid: 4326)` - Create test polygons
|
|
241
241
|
- `create_test_linestring(srid: 4326)` - Create test linestrings
|
|
242
242
|
- `factory(srid: 4326, geographic: false)` - Get geometry factory
|
|
243
243
|
- `geographic_factory(srid: 4326)` - Get geographic factory
|
|
@@ -245,20 +245,18 @@ end
|
|
|
245
245
|
|
|
246
246
|
## Documentation
|
|
247
247
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
- [🚀 Spatial Warfare Manual](docs/SPATIAL_WARFARE.md) - Advanced PostGIS arsenal explained through space combat
|
|
251
|
-
- [🍳 The PostGIS Cookbook](docs/COOKBOOK.md) - Real-world recipes from delivery fleets to geofencing
|
|
248
|
+
- [Spatial Warfare Manual](docs/SPATIAL_WARFARE.md) - Advanced PostGIS arsenal explained through space combat
|
|
249
|
+
- [The PostGIS Cookbook](docs/COOKBOOK.md) - Real-world recipes from delivery fleets to geofencing
|
|
252
250
|
|
|
253
251
|
## Features
|
|
254
252
|
|
|
255
|
-
|
|
256
|
-
- `st_point`, `st_line_string`, `st_polygon`
|
|
253
|
+
**Complete PostGIS Type Support**
|
|
254
|
+
- `st_point`, `st_line_string`, `st_polygon`
|
|
257
255
|
- `st_multi_point`, `st_multi_line_string`, `st_multi_polygon`
|
|
258
256
|
- `st_geometry_collection`, `st_geography`
|
|
259
257
|
- Support for SRID, Z/M dimensions
|
|
260
258
|
|
|
261
|
-
|
|
259
|
+
**Spatial Query Methods**
|
|
262
260
|
- Core methods: `st_distance`, `st_contains`, `st_within`, `st_length`
|
|
263
261
|
- **NEW:** Advanced spatial operations:
|
|
264
262
|
- `<->` (distance_operator) - K-Nearest Neighbor search (blazing fast!)
|
|
@@ -270,13 +268,13 @@ end
|
|
|
270
268
|
- Custom Arel visitor for PostGIS SQL generation
|
|
271
269
|
- Seamless integration with ActiveRecord queries
|
|
272
270
|
|
|
273
|
-
|
|
274
|
-
- Built on Rails 8 patterns
|
|
271
|
+
**Modern Architecture**
|
|
272
|
+
- Built on Rails 8.1 patterns
|
|
275
273
|
- Clean module extensions (no inheritance)
|
|
276
274
|
- Proper type registration and schema dumping
|
|
277
275
|
- Compatible with multi-database setups
|
|
278
276
|
|
|
279
|
-
|
|
277
|
+
**Developer Experience**
|
|
280
278
|
- Standard `postgres://` URLs
|
|
281
279
|
- Works with existing PostgreSQL tools
|
|
282
280
|
- Clear error messages and debugging
|
|
@@ -287,17 +285,17 @@ end
|
|
|
287
285
|
|
|
288
286
|
This gem builds upon the incredible work of many contributors to the Ruby geospatial ecosystem:
|
|
289
287
|
|
|
290
|
-
|
|
288
|
+
**RGeo Ecosystem** - The foundation that makes Ruby geospatial possible:
|
|
291
289
|
- [RGeo](https://github.com/rgeo/rgeo) originally by Daniel Azuma, currently maintained by Keith Doggett (@keithdoggett) and Ulysse Buonomo (@BuonOmo)
|
|
292
290
|
- [RGeo::ActiveRecord](https://github.com/rgeo/rgeo-activerecord) for ActiveRecord integration
|
|
293
291
|
- [RGeo::Proj4](https://github.com/rgeo/rgeo-proj4) for coordinate system transformations
|
|
294
292
|
- Former maintainer Tee Parham and all contributors who built this ecosystem
|
|
295
293
|
|
|
296
|
-
|
|
294
|
+
**PostGIS Pioneers** - Previous PostGIS adapters that paved the way:
|
|
297
295
|
- [activerecord-postgis-adapter](https://github.com/rgeo/activerecord-postgis-adapter) by Daniel Azuma and the RGeo team
|
|
298
296
|
- All the maintainers and contributors who solved spatial data challenges in Rails
|
|
299
297
|
|
|
300
|
-
|
|
298
|
+
**PostGIS & GEOS** - The underlying spatial powerhouses:
|
|
301
299
|
- PostGIS developers for the amazing spatial database extension
|
|
302
300
|
- GEOS contributors for computational geometry
|
|
303
301
|
- PostgreSQL team for the solid foundation
|
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
|
12
12
|
spec.description = spec.summary
|
|
13
13
|
spec.homepage = 'https://github.com/seuros/activerecord-postgis'
|
|
14
14
|
spec.license = 'MIT'
|
|
15
|
-
spec.required_ruby_version = '>= 3.3.0'
|
|
15
|
+
spec.required_ruby_version = '>= 3.3.0', '< 5.0'
|
|
16
16
|
|
|
17
17
|
spec.metadata['homepage_uri'] = spec.homepage
|
|
18
18
|
spec.metadata['source_code_uri'] = spec.homepage
|
|
@@ -22,7 +22,8 @@ Gem::Specification.new do |spec|
|
|
|
22
22
|
spec.files = Dir.glob('{lib}/**/*') + [ gemspec, 'LICENSE.txt', 'README.md' ]
|
|
23
23
|
spec.require_paths = [ 'lib' ]
|
|
24
24
|
|
|
25
|
-
spec.add_dependency 'activerecord', '>= 8.1.0', '< 8.
|
|
25
|
+
spec.add_dependency 'activerecord', '>= 8.1.0', '< 8.3'
|
|
26
26
|
spec.add_dependency 'pg'
|
|
27
|
+
spec.add_dependency 'rgeo', '>= 3.1.0'
|
|
27
28
|
spec.add_dependency 'rgeo-activerecord', '>= 8.0'
|
|
28
29
|
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ActiveRecord
|
|
4
|
+
module ConnectionAdapters
|
|
5
|
+
module PostGIS
|
|
6
|
+
module DatabaseStatements
|
|
7
|
+
def truncate_tables(*table_names)
|
|
8
|
+
table_names -= [ "spatial_ref_sys" ]
|
|
9
|
+
super(*table_names)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -20,6 +20,7 @@ require_relative "postgis/adapter_extensions"
|
|
|
20
20
|
require_relative "postgis/column_extensions"
|
|
21
21
|
require_relative "postgis/quoting"
|
|
22
22
|
require_relative "postgis/spatial_queries"
|
|
23
|
+
require_relative "postgis/database_statements"
|
|
23
24
|
|
|
24
25
|
module ActiveRecord
|
|
25
26
|
module ConnectionAdapters
|
|
@@ -34,26 +35,43 @@ module ActiveRecord
|
|
|
34
35
|
|
|
35
36
|
SPATIAL_OPTIONS_FOR_REGISTRATION = %i[srid has_z has_m geographic].freeze
|
|
36
37
|
|
|
38
|
+
POSTGIS_SYSTEM_TABLES = %w[
|
|
39
|
+
geography_columns
|
|
40
|
+
geometry_columns
|
|
41
|
+
layer
|
|
42
|
+
raster_columns
|
|
43
|
+
raster_overviews
|
|
44
|
+
spatial_ref_sys
|
|
45
|
+
topology
|
|
46
|
+
].freeze
|
|
47
|
+
|
|
37
48
|
def self.initialize!
|
|
38
49
|
return if @initialized
|
|
39
50
|
@initialized = true
|
|
40
51
|
|
|
41
|
-
|
|
42
|
-
PostgreSQL::Column.include(ColumnExtensions)
|
|
52
|
+
extend_postgresql_adapter
|
|
43
53
|
|
|
44
|
-
|
|
45
|
-
PostgreSQLAdapter.prepend(Quoting)
|
|
54
|
+
register_spatial_types
|
|
46
55
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
# The issue might be deeper in how schema.rb is processed or how options are validated.
|
|
50
|
-
# Let's ensure that the column methods are defined *before* any schema loading that might trigger validation.
|
|
56
|
+
ignore_postgis_system_tables
|
|
57
|
+
end
|
|
51
58
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
)
|
|
59
|
+
def self.extend_postgresql_adapter
|
|
60
|
+
PostgreSQL::Column.include(ColumnExtensions)
|
|
61
|
+
PostgreSQLAdapter.prepend(Quoting)
|
|
62
|
+
PostgreSQL::Table.include(PostGIS::TableDefinition)
|
|
63
|
+
PostgreSQLAdapter.prepend(AdapterExtensions)
|
|
64
|
+
PostgreSQLAdapter.prepend(DatabaseStatements)
|
|
65
|
+
end
|
|
55
66
|
|
|
56
|
-
|
|
67
|
+
def self.register_spatial_types
|
|
68
|
+
register_native_database_types
|
|
69
|
+
register_column_methods
|
|
70
|
+
register_type_classes
|
|
71
|
+
register_type_mapping
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def self.register_native_database_types
|
|
57
75
|
PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:st_geography] = { name: "geography" }
|
|
58
76
|
PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:st_geometry] = { name: "geometry" }
|
|
59
77
|
PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:st_geometry_collection] = { name: "geometry(GeometryCollection)" }
|
|
@@ -64,7 +82,6 @@ module ActiveRecord
|
|
|
64
82
|
PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:st_point] = { name: "geometry(Point)" }
|
|
65
83
|
PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:st_polygon] = { name: "geometry(Polygon)" }
|
|
66
84
|
|
|
67
|
-
# Legacy aliases for compatibility with activerecord-postgis-adapter
|
|
68
85
|
PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:geography] = { name: "geography" }
|
|
69
86
|
PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:geometry] = { name: "geometry" }
|
|
70
87
|
PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:geometry_collection] = { name: "geometry(GeometryCollection)" }
|
|
@@ -73,92 +90,69 @@ module ActiveRecord
|
|
|
73
90
|
PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:multi_point] = { name: "geometry(MultiPoint)" }
|
|
74
91
|
PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:multi_polygon] = { name: "geometry(MultiPolygon)" }
|
|
75
92
|
PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:polygon] = { name: "geometry(Polygon)" }
|
|
93
|
+
end
|
|
76
94
|
|
|
77
|
-
|
|
78
|
-
# Tell Rails these are valid column methods for schema dumping - PostgreSQL only
|
|
95
|
+
def self.register_column_methods
|
|
79
96
|
PostgreSQL::TableDefinition.send(:define_column_methods,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
# prevent unknown OID warning and register PostGIS types
|
|
88
|
-
PostgreSQLAdapter.singleton_class.prepend(RegisterTypes)
|
|
89
|
-
|
|
90
|
-
# Prepend our extensions to handle spatial columns
|
|
91
|
-
PostgreSQLAdapter.prepend(AdapterExtensions)
|
|
97
|
+
:st_geography, :st_geometry, :st_geometry_collection, :st_line_string,
|
|
98
|
+
:st_multi_line_string, :st_multi_point, :st_multi_polygon, :st_point, :st_polygon,
|
|
99
|
+
:geography, :geometry, :geometry_collection, :line_string,
|
|
100
|
+
:multi_line_string, :multi_point, :multi_polygon, :polygon,
|
|
101
|
+
*SPATIAL_OPTIONS_FOR_REGISTRATION)
|
|
102
|
+
end
|
|
92
103
|
|
|
93
|
-
|
|
104
|
+
def self.register_type_classes
|
|
94
105
|
adapter_name = :postgresql
|
|
95
106
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
ActiveRecord::Type.register(:st_multi_polygon, Type::MultiPolygon, adapter: adapter_name)
|
|
104
|
-
ActiveRecord::Type.register(:st_point, Type::Point, adapter: adapter_name)
|
|
105
|
-
ActiveRecord::Type.register(:st_polygon, Type::Polygon, adapter: adapter_name)
|
|
106
|
-
|
|
107
|
-
# Legacy type registrations for compatibility with activerecord-postgis-adapter
|
|
108
|
-
ActiveRecord::Type.register(:geography, Type::Geography, adapter: adapter_name)
|
|
109
|
-
ActiveRecord::Type.register(:geometry, Type::Geometry, adapter: adapter_name)
|
|
110
|
-
ActiveRecord::Type.register(:geometry_collection, Type::GeometryCollection, adapter: adapter_name)
|
|
111
|
-
ActiveRecord::Type.register(:line_string, Type::LineString, adapter: adapter_name)
|
|
112
|
-
ActiveRecord::Type.register(:multi_line_string, Type::MultiLineString, adapter: adapter_name)
|
|
113
|
-
ActiveRecord::Type.register(:multi_point, Type::MultiPoint, adapter: adapter_name)
|
|
114
|
-
ActiveRecord::Type.register(:multi_polygon, Type::MultiPolygon, adapter: adapter_name)
|
|
115
|
-
ActiveRecord::Type.register(:polygon, Type::Polygon, adapter: adapter_name)
|
|
116
|
-
|
|
117
|
-
# Ignore PostGIS system tables in schema dumps - PostgreSQL specific
|
|
118
|
-
PostgreSQL::SchemaDumper.ignore_tables |= %w[
|
|
119
|
-
geography_columns
|
|
120
|
-
geometry_columns
|
|
121
|
-
layer
|
|
122
|
-
raster_columns
|
|
123
|
-
raster_overviews
|
|
124
|
-
spatial_ref_sys
|
|
125
|
-
topology
|
|
126
|
-
]
|
|
107
|
+
SPATIAL_TYPES_FOR_REGISTRATION.each do |type_name|
|
|
108
|
+
type_class_name = type_name.to_s.sub(/^st_/, "").split("_").map(&:capitalize).join
|
|
109
|
+
type_class = Type.const_get(type_class_name) rescue nil
|
|
110
|
+
if type_class
|
|
111
|
+
ActiveRecord::Type.register(type_name, type_class, adapter: adapter_name)
|
|
112
|
+
end
|
|
113
|
+
end
|
|
127
114
|
end
|
|
128
115
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
116
|
+
def self.register_type_mapping
|
|
117
|
+
if PostgreSQLAdapter.respond_to?(:register_type_mapping)
|
|
118
|
+
PostgreSQLAdapter.register_type_mapping { |m| TypeRegistration.register!(m) }
|
|
119
|
+
else
|
|
120
|
+
PostgreSQLAdapter.singleton_class.prepend(RegisterTypes)
|
|
121
|
+
end
|
|
122
|
+
end
|
|
132
123
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
124
|
+
def self.schema_ignored_tables
|
|
125
|
+
if ActiveRecord.respond_to?(:schema_ignored_tables)
|
|
126
|
+
ActiveRecord.schema_ignored_tables
|
|
127
|
+
else
|
|
128
|
+
PostgreSQL::SchemaDumper.ignore_tables
|
|
129
|
+
end
|
|
130
|
+
end
|
|
137
131
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
132
|
+
def self.ignore_postgis_system_tables
|
|
133
|
+
if ActiveRecord.respond_to?(:schema_ignored_tables)
|
|
134
|
+
ActiveRecord.schema_ignored_tables |= POSTGIS_SYSTEM_TABLES
|
|
135
|
+
else
|
|
136
|
+
PostgreSQL::SchemaDumper.ignore_tables |= POSTGIS_SYSTEM_TABLES
|
|
141
137
|
end
|
|
138
|
+
end
|
|
142
139
|
|
|
143
|
-
|
|
140
|
+
module TypeRegistration
|
|
141
|
+
def self.register!(m)
|
|
142
|
+
m.register_type("geometry") { |_, _, sql| from_sql(sql) }
|
|
143
|
+
m.register_type("geography") { |_, _, sql| from_sql(sql) }
|
|
144
|
+
end
|
|
144
145
|
|
|
145
|
-
def
|
|
146
|
-
# Handle empty sql_type (common in joins) - this is an upstream Rails issue
|
|
147
|
-
# where sql_type comes back as empty string, making it impossible to determine
|
|
148
|
-
# the correct spatial type properties
|
|
146
|
+
def self.from_sql(sql_type)
|
|
149
147
|
if sql_type.nil? || sql_type.empty?
|
|
150
|
-
# Log warning about potential type mismatch due to upstream issue
|
|
151
|
-
# Users experiencing this should use explicit attribute registration as workaround
|
|
152
|
-
# See: https://github.com/rgeo/activerecord-postgis-adapter/pull/334
|
|
153
148
|
return Type::Geometry.new(srid: 0, has_z: false, has_m: false, geographic: false)
|
|
154
149
|
end
|
|
155
150
|
|
|
156
|
-
# Extract SRID and dimensions from SQL type
|
|
157
151
|
srid = extract_srid_from_sql(sql_type)
|
|
158
|
-
# Check for dimension suffixes (e.g., PointZ, PointM, PointZM)
|
|
159
152
|
has_z = sql_type.match?(/\b\w+Z\b|\b\w+ZM\b/)
|
|
160
153
|
has_m = sql_type.match?(/\b\w+M\b|\b\w+ZM\b/)
|
|
161
154
|
geographic = sql_type.start_with?("geography")
|
|
155
|
+
|
|
162
156
|
case sql_type
|
|
163
157
|
when /geography\(Point/i
|
|
164
158
|
Type::Point.new(srid: srid, has_z: has_z, has_m: has_m, geographic: geographic)
|
|
@@ -193,17 +187,22 @@ module ActiveRecord
|
|
|
193
187
|
when /geometry/i
|
|
194
188
|
Type::Geometry.new(srid: srid, has_z: has_z, has_m: has_m)
|
|
195
189
|
else
|
|
196
|
-
# Fallback for unrecognized types
|
|
197
190
|
Type::Geometry.new(srid: srid, has_z: has_z, has_m: has_m)
|
|
198
191
|
end
|
|
199
192
|
end
|
|
200
193
|
|
|
201
|
-
def extract_srid_from_sql(sql_type)
|
|
202
|
-
# Extract SRID from patterns like geometry(Point,3785) or geography(Point,4326)
|
|
194
|
+
def self.extract_srid_from_sql(sql_type)
|
|
203
195
|
match = sql_type.match(/,(\d+)\)/)
|
|
204
196
|
match ? match[1].to_i : 0
|
|
205
197
|
end
|
|
206
198
|
end
|
|
199
|
+
|
|
200
|
+
module RegisterTypes
|
|
201
|
+
def initialize_type_map(m = type_map)
|
|
202
|
+
super
|
|
203
|
+
TypeRegistration.register!(m)
|
|
204
|
+
end
|
|
205
|
+
end
|
|
207
206
|
end
|
|
208
207
|
end
|
|
209
208
|
end
|
data/lib/activerecord-postgis.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: activerecord-postgis
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Abdelkader Boudih
|
|
@@ -18,7 +18,7 @@ dependencies:
|
|
|
18
18
|
version: 8.1.0
|
|
19
19
|
- - "<"
|
|
20
20
|
- !ruby/object:Gem::Version
|
|
21
|
-
version: '8.
|
|
21
|
+
version: '8.3'
|
|
22
22
|
type: :runtime
|
|
23
23
|
prerelease: false
|
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -28,7 +28,7 @@ dependencies:
|
|
|
28
28
|
version: 8.1.0
|
|
29
29
|
- - "<"
|
|
30
30
|
- !ruby/object:Gem::Version
|
|
31
|
-
version: '8.
|
|
31
|
+
version: '8.3'
|
|
32
32
|
- !ruby/object:Gem::Dependency
|
|
33
33
|
name: pg
|
|
34
34
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -43,6 +43,20 @@ dependencies:
|
|
|
43
43
|
- - ">="
|
|
44
44
|
- !ruby/object:Gem::Version
|
|
45
45
|
version: '0'
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: rgeo
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
requirements:
|
|
50
|
+
- - ">="
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: 3.1.0
|
|
53
|
+
type: :runtime
|
|
54
|
+
prerelease: false
|
|
55
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - ">="
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: 3.1.0
|
|
46
60
|
- !ruby/object:Gem::Dependency
|
|
47
61
|
name: rgeo-activerecord
|
|
48
62
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -72,9 +86,11 @@ files:
|
|
|
72
86
|
- lib/active_record/connection_adapters/postgis/column_extensions.rb
|
|
73
87
|
- lib/active_record/connection_adapters/postgis/column_methods.rb
|
|
74
88
|
- lib/active_record/connection_adapters/postgis/constants.rb
|
|
89
|
+
- lib/active_record/connection_adapters/postgis/database_statements.rb
|
|
75
90
|
- lib/active_record/connection_adapters/postgis/oid/spatial.rb
|
|
76
91
|
- lib/active_record/connection_adapters/postgis/oid/spatial_types.rb
|
|
77
92
|
- lib/active_record/connection_adapters/postgis/quoting.rb
|
|
93
|
+
- lib/active_record/connection_adapters/postgis/railtie.rb
|
|
78
94
|
- lib/active_record/connection_adapters/postgis/schema_dumper.rb
|
|
79
95
|
- lib/active_record/connection_adapters/postgis/schema_statements.rb
|
|
80
96
|
- lib/active_record/connection_adapters/postgis/spatial_column_methods.rb
|
|
@@ -111,13 +127,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
111
127
|
- - ">="
|
|
112
128
|
- !ruby/object:Gem::Version
|
|
113
129
|
version: 3.3.0
|
|
130
|
+
- - "<"
|
|
131
|
+
- !ruby/object:Gem::Version
|
|
132
|
+
version: '5.0'
|
|
114
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
134
|
requirements:
|
|
116
135
|
- - ">="
|
|
117
136
|
- !ruby/object:Gem::Version
|
|
118
137
|
version: '0'
|
|
119
138
|
requirements: []
|
|
120
|
-
rubygems_version:
|
|
139
|
+
rubygems_version: 4.0.10
|
|
121
140
|
specification_version: 4
|
|
122
141
|
summary: PostGIS Type support for ActiveRecord
|
|
123
142
|
test_files: []
|