-
Notifications
You must be signed in to change notification settings - Fork 14
FeatureIterator
The FeatureIterator iterates over the features of one featurecoverage
IFeatureCoverage features("http://uger.co.uk/wfs/drainage_west"); // normalized url for wfs
// base construction for the whole map
FeatureIterator iterAll(features);
// limit the set of features by a query
std::vector<quint32> subset1 = features.select("within POLYGON((30 10, 40 40, 20 40, 10 20, 30 10))");
//or,
std::vector<quint32> subset2 = features.select("classification=\"small stream\"");
// subset contains the indexes of the features in the bounding box
FeatureIterator iterLimited1(features,subset1);
FeatureIterator iterLimited2(features,subset2);
FeatureIterators only iterate over the features, not over the geometries. The deref operator '*' gives access to the underlying interface of the feature currently being pointed to by the iterator; so
while(iterAll != end(features)){
QVariant somename= (*iterAll)("name"); // accessing the attribute 'name'
Envelope envelope = (*iterAll)->geometry()->envelope(); // getting the envelope of the geometry
cout << somename.toString().toStdString() << envelope.area();
}
returns for every feature its name and its area. The interface of the feature also gives access to the index of geometries that might be in the feature (see Features(s))
IFeatureCoverage icebergs("http://mydatbase:4032/southpole/icebergtracks");
for(auto iceberg : icebergs) {
cout << iceberg("identifier")->toString().toStdString();
for(int index = 0; index < icebergs->trackSize(); ++index){
const Coordinate *crd = iceberg->geometry(index)->coordinate();
cout << crd.x << crd.y;
}
cout << std::nl;
}
prints for every iceberg its identifier and the coordinates it had when drifting over the ocean. We see here accessing the geometries in the track and the use of the use of the implicit iterator ( in the outer for loop).
As most features have only one geometry, the 'geometry(quint32 index)' method of a Feature, defaults to 0 when no parameter value is given, so it returns the first (and only) geometry .
An important concept in relation to the FeatureIterator are the spatial-queries. Though there is a seperate script statement for it, queries are usually done by using the select method of a feature coverage. This generates an index vector which can be fed to the FeatureIterator.
IFeatureCoverage fc("kenya.mpa");
Indices areas= fc->select("contains(\"multipoint(39.434229 -1.262508,34.560120 -0.212529)\") and SQKM < 17000.00");
FeatureIterator(fc, areas);
In this query the index will be generated for all regions in the kenya polygon map that contain at least one of the two points mentioned in the multipoint and has ann attribute SQKM smaller than 17000. Currently Ilwis-Objects supports the spatial predicates
- Contains
- Covered
- CoveredBy
- Touches
- Intersects
- Disjoint
- Within
- Equals
- Crosses
- Overlaps
- Distance
The syntax for all the predicates apart from distance is: < predicate >(< wkt definition of geometry > ). Important is to know that the geometry definition can be either a single element geometry or a multi geometry. In case of the multi-geometry the predicate is tested against all seperate elements of the multi geometry seperately and if one holds true the relation holds true. So the multi-geometry isnt representing one geometry but a collection of geometries.