8

I am very new to PostGIS/PostgreSQL. In fact, I downloaded it because of the answers I got to this question: Distance between centroid and farthest point of polygon

I installed both PostgreSQL and PostGIS. But I am not able to import a shapefile to the database? It gives an error, "Shapefile import failed". What am I doing wrong?

enter image description here

5
  • 2
    Probably doesn't like that your shapefile is a multipolygon. You could try using Vector > Geometries Tools > Multipart to Singleparts from the QGIS menubar and see if you can import again.
    – Joseph
    Jun 28, 2016 at 9:24
  • 2
    @Joseph I think she is using ArcGIS not QGIS, there is a similar tool in ArcGIS too Jun 28, 2016 at 13:34
  • 1
    @HichamZouarhi - Ahh, I barely see questions involving both ArcGIS and PostGIS together :)
    – Joseph
    Jun 28, 2016 at 13:38
  • 1
    I've received this error before when trying to import a file that is also open in QGIS. It produces the same error (at least on my machine). After closing QGIS (or alternatively using a copy of the shapefile) I could import the shapefile without issue. I'm not sure if similar behavior occurs with ArcGIS (or machine-specific) but worth a shot for anyone who has tried everything else.
    – Don P
    Aug 31, 2017 at 20:40
  • So how did you remove this 'geom' field which is the default default geometry field name of Shp2pgsql GUI? What I did not happen. Can you help? Oct 6, 2019 at 7:51

10 Answers 10

8

you have to install postgis extension on database "create extension postgis"

First chek if you had already installed the Postgis Extension, if not the Import will be failed , because this extension is responsable to talk with postgis-shape-Loader

enter image description here

if didn't insatll it then :write a query in the "your database": Create extension postgis;

enter image description here

1

The problem is maybe with the type of your geometry as you see its type is Polygon Z in ArcGIS but you are trying to convert it as polygon to use it in PostGIS.

I did some search and found this workaround:

run Feature Class to Feature Class tool then (before executing it) in 'Environments' at the bottom > expand Z values > set 'Output has Z Values' to Disabled

there are some issues like this one in the esri web page if you want to consult it

1

I have encountered a similar problem and searched to find only this post relevant, although my polygons are simply two dimensional. Here is my import configuration.

Importing with configuration: sz_div_st_cell, public, geom, F:\path\to_polygons.shp, mode=c, dump=1, simple=0, geography=0, index=1, shape=1, srid=0

Shapefile type: Polygon

PostGIS type: MULTIPOLYGON[2]

Shapefile import failed.

After checking the input shapefile several times, I found that the polygon shapefile itself, which came from an postgresql export and underwent some operations in ArcGIS, had a field named 'geom' in its attribute table (.dbf), and caused the import failure. After removing that 'geom' field, which was the default geometry field name in shp2pgsql GUI, the import went smoothly and successfully.

0

Simple solution: from the "SRID" in the PostGIS, Check the EPSG value from QGIS and paste it in the SRID then your problem is solved.

0

You can use QGIS, and drag the map to the db.

1
  • How? Could you give more information? Sep 21, 2020 at 13:44
0

"create extension postgis" worked when I added it in the psql command prompt, but didn't work when I entered it into pgAdmin.

1
  • 2
    Is this an answer to the question or a new question? Nov 10, 2020 at 1:10
0

In my case, specifying a database in connection details solved the error message.

0
0

I confirm that in most cases it is a column in your data called "geom" which duplicates with "geometry". It must be deleted (geom) before import. From QGIS for example by going to the DB manager by connecting directly to your Database at best and by making an SQL query excluding this field.

I found that a symbol character (²) in a field heading was not recognised by PostGIS and prevented import, once removed problem solved.

0
0

It might be a different issue.

Once in my specific case it was (that I saw from others here but with some differences) - that it is based on wrong connection settings. PostGIS accepts the connection settings, even if you don't have a "Database", or if you have a wrong Server Host.

-1

If it's not resolved yet. I think it's a PostGIS extension you need to load.

With PostGIS extension execute this query: create extension postgis;

Not the answer you're looking for? Browse other questions tagged or ask your own question.