3

I have problem with importing shapefile to Postgis table.

PostGIS table has:

the_geom geometry(LineString,102067) for geometry

Shapefile has:

INFO: Open of `postup_doby.shp'
using driver `ESRI Shapefile' successful.
1: postup_doby (Line String)

ogr2ogr command is:

PGCLIENTENCODING=WIN1250 ogr2ogr -skipfailures --config PG_USE_COPY YES -f PostgreSQL PG:"host=localhost port=5432 dbname=myname password=secure active_schema=povis user=sa" -lco DIM=2 postup_doby.shp postup_doby -append -nlt GEOMETRYCOLLECTION -lco GEOMETRY_NAME=the_geom -lco FID=envi_id -nln postupove_doby PRECISION=NO

Error message is:

Insertion is likely to fail
ERROR 1: COPY statement failed.
ERROR:  Geometry type (MultiLineString) does not match column type (LineString)
CONTEXT:  COPY postupove_doby, line 1, column the_geom: "0105000020B38E01000200000001020000006C000000E4E2809372B61CC13F49396A56C030C1C24C8D97FAB41CC175C2C6B5..."

Problem is in shapefile, because has 10 features, which one feature has MULTILINESTRING geometry, others has LINESTRING geometry.

ogrinfo of feature with MULTILINESTRING, others has LINESTRING:

MULTILINESTRING ((-470428.644046349683776 -1097814.414936616783962,-470334.64799995359499 -1097731.710 ...

My solution is convert feature with MULTILINESTRING to LINESTRING and import to PostGIS, but I dont know, how I make it in comand line.


How can I resove this problem?

1 Answer 1

4

I would read first http://www.gdal.org/ogr2ogr.html and then run ogr2ogr with option -explodecollections.

-explodecollections: (starting with GDAL 1.8.0) produce one feature for each geometry in any kind of geometry collection in the source file

Something like this should work for you:

 ogr2ogr -explodecollections --config PG_USE_COPY YES -f PostgreSQL PG:"host=localhost port=5432 dbname=myname password=secure active_schema=povis user=sa" -lco DIM=2 postup_doby.shp postup_doby -append  -lco GEOMETRY_NAME=the_geom -lco FID=envi_id -nln postupove_doby PRECISION=NO

I believe that -skipfailures does not work with the COPY method which seems to be all-or-nothing in PostgreSQL https://www.postgresql.org/docs/9.2/static/sql-copy.html.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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