Spatial Filters

AutoCAD Map 3D Geospatial Platform API

 
Spatial Filters
 
 
 

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
NoteThe spatial operations are not case sensitive, so “CONTAINS” and “contains” produce the same result.

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.

NoteNot all spatial operations can be used on all features. It depends on the capabilities of the FDO provider that supplies the data. This restriction applies to separate spatial filters and spatial properties that are used in a basic filter.