I would have been stumped by your second error for awhile, but by testing your SQL user with a different import utility (shp2pgsql), which was smart, you got a more precise error message and gave your SQL user necessary privileges on the spatial_ref_sys table. Because the error message creates a red herring, this is a possibility others need to keep in the back of their minds. As you discovered, it was actually just a problem with user permissions. But there is an important lesson here for others, specifically, ogr2ogr's error message on this point was misleading! Indeed, one of the first commenters thought your shapefile was invalid, and admittedly, my first guess was that there was probably an error/typo in the path/filename, or that there might have been an unconventional character in the file path-like a space-that was breaking ogr2ogr's ability to point to the shapefile. * Note the recommendation in comment that -nlt PROMOTE_TO_MULTI be used as a default solution, rather than nlt GEOMETRY, as the former promotes best practice in addition to ancillary benefits.įirst, ogr2ogr couldn't open your shapefile, and you realized permissions issues were in fact affecting the OS user accessing your shapefile.
Data loaded in db correctly! ogr2ogr -f "PostgreSQL" PG:"host=localhost user=geonode dbname=geonode_imports password=geonode" -nlt GEOMETRY wld_bnd_adm0_gaul_2015.shpĪs you discovered by trial and error, there were few nagging issues you needed to fix, the last of which was resolved using ogr2ogr's -nlt GEOMETRY * argument.
PostgreSQL driver failed to create PG:host=localhost user=my_user_name dbname=my_database password=password -nlt POLYGONīut it gets loaded using the shp2pgsql GUI.Ĭomment of enabled this to finally work. Please create database with the `createdb' command. So it seems I need to use the parameter: -nlt MULTIPOLYGONīut when I do so I get another error, which doesn't make any sense to me: ERROR 1: PostgreSQL driver doesn't currently support database creation. Next error message is: Warning 1: Geometry to be inserted is of type 3D Multi Polygon, whereas the layer geometry type is 3D Polygon.ĮRROR 1: INSERT command for new feature failed.ĮRROR: Geometry type (MultiPolygon) does not match column type (Polygon) This fixed it: GRANT ALL ON TABLE spatial_ref_sys TO my_user_name The issue this time was that this database user didn't have sufficient permissions. PL/pgSQL function addgeometrycolumn(character varying,character varying,character varying,integer,character varying,integer,boolean) line 5 at SQL statement PL/pgSQL function addgeometrycolumn(character varying,character varying,character varying,character varying,integer,character varying,integer,boolean) line 50 at SQL statement I also tried to import it through the GUI shp2pgsql and I get the following error: ALTER TABLE "public".""įailed in pgui_exec(): ERROR: permission denied for relation spatial_ref_sysĬONTEXT: SQL statement "SELECT SRID FROM spatial_ref_sys WHERE SRID = new_srid" Translation of layer world_boundaries (use -skipfailures to skip errors)
I have also tried to define the full path of the shapefile but I got the same message.Īlso I tried to run the: ogrinfo world_boundaries.shpĪfter fixing the issues with the permissions of the file I get the following error: ERROR 1: AddGeometr圜olumn failed for layer world_boundaries, layer creation has failed.ĮRROR 1: Terminating translation prematurely after failed
What I get back is an error message: Unable to open datasource `world_boundaries.shp' with the following drivers: -a list of drivers follows (ESRI Shape File etc.) I have successfully installed ogr2ogr and I run from the pgsql the following command: ogr2ogr -f "PostgreSQL" PG:"host=localhost user=user_1 password=***** dbname=imports" world_boundaries.shp I want to use ogr2ogr in order to import a shapefile in a postgis database.