[Gdal-dev] Problems with PostGIS and Shapefile interface

Frank Warmerdam warmerdam at pobox.com
Wed Mar 22 23:56:46 EST 2006


rompenb at unbc.ca wrote:
> Hi, I've been having major difficulties in programming with the OGR API.  
> Currently I'm attempting to write a program that reads features from a
> PostGIS database and writes them to an ESRI Shapefile.   The following
> strange problems are occurring:
> 
> 1) When I read a feature from the PostGIS database, both of the following
> statements
>    currentfeat->GetGeometryRef()->getGeometryType()
>    loadlayer->GetLayerDefn()->GetGeomType()
> return 0, or 'wkbUnknown', when according to currentfeat->DumpReadable()
> all the features in the database table are multipolygons.

Ben,

It is common for GetLayerDefn()->GetGeomType() to return wkbUnknown.  It
just means the driver doesn't know for sure what geometry types will occur
in this layer.

I can't think of any circumstance under which getGeometryType() on a
geometry could return wkbUnknown.  If this is reproducable, there is
an issue that should be investigated.

> 2)OGRGeometryFactory::forceToPolygon() isn't working.   According to the
> following code,
>    currentfeat->DumpReadable(dumpfile);
>    destfeat->SetGeometryDirectly(
>             OGRGeometryFactory::forceToPolygon(destfeat->StealGeometry()));
>    destfeat->DumpReadable(dumpfile);
> the geometry remains in multipolygon format.   destfeat previously had its
> geometry created via OGRFeature::SetFrom().

Your approach looks fine.  I don't know why this is happening.  If you can
boil down an example please file a bug report on this issue.

> 3)When I re-read the shapefile following translation, using
> OGRFeature::DumpReadable() again, the features appear as a mixture of
> polygons and multipolygons.

The Shapefile does not store a distinction between polygons and
multipolygons.  Which is to be created is deduced by analysing the
geometric relationship of the rings.  This could easily result in
a multipolygon written to shapefiles coming back as a polygon.

It is also quite plausible that the shapefile reading code in OGR
may be mis-classifying some things as polygon vs. multipolygon.

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 OSGF, http://osgeo.org




More information about the Gdal-dev mailing list