Example: Selection

The following example creates a selection, then lists properties from the selected features. See the Working With Feature Data sample, in the Developer’s Guide samples, for the complete version.

It selects parcels within the boundaries of District 1 that are owned by SCHMITT. This requires a spatial filter and a basic filter.

$map = new MgMap($siteConnection);
$map->Open($mapName);
 
// Get the geometry for the boundaries of District 1
 
$districtQuery = new MgFeatureQueryOptions();
$districtQuery->SetFilter("Autogenerated_SDF_ID = 1");
 
$layer = $map->GetLayers()->GetItem('Districts');
$featureReader = $layer->SelectFeatures($districtQuery);
$featureReader->ReadNext();
$districtGeometryData = $featureReader->
GetGeometry('Data');
 
// 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);
 
// Select the features.
 
$layer = $map->GetLayers()->GetItem('Parcels');
$featureReader = $layer->SelectFeatures($queryOptions);
 
// For each selected feature, display the address.
 
echo '<p>Properties owned by Schmitt ';
echo 'in District 1</p><p>';
 
while ($featureReader->ReadNext())
{
  $val = $featureReader->GetString('RPROPAD');
  echo $val . '<br />';
}
echo '</p>';