OregonStateUniversity / ltpbr-explorer

Tracking artificial beaver dams for river restoration.
http://bdaexplorer.com
GNU General Public License v3.0
1 stars 0 forks source link

seeds: simplify #302

Open ybakos opened 11 months ago

ybakos commented 11 months ago

The seeds work currently involves:

This should be able to be done directly, by a straightforward seeds.rb script. But, when doing so, eg:

State.create!(iso_code: 'US-MN', state_type: 'State', name: 'Minnesota', geom: '0106...40');

The geometry is stored as srid 0 instead of srid 4326. This causes the Project#calculate_state work to fail. (When doing the states_ref to states copying, the geometry is srid 4326.)

The states table migration only specified:

t.multi_polygon :geom

Resulting in the following in schema.rb:

t.geometry "geom", limit: {:srid=>0, :type=>"multi_polygon"}

It seems we can alter the table:

change_column :states, :geom, :multi_polygon, srid: 4326

And then create a more straightforward seeds.rb file:

State.create!(iso_code: 'US-MN', state_type: 'State', name: 'Minnesota', geom: '0106...40');

Instead of using the raw sql and copy ceremony that is currently there.

Additional Notes:

To find out the SRID(s) of a table:

SELECT DISTINCT ON (ST_SRID(geom)) ST_SRID(geom) FROM states;

To set the SRID of a geom column that has already been created:

UPDATE temppat SET geom = ST_SETSRID(geom,27700)

Note that this won't transform the geometries.

https://gis.stackexchange.com/questions/39138/reprojecting-all-geometries-in-postgis-table

ybakos commented 11 months ago

Also see https://github.com/rgeo/activerecord-postgis-adapter