Hi Even, Thank you for your reply, that explains a lot. I still wonder why there is not a possibility to return wkbPolygon like below:
if( numPoints > 0 && numLines == 0 && numRegions == 0 ) m_poDefn->SetGeomType( wkbPoint ); else if( numPoints == 0 && numLines > 0 && numRegions == 0 ) m_poDefn->SetGeomType( wkbLineString ); +++ else if ( numPoints == 0 && numLines == 0 && numRegions > 0 ) +++ m_poDefn->SetGeomType( wkbPolygon ); else /* we leave it unknown indicating a mixture */; Maybe there is also a way to check if the layer is made of multi geometries of one type (no mixture)... It looks to me that the mitab_ tabfile.cpp module could be improved that way. What do you think? -Max Demars On Thu, Apr 24, 2014 at 2:23 PM, Even Rouault <even.roua...@mines-paris.org>wrote: > 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 > -- Stack Overflow: http://stackoverflow.com/users/1914034/burton449 GIS Overflow: http://gis.stackexchange.com/users/14426/burton449 LastFm: http://www.lastfm.fr/user/burton449
_______________________________________________ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev