1

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?

Luffydude
  • 2,308
  • 3
  • 18
  • 38
  • 3
    What does ogrinfo folders/file.shp show? Have you tried to give an absolute path to shapefile? – user30184 Nov 03 '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 03 '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. https://gis.stackexchange.com/questions/195172/import-a-shapefile-to-postgis-with-ogr2ogr-gives-unable-to-open-datasource/195223 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 03 '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 03 '20 at 19:53
  • @JGH whoops. I'll give the psql a go tomorrow but thanks for pointing that out – Luffydude Nov 03 '20 at 19:54
  • @jgm_GIS I got full permission on my laptop and have superuser on the database so that shouldnt be an issue? – Luffydude Nov 03 '20 at 19:56
  • If also ogrinfo fails you have no chance to success. Whatever the issue is fix it first. – user30184 Nov 03 '20 at 20:35
  • You really should read the link in detail that I included in my comment and investigate how permissions work for Mac/Linux systems and Postgres. Also, how large are the components of your shapefiles? If any of them are over 2gb, you should make sure you have the latest 64 bit (32 bit programs max out at 2gb) build of GDAL. I see that it has a lot of bug fixes for files greater than 2 gb. – jgm_GIS Nov 04 '20 at 13:03
  • @user30184 really not sure how to troubleshoot ogrinfo... there's not much room to messup, it's literally just ogrinfo plus directory – Luffydude Nov 04 '20 at 17:07
  • Use some imagination. Copy one other shapefile that you know to be valid into the same directory. Remember to copy all compulsory parts .shp, .shx and dbf. If ogrinfo reads the shapefile then at least the read rights to the directory are OK. Then you can move the failing shapefile into other directory and test with ogrinfo. If it still fails I would suspect that the shapefile is corrupted but because QGIS can open it I do not believe in that. Have you tried to save a new copy with QGIS? Saving into geopackage could be worth trying as well. – user30184 Nov 04 '20 at 17:23
  • @user30184 i cant seem to open anything using ogrinfo. I tried 5 different files with the extention but the outcome is always unable to open datasource – Luffydude Nov 04 '20 at 17:38
  • Now this is progress! Do you have all the parts of the shapefile in the same directory? – user30184 Nov 04 '20 at 17:41
  • @user30184 I've been trying csv files now and still the same outcome – Luffydude Nov 04 '20 at 17:43

0 Answers0