rgeo / rgeo-activerecord

RGeo ActiveRecord extensions and tools for spatial connection adapters
Other
89 stars 64 forks source link

How can I transform a geometry? #40

Closed allthesignals closed 3 years ago

allthesignals commented 7 years ago

How can I transform a geometry from an SRID to another SRID?

In GeoDjango, I can accomplish this with #transform: https://docs.djangoproject.com/en/1.11/ref/contrib/gis/geoquerysets/#transform

In PostGIS, I can SELECT ST_Transform(geometry, 4326) AS the_geom_wgs84.

Is it possible with this gem?

keithdoggett commented 3 years ago

This is possible using a model's arel_table and st_function.

locations = Location.arel_table

query = location.project(location[:geom].st_function("ST_Transform", [4326], [true, true, false]).as('the_geom_wgs84'))
Location.find_by_sql(query.to_sql)