1

I'm having difficulties with the Geometry types in PostGIS and/or ArcPy and hope some of you can shed a light on what I'm missing or how I can fix it.

I have a .gdb containing Polygons. The Table in ArcGIS lists the features as Polygons and using ArcPy using the following code I get the Output "Polygon" as well.

desc = arcpy.Describe("Path to Featureclass")
geometryType = desc.shapeType
print(geometryType)

Now when I upload the featureclass using ogr2ogr:

ogr2ogr -f "PostgreSQL" “PG:host=[host] port=[port] dbname=[dbName] user=[user]" “[PathtoFileGDB]” -overwrite -skipfailures –progress

And then access it via psycopg2:

import psycopg2
from shapely import wkb

conn = psycopg2.connect(host...)
conn.autocommit = True
cursor = conn.cursor()

cursor.execute('''select * from testfeatures;''')
record = cursor.fetchall()

conn.commit()
conn.close()

I'll get Multipolygons as a geometry. I already ran the "Repair Geometry" Tool in ArcGIS Pro before uploading the .gdb and the features display fine at every turn...

This sums up my problem, if you need any more information don't hesitate to ask and I'll try to provide it.

5
  • Do you get errors about non-matching geometry type if you run the command without -skipfailures? – user30184 Feb 17 at 14:50
  • no errors when omitting -skipfailures – BastiG Feb 17 at 14:57
  • Are there errors without -skipfailures but with -nlt polygon? – user30184 Feb 17 at 14:58
  • No errors, but now the output using Psycopg2 is Polygon! Thank you very much. I'll test out if my other scripts are able to process the data – BastiG Feb 17 at 15:09
  • 2
    That is actually not a solution but I tried to find out what happens. ESRI traditionally talks just about polygons and they can be a mixture of polygons and multipolygons. PostGIS considers that they are different and you can't insert a polygon into multipolygon table and vice versa. Ogr2ogr by default checks the type of the first geometry and my theory was that the first feature in your data was a multipolygon. – user30184 Feb 17 at 15:19

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.