1

I'm using Rails' PostGIS adapter and RGeo-GeoJSON gems to store/serve some simple geometries in the Postgres database, but I'm having a little trouble with my database seed file... I'd like to be able to use GeoJSONs to seed my database, but seem to only be able to use WKT format.

For example, I'm able to seed the database successfully using the following syntax:

Model.create([{geometry: 'LINESTRING(-72.81164550781249 43.627896481020855, -72.90228271484375 43.386951440524854, -72.9324951171875 43.204107493733176)', description: 'test'}]),

but I'd much rather be able to simply insert a single GeoJSON into the geometry column, rather than have to break up its attributes across different columns and reassemble it later.

In the past, I've done this with PHP like so:

ST_SetSRID(ST_GeomFromGeoJSON('$geoJson'), 4326)

which passed the entire GeoJSON into one column, but it seems to me that the PostGIS adapter can only handle lat/longs in WKT format. Is that the case, or is there a way to insert a pure GeoJSON?

  • Whatever you can do using raw sql code in a php environment you can certainly do the same in a ruby environment. Model.connection.execute(sql) will do everything in sql if you like – boulder_ruby Jan 9 '17 at 3:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.