With spatial filters, you can do comparisons using geometric properties. For example, you can select all features that are inside an area on the map, or that intersect an area.
There are two ways of using spatial filters:
- Create a separate spatial filter to apply to the feature source, using the MgFeatureQueryOptions.SetSpatialFilter() method.
- Include spatial properties in a basic filter created with the MgFeatureQueryOptions.SetFilter() method.
The MgFeatureQueryOptions.SetSpatialFilter() method requires an MgGeometry object to define the geometry and a spatial operation to compare the feature property and the geometry. The spatial operations are defined in class MgFeatureSpatialOperations.
To include spatial properties in a basic filter, define the geometry using WKT format. Use the GEOMFROMTEXT() function in the basic filter, along with one of the following spatial operations:
- CONTAINS
- COVEREDBY
- CROSSES
- DISJOINT
- EQUALS
- INTERSECTS
- OVERLAPS
- TOUCHES
- WITHIN
- INSIDE
For example, the following selects features that cross an area:
queryOptions.SetFilter(
"SHPGEOM crosses GEOMFROMTEXT(" + wktGeom + ")" );
The same filtering syntax can be used in a layer definition, to create a layer containing only those features that pass the filter. See Filtering Layers By Geometry for details.