Query Feature Class
The following example demonstrates how to query features from a Feature Class by one spatial query condition and one attribute query condition. The spatial query condition selects only features where the geometry intersects the specified polygon. The attribute query condition selects only features where the name attributes equals "Austria"
.
POST /api/gis/dataset/{id}/query
[ body ]
{
"conditions": [
{
"geometry": {"type": "Polygon", "coordinates": [...]}
"operator": "Intersects"
},
{
"name": "name"
"operator": "Equal"
"value": "Austria"
}
]
}
IGISClient _gisClient ;// see SDK how to get the client
var projectId = Guid.NewGuid(); // define relevant project id
var queryGeometryWkt = "POLYGON((7.59 53.21,23.76 53.21,23.76 44.70,7.59 44.70,7.59 53.21))";
var wktReader = new WKTReader();
var queryGeometry = wktReader.Read(queryGeometryWkt);
var conditions = new QueryCondition[] {
new AttributeQueryCondition { Name="name", Operator = AttributeOperator.Equal, Value = "Austria" },
new SpatialQueryCondition { Geometry = queryGeometry, Operator = SpatialOperator.Intersects }
};
var fc = await _gisClient.QueryFeatureClassAsync(_fixture.ProjectId, datasetId, conditions);
var attributes = fc.Attributes;
var features = fc.Features;
var firstFeature = features.First();
var firstGeometry = firstFeature.Geometry;
var firstAttributes = firstFeature.Attributes;
The SDK offers several spatial filters. The Intersection
is demonstrated above, another available spatial query condition is WithIn
operation. The example below shows how to limit query result to nearest 5 features to the given geometry.
POST /api/gis/dataset/{id}/query
[ body ]
{
"limitClause":
{
"type": "LimitToNearest",
"geometry": {"type": "Point", "coordinates": [14.22056, 50.76978]},
"limit":1
}
}
IGISClient _gisClient ;// see SDK how to get the client
var projectId = Guid.NewGuid(); // define relevant project id
var queryGeometryWkt = "POINT(14.22056, 50.76978)";
var wktReader = new WKTReader();
var queryGeometry = wktReader.Read(queryGeometryWkt);
var limit = new LimitToNearest() {
Limit = 5,
Geometry = queryGeometry
};
var fc = await _gisClient.QueryFeatureClassAsync(_fixture.ProjectId, datasetId, limitClause: limit);
var attributes = fc.Attributes;
var features = fc.Features;
var firstFeature = features.First();
var firstGeometry = firstFeature.Geometry;
var firstAttributes = firstFeature.Attributes;