I am trying to import a shapefile into Postgre using python and psycopg2. I have run into a few issues.
I am using ST_GeometryFromText() of a WKT string.
First, the shape@WKT returns MULTIPOLYGON ZM at the beginning of the string. I believe that it is only supposed to be MULTIPOLYGON correct?
I fixed this by doing a replace on the string but this does not seem like what should be done. What do I do to make this correct?
Second, the shape@WKT contains X, Y, 0, NAN as values. I am expecting only 2 values, x and y. Why am I getting 0 and NAN?
with arcpy.da.SearchCursor(input_fc, ["FID", "Shape@WKT"]) as da_cursor: for row in da_cursor: geoms = row.replace(' ZM ','') print geoms pg_cursor.execute("INSERT INTO %s (fid_p, geom) VALUES (%s, ST_GeometryFromText('%s', %s))" %(dataset_name, int(row), geoms, int(coordinate_system))) pg_connection.commit()
RESULT of print geoms:
MULTIPOLYGON ZM (((440185.43178632273 6350644.499023444 0 NAN, 440189.09859540447 6350575.940429694 0 NAN, .........
InternalError: parse error - invalid geometry HINT: "...85.43178632273 6350644.499023444 0 NA" <-- parse error at position 60 within geometry