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 around a feature, use theMgFeatureReader as part of a selection, this requires getting the geometry data from the feature reader and converting it to an MgGeometry object. For example:
To create a buffer, get the geometry of the feature to be buffered. If the feature is being processed in an$geometryData =
$featureReader->GetGeometry($geometryName);
$featureGeometry = $agfReaderWriter->Read($geometryData);
MgCoordinateSystemMeasure object from the coordinate system for the map. For example:
If the buffer is to be calculated using coordinate system units, create an$mapWktSrs = $currentMap->GetMapSRS();
$coordSysFactory =
new MgCoordinateSystemFactory();
$srs = $coordSysFactory->Create($mapWktSrs);
$srsMeasure =
new MgCoordinateSystemMeasure($srs);
Use the coordinate system measure to determine the buffer size in the coordinate system, and create the buffer object from the geometry to be buffered.
$srsDist =
$srs->ConvertMetersToCoordinateSystemUnits($bufferDist);
$bufferGeometry =
$featureGeometry->Buffer($srsDist, $srsMeasure);
To display the buffer in the map, perform the following steps:
MgFeatureService::SelectFeatures(). For example, the following code selects 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.
To use the buffer as part of a query, create a spatial filter using the buffer geometry, and use this in a call to$queryOptions = new MgFeatureQueryOptions();
$queryOptions->SetFilter("RTYPE = 'MFG'");
$queryOptions->SetSpatialFilter('SHPGEOM', $bufferGeometry,
MgFeatureSpatialOperations::Inside);
$featureResId = new MgResourceIdentifier(
"Library://Samples/Sheboygan/Data/Parcels.FeatureSource");
$featureReader = $featureService->SelectFeatures($featureResId,
"Parcels", $queryOptions);