[Gdal-dev] MapInfo mixing geometry types in a layer

Frank Warmerdam warmerdam at pobox.com
Thu Nov 28 16:08:37 EST 2002


Ben Discoe wrote:
> Happy Thanksgiving, Frank.  Since we're both working on a holiday, i figure
> i'll bug you with more questions :-)
> 
> I'm using OGR to read some MapInfo .MAP/.TAB files.  Most are working fine,
> but for some of them i am encountering a strange behavior.
> 
> When i ask the type of the layer:
> 
> 	OGRFeatureDefn *defn = pLayer->GetLayerDefn();
> 	OGRwkbGeometryType geom_type = defn->GetGeomType();
> 
> it says "OGRLineString."  However, when i am reading each geometry, some of
> them are OGRLineString, and some of them are OGRMultiLineString!
> 
> Is this an expected behavior, correct OGR functioning?  Does MapInfo really
> mix geometry types within a single layer, ESRI Shapefiles sure don't.

Ben,

It is routine to mix geometry types in Mapinfo files; however, the
pLayer->GetLayerDefn() should return wkbUnknown as the geometry type for
layers with a mixture of geometries.  I believe the problem is that the MITAB
code determines if a specific geometry type can be used by checking the
tab file header.  In cases where the "number of lines" field is the only
non-zero one, it assumes the layer holds only lines.  However, there
can be cases where some geometries are more properly modelled as
OGRMultiLineString (a set of disconnected lines).

The correct solution would be for us to either scan all geometries in advance
(to determine the geometry type for the layer), or return wkbUnknown all the
time since it is hard for us to be certain in advance.  However, both solutions
suck.

I am a little surprised there are multi line strings in Mapinfo, but the
problem you see frequently arises with polygons where multi-island polygons
really need to be represented as OGRMultiPolygons, but this is often not
possible to know in advance untill the geometry is encountered.  This is
the case with the still buggy shapefile reader for instance.  An ESRI
polygon shapefile may contain a mix of OGRPolygon and OGRMultiPolygon
geometries.  In ESRI parlance they are all polygons, but in the OpenGIS
Simple Features geometry model some are polygons and some are multi-polygons.

The shapefile driver actually just returns the multi-island geometries
as OGRPolygon even though there are really more than one outer ring.

In short, for the time being you should be wary of completely trusting
the return result of OGRFeatureDefn->GetGeomType().

PS. we had our Canadian Thanksgiving several weeks ago; however, I did have
a turkey lunch with an American friend today to celebrate your holiday.

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    | Geospatial Programmer for Rent





More information about the Gdal-dev mailing list