To create a buffer around a feature, use the MgGeometry.Buffer() method. This returns an MgGeometry object that you can use for further analysis. For example, you could display the buffer by creating a feature in a temporary feature source and adding a new layer to the map. You could also use the buffer geometry as part of a spatial filter. For example, you might want to find all the features within the buffer zone that match certain criteria, or you might want to find all roads that cross the buffer zone.
To create a buffer, get the geometry of the feature to be buffered. If the feature is being processed in an MgFeatureReader as part of a selection, this requires getting the geometry data from the feature reader and converting it to an MgGeometry object. For example:
MgByteReader geometryData =
MgGeometry featureGeometry = agfReaderWriter.Read(geometryData);
string mapWktSrs = currentMap.GetMapSRS();
MgCoordinateSystemFactory coordSysFactory =
MgCoordinateSystem srs = coordSysFactory.Create(mapWktSrs);
MgCoordinateSystemMeasure srsMeasure = srs.GetMeasure();
double srsDist =
MgGeometry bufferGeometry =
- Create a feature source for the buffer. This may require creating a new file for the feature source. See Creating SDF files.
- Create a layer that references the feature source. Add it to the map and make it visible.
- Create a new feature using the buffer geometry and insert it into the feature source.
MgPropertyCollection properties = new MgPropertyCollection();
MgFeatureCommandCollection commands =
To use the buffer as part of a query, create a spatial filter using the buffer geometry, and use this in a call to AcMapLayer.SelectFeatures(). For example, the following code uses a basic filter and a spatial filter to select parcels inside the buffer area that are of type “MFG”. You can use the MgFeatureReader to perform tasks like generating a report of the parcels, or creating a new layer that puts point markers on each parcel.
MgFeatureQueryOptions queryOptions = new MgFeatureQueryOptions();
queryOptions.SetFilter("PARCELTYPE = 'MFG'");
MgResourceIdentifier featureResId = new MgResourceIdentifier(
MgFeatureReader featureReader =