[Gdal-dev] ogr getnextfeature
Mateusz Loskot
mateusz at loskot.net
Fri Jan 19 08:51:04 EST 2007
mbaye wrote:
> Wath are doing Geometry.GetNextFeature in the following cases
> Geometry = polygon
> and
> Geometry = multipolygon
mbaye,
I'm sorry I don't understand your question.
1. What do you mean as "Geometry.GetNextFeature"?
There is no GetNextFeature() member function in Geometry class, as well
as there is no Geometry class in OGR.
http://www.gdal.org/ogr/classOGRGeometry.html
2. There is OGRLayer::GetNextFeature() and here you can read
how it works:
http://www.gdal.org/ogr/classOGRLayer.html#47d21ff33b32d14fa4e9885b9edecad6
3. Please, check the OGR tutorial, section "Reading from OGR" and check
what GetNextFeature() returns and how to use it to iterate through
features in data sources.
http://www.gdal.org/ogr/ogr_apitut.html
4. As it's described in resoruces I'm giving above, the GetNextFeature()
returns reference (pointer, in C/C++) to object of type of OGRFeature.
http://www.gdal.org/ogr/classOGRFeature.html
Next, you can ask for reference to geometry stored in fetched
feature using GetGeometryRef()
http://www.gdal.org/ogr/classOGRFeature.html#cc966ce8c10ae3ddf9f14c2736fdce9a
As the GetGeometryRef() returns pointer to base class of geometries
hierarchy, you need to cast it to one of specialized type - *based* on
type of geometries stored in the data soure using
OGRGeometry::getGeometryType() function:
http://www.gdal.org/ogr/classOGRGeometry.html#26fef0fc5e95c9e8e526922476c778bd
Check the OGR tutorial for example.
If the type of geometry is Polygon, the pointer returned by
GetGeometryRef() points in fact to OGRPolygon, so you need to cast it:
OGRPolygon *poPoly = (OGRPolygon *) poGeometry;
or if you prefer C++ casting operators:
OGRPolygon *poPoly = static_cast<OGRPolygon *>(poGeometry);
After this operation, you can use poPoly pointer to access interface of
OGRPolygon class which is described here:
http://www.gdal.org/ogr/classOGRPolygon.html
You can take similar steps for geometries of type of
OGRMultiPolygon class.
I'm still not sure if you're asking for explanation as given above,
but I hope it helps.
Cheers
--
Mateusz Loskot
http://mateusz.loskot.net
More information about the Gdal-dev
mailing list