[gdal-dev] GetGeomType() for a MapInfo TAB using OGR MapInfo File driver
Even Rouault
even.rouault at mines-paris.org
Thu Apr 24 11:23:24 PDT 2014
Le jeudi 24 avril 2014 19:47:36, Max Demars a écrit :
> Hi!
>
> I am using the OGR MapInfo File driver to read a MapInfo TAB file. However,
> the function
> GetGeomType()<http://gdal.org/python/osgeo.ogr.Layer-class.html#GetGeomTyp
> e>returns 0 which means point
> geometry, even if the features in the TAB are only multi-polygons.
No, see ogr_core.h :
wkbUnknown = 0, /**< unknown type, non-standard */
>
> Is it because MapInfo TAB can store many different GeomTypes in the same
> file?
The MapInfo TAB file will return wkbPoint, wkbLineString or wkbUnknown. The
later being for polygons/multipolygons, or mix or geometry types.
Source is ogr/ogrsf_frmts/mitab/mitab_tabfile.cpp :
if( numPoints > 0 && numLines == 0 && numRegions == 0 )
m_poDefn->SetGeomType( wkbPoint );
else if( numPoints == 0 && numLines > 0 && numRegions == 0 )
m_poDefn->SetGeomType( wkbLineString );
else
/* we leave it unknown indicating a mixture */;
>
> If I take for granted that only one geometry type would always be founded
> in the TAB, how could I retrieve it?
>
> driver = ogr.GetDriverByName("MapInfo File")
> datasource = driver.Open(os.path.join(dirname,shapefileName))
> layer = datasource.GetLayer(0)
> geometryType = layer.GetGeomType()
>
> >>>geometryType
> >>>0
>
> Even when looping over features in layer and retrieving geometry type using
> GetDefnRef()<http://gdal.org/python/osgeo.ogr.Feature-class.html#GetGeometr
> yRef>.GetGeomType() the result is always 0 even for multi-polygon features.
You should call
g = feat.GetGeometryRef()
g.GetType()
to retrieve the geometry type of an individual feature, and that cannot be
0=wkbUnknown
layer.GetGeomType(), feat.GetDefnRef().GetGeomType() or
layer.GetLayerDefn().GetGeomType() are all alias, that will return the
declared layer geometry type, but not the geometry type of an actual feature.
Even
--
Geospatial professional services
http://even.rouault.free.fr/services.html
More information about the gdal-dev
mailing list