[gdal-dev] ogr2ogr PROMOTE_TO_MULTI with linestrings?

Stephen Woodbridge woodbri at swoodbridge.com
Tue May 16 06:21:06 PDT 2017


I'm just trying to load the census roads data. I think what happened is 
that when the table was created using -nlt PROMOTE_TO_MULTI it was 
created as polygon geometry. then the subsequent insert failed. I change 
the script to -nlt MULTILINESTRING and it loaded all the data. I found a 
post from Even circa 2012 IIRC that indicated PROMOTE_TO_MULTI should 
work for both polygons and linestrings.

I just checked the log file and the table was created with:

ogr2ogr -t_srs EPSG:4326 -nln census.roads -nlt PROMOTE_TO_MULTI -f 
PostgreSQL -overwrite -lco OVERWRITE=YES -lco PRECISION=NO -lco 
GEOMETRY_NAME=geom -lco FID=gid "PG:dbname=buildings host=localhost 
port=5432 user=postgres active_schema=census" 
/u/ror/buildings/data/census/tmp-11/tl_2016_us_county.shp

and then failed on the first insert:

ogr2ogr -t_srs EPSG:4326 -nln census.roads -nlt PROMOTE_TO_MULTI -f 
PostgreSQL -append "PG:dbname=buildings host=localhost port=5432 
user=postgres active_schema=census" 
/u/ror/buildings/data/census/tmp-11/tl_2016_06001_roads.shp
Warning 1: Geometry to be inserted is of type Multi Line String, whereas 
the layer geometry type is Multi Polygon.
Insertion is likely to fail
ERROR 1: ERROR:  Geometry type (MultiLineString) does not match column 
type (MultiPolygon)

ERROR 1: INSERT command for new feature failed.

When I changed, PROMOTE_TO_MULTI to MULTILINESTRING, everything worked 
fine. I only loaded one state (CA), but I do know for a fact that some 
of the Census roads data has a mix of Linestring and MultiLinestring 
features, which is why I used PROMOTE_TO_MULTI in the first place.

-Steve

On 5/16/2017 2:58 AM, jratike80 wrote:
> Stephen Woodbridge wrote
>> On 5/15/2017 6:15 PM, Stephen Woodbridge wrote:
>>> Hi,
>>>
>>> I'm trying to load both polygons and linestrings and would like
>>> PROMOTE_TO_MULTI to work for both, but it appears to define Multipolygon
>>> type and does not work for linestrings/multilinestrings.
>>>
>>> Maybe it would make more sense to have:
>>>
>>> PROMOTE_TO_MULTI - work for either polygon or linestring depending on
>>> what the first object is
>>>
>>> or have two options like:
>>>
>>> PROMOTE_POLY_TO_MULTI
>>> PROMOTE_LINE_TO_MULTI
>>>
>>> Or maybe, I'm totally missing something in the docs.
>>
>> Sorry, forgot to add:
>>
>> ogrinfo --version
>> GDAL 2.1.0, released 2016/04/25
>>
>> ogr2ogr -t_srs EPSG:4326 -nln census.roads -nlt PROMOTE_TO_MULTI -f
>> PostgreSQL -append PG:dbname=buildings host=localhost port=5432
>> user=postgres active_schema=census
>> /u/ror/buildings/data/census/tmp-11/tl_2016_06061_roads.shp
>> Warning 1: Geometry to be inserted is of type Multi Line String, whereas
>> the layer geometry type is Multi Polygon.
>> Insertion is likely to fail
>> ERROR 1: ERROR:  Geometry type (MultiLineString) does not match column
>> type (MultiPolygon)
> 
> Hi,
> 
> Please tell more details about what you plan to do. Shapefile can't contain
> a mixture of lines and polygons so the error you get must mean that PostGIS
> table "census.roads" already exists and it has been created as MultiPolygon.
> Did you convert some polygons from another shapefile into the same table
> before? Anyway the restriction is at this stage set by PostGIS which
> requires multipolygons and you just can't  convert your lines into
> multipolygons.
> 
> Drop your table and start again by using -nlt GEOMETRY and you should be
> fine. That makes the PostGIS table to accept any kind of geometries. If you
> definitely need a mixture of MULTIpolygons and MULTIlinestrins we must add
> casts somewhere but perhaps that is not what you really want.
> 
> -Jukka Rahkonen-
> 
> 
> 
> 
> 
> 
> --
> View this message in context: http://osgeo-org.1560.x6.nabble.com/gdal-dev-ogr2ogr-PROMOTE-TO-MULTI-with-linestrings-tp5320602p5320626.html
> Sent from the GDAL - Dev mailing list archive at Nabble.com.
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev
> 


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus



More information about the gdal-dev mailing list