[Gdal-dev] Need Help with ogr2ogr Import Shapefile Error

Frank Warmerdam warmerdam at pobox.com
Mon Dec 4 13:53:23 EST 2006


Bill Thoen wrote:
> I just tried to import a shapefile into an empty database,but got an error
> I don't understand. Can anyone tell me what's wrong and how to fix this?
> 
> The table is projected in the NAD83 UTM zone 16 system. The shapefile has
> associated .dbf, .prj, .sbn, .sbx, .shp, .shp.xml, and .shx files.
> Here's what I tried:
> 
> $ ogr2ogr -update -append -f PostgreSQL PG:dbname=clu 
>    clu_001ilna04_U.shp -a_srs EPSG:26916
> 
> ERROR 1: INSERT command for new feature failed.
> ERROR:  new row for relation "clu_001ilna04_U" violates check constraint
> "enforce_geotype_wkb_geometry"
> 
> Command: INSERT INTO "clu_001ilna04_U" (wkb_geometry , "calcacres",
> "fid_clu_pu", "fid_raster", "gridcode", "id") VALUES
> (GeomFromEWKT('SRID=32767;MULTIPOLYGON (((644362.065155122079886

Bill,

The problem is that the OGR Shapefile driver lies, and reports it
has a geometry type of POLYGON when in fact it can have either
polygon or multipolygon.  As you can see the above insert it trying
to insert a MULTIPOLYGON in a table that was presumably created with
the restriction that it has polygon geometries.

The workaround is to force the table geometry type to GEOMETRY (a
generic geometry of any kind).  This can be accomplished by adding
the commandline switch "-nlt geometry".

The "fix" is for the shapefile driver to report the layer type as
geometry instead of polygon but this is also likely to cause lots of
folks problems so I have hesitated to make the change.

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org




More information about the Gdal-dev mailing list