Using the VertexIterator - 52North/IlwisCore GitHub Wiki
The vertex iterator iterates over the vertices of a geometry
The VeretxIterator always takes a geometry is input. Geometries are owned by features, which in turn are in the FeatureCoverage. So ...
IFeatureCoverage features("file:///d:/data/world.shp");
FeatureIterator iter(features);
UPFeature& feature = *(iter + 10); // accessing the 10th feature
VertexIterator vertices(feature->geometry());
Note that the VertexIterator doesnt 'own' the geometry. The owner is still the feature. A related way is creating it by string.
VertextIterator vertices("Linestring((16.34 78.90, 14.55 74.23, 10.98 66.90) (8.23 59.43, 7.56 54.99))");
In this case a internal geometry is created which is deleted by the iterator when it goes out of scope.
The vertexiterator 'sees' all the points of a geometry is one long sequence of coordinates. So
std::vector<geos::geom::Coordinate> coords;
std::copy(begin(vertices), end(vertices), std::back_inserter(coords));
//transforming projected coordinates to geographic coordinates
ICoordinateSystem csy("code=proj4:+proj=utm +zone=29 +ellps=clrk80 +towgs84=-125,53,467,0,0,0,0");
std::transform(begin(coords), end(coords),begin(coords)[&](geos::geom::Coordinate& crd){
crd = csy->coord2latlon(crd);
});
should work. The vertexiterator has state. The vertices of a geometry are of course not always an orderly range of consecutive points. You might have a multi geometry or a polygon might have one or more holes. Suppose you want to split up multi-geometry into its parts
VertexIterator iter(multilinegeom);
std::vector<std::vector<geos::geom::Coordinate>> lineparts;
while(iter != end(iter)){
lineparts.push_back(std::vector<geos::geom::Coordinate>());
while(!iter.nextSubgeometry()){ // check if we jumped to next subgeometry
lineparts.back().push_back(*iter);
++iter;
}
}
There are of course also other ways of doing this, but this illustrates the use of the vertexiterator.