georust / gdal

Rust bindings for GDAL
https://crates.io/crates/gdal
MIT License
339 stars 92 forks source link

PostGIS write example #135

Open stuartlynn opened 3 years ago

stuartlynn commented 3 years ago

I was wondering if you had or knew of an example of using these binding to load vector data into a PostGIS database.

Essentially an example like https://github.com/georust/gdal/blob/master/examples/read_write_ogr.rs but instead of converting the GeoJSON to a shapefile, it gets converted to a PostGIS table.

When try this:

let mut postgis = Dataset::open(Path::new("PG: host=localhost dbname=** user=*"))?;

I get an Error browsing database for PostGIS Raster tables: error.

Running the ogr2ogr command:

ogr2ogr -f "PostgreSQL" PG:"dbname=** user=**" input.geojson

works fine so I think I have all the correct drivers installed.

Apologies if this is obvious but been trying to figure it out for a while now without success. I would be willing to submit a PR with a working example for the examples folder for others who are trying to do the same if you can help me figure this out.

Thanks!

JorgeMartinezG commented 10 months ago

Jumping late on this issue. I was able to solve it by switching to URI syntax like postgresql://[user[:password]@][netloc][:port][/dbname][?param1=value1&...]