I have enabled postgis extension already and have imported 3 shapefiles through the qgis db manager. Problem is that now I still have 2 large files to import and leaving qgis importing the entire night was not able to do finish the import. This is why I would need ogr2ogr to work

When I try to use the following command

ogr2ogr -f PostgreSQL PG:"dbname='postgres' host='hostnamehere' port='5432' user='user' password=passwordhere" folders/file.shp -nlt MULTIPOLYGON

I simply get the following error:

Unable to open datasource `folders/file.shp' with the following drivers.

The file opens just fine on QGIS. Is my ogr2ogr command wrong?

Alternatively I also tried psql as I've seen here on this website using:

psql -h host=hosthere gis postgres -p 5432

But got met with this error

psql: could not translate host name "host=host.rds.amazonaws.com" to address: nodename nor servname provided, or not known

I then tried using dbeaver to import a file from a csv but I keep getting java.lang.NullPointerException and it just doesnt appear to match the fields, yet the file still opens fine on Excel

Is my Ogr2ogr wrong or is there a different thing I can try?

  • 3
    What does ogrinfo folders/file.shp show? Have you tried to give an absolute path to shapefile?
    – user30184
    Nov 3 '20 at 18:22
  • for #2, remove host= (psql -h bd1....amazonaws.com ...). Then you may want to ensure that only you can connect to this host, not the entire world. For #3 you can specify the field names in the copy command. It might be worth reading the doc on copy and to write the import statement by hand.
    – JGH
    Nov 3 '20 at 18:27
  • The command lines I've used to upload shapefiles with ogr2gr to postgres didn't have single quotes inside the double quotes. This post discusses your issue in detail. gis.stackexchange.com/questions/195172/… It recommends making sure you have access to read the shapefile. I'd also check your pg_hba.conf to make sure you can access postgres from your machine.
    – jgm_GIS
    Nov 3 '20 at 19:27
  • @user30184 it still says unable to open datasource. I'm on a mac so the full path would be Users/myname/Downloads/folder/file.shp which i tried and didnt work
    – Luffydude
    Nov 3 '20 at 19:53
  • @JGH whoops. I'll give the psql a go tomorrow but thanks for pointing that out
    – Luffydude
    Nov 3 '20 at 19:54

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.