[gdal-dev] GetGeomType() for a MapInfo TAB using OGR MapInfo File driver
Even Rouault
even.rouault at mines-paris.org
Fri Apr 25 10:29:23 PDT 2014
Le vendredi 25 avril 2014 18:23:23, Max Demars a écrit :
> 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?
I imagine (I haven't coded that driver) that the reason is that regions can be
either a mix of Polygon and MultiPolygon, hence it is not possible to expose a
single geometry type.
Well, in the shapefile driver, the same situation occurs and we expose
wkbPolygon, but can indeed cause some issues when converting to other formats.
A potential solution would be to declare MultiPolygon as geometry type and
indeed return single Polygon in a MultiPolygon.
>
> -Max Demars
>
>
> On Thu, Apr 24, 2014 at 2:23 PM, Even Rouault
>
> <even.rouault at 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
--
Geospatial professional services
http://even.rouault.free.fr/services.html
More information about the gdal-dev
mailing list