Select features
Open($userInfo);
$map = new MgMap($siteConnection);
$map->Open($mapName);
// Get the geometry for the boundaries of District 6
$layer = $map->GetLayers()->GetItem('Districts');
$districtQuery = new MgFeatureQueryOptions();
$districtQuery->SetFilter("ID = '6'"); //ID property is string
$featureReader = $layer->SelectFeatures($districtQuery);
$featureReader->ReadNext();
$districtGeometryData = $featureReader->GetGeometry($layer->GetFeatureGeometryName());
// Convert the AGF binary data to MgGeometry.
$agfReaderWriter = new MgAgfReaderWriter();
$districtGeometry = $agfReaderWriter->Read($districtGeometryData);
// Create a filter to select the desired features. Combine
// a basic filter and a spatial filter.
$queryOptions = new MgFeatureQueryOptions();
$queryOptions->SetFilter("RNAME LIKE 'SCHMITT%'");
$queryOptions->SetSpatialFilter('SHPGEOM', $districtGeometry, MgFeatureSpatialOperations::Inside);
// Get the features from the feature source,
// turn it into a selection, then save the selection as XML.
$layer = $map->GetLayers()->GetItem('Parcels');
$featureReader = $layer->SelectFeatures($queryOptions);
$layer = $map->GetLayers()->GetItem('Parcels');
$selection = new MgSelection($map);
$selection->AddFeatures($layer, $featureReader, 0);
$selectionXml = $selection->ToXml();
echo 'Selecting parcels owned by Schmitt in District 6';
}
catch (MgException $e)
{
echo $e->GetExceptionMessage();
echo $e->GetDetails();
}
?>