9

I'm using ogr2ogr to import data into a PostGIS database. Each dataset I need to import has (theoretically) the same exact data structure, but it appears that they are not the same geometry types. Example, I've already imported the first layer, and there's a layer called "streets". Running this command, I import the first feature class from the first database (I have GDAL configured to read .mdb):

ogr2ogr -f PostgreSQL PG:"host=localhost user=postgres dbname=database port=5432" city1.mdb streets -nln streets -nlt MULTILINESTRING -lco GEOMETRY_NAME=geometry

When I go to append (using the -append flag) the same streets layer from city2.mdb, I get this error (presumably due to conflicting geometry types for the two "streets" layers:

Warning 1: Geometry to be inserted is of type 3D Line String, whereas the layer geometry type is 3D Multi Line String.
Insertion is likely to fail
ERROR 1: INSERT command for new feature failed.
ERROR:  Geometry type (LineString) does not match column type (MultiLineString)

Is there a straightforward way with ogr2ogr to cast geometries to the same type on import? Or a way to handle this by predefining the schema and geometries for each table beforehand?

0

1 Answer 1

18

Use the -nlt option. In this case you want:

-nlt MULTILINESTRING

There is also PROMOTE_TO_MULTI (GDAL 1.10 and later), which chooses either MULTILINESTRING or MULTIPOLYGON depending on the input layer. The use case for this is "doing a mass conversion of shapefiles that [mix] different types of geometries".

Your Answer

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

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