Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

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".

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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