Example: Listing Selected Features
 
 

The following example creates a selection, then lists properties from the selected features.

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<html>

 

   <head>

      <title>Selecting properties</title>

   </head>

 

   <body>

 

      <h1>Selection</h1>

 

         <?php

         include 'AppConstants.php';

 

         $mgSessionId = ($_SERVER['REQUEST_METHOD'] == "POST")?

            $_POST['SESSION']: $_GET['SESSION'];

         $mapName = ($_SERVER['REQUEST_METHOD'] == "POST")?

            $_POST['MAPNAME']: $_GET['MAPNAME'];

 

         try

         {

 

            //

Initialize the Web Extensions and connect to

            //

the Server using the Web Extensions session

            //

identifier stored in PHP session state.

 

            MgInitializeWebTier ($configFilePath);

 

            $userInfo = new MgUserInformation($mgSessionId);

            $siteConnection = new MgSiteConnection();

            $siteConnection->Open($userInfo);

 

            $resourceService = $siteConnection->                CreateService(MgServiceType::ResourceService);

            $featureService = $siteConnection->                CreateService(MgServiceType::FeatureService);

 

            $map = new MgMap();

            $map->Open($resourceService, $mapName);

 

            //

Get the geometry for the boundaries of District 1

 

            $districtQuery = new MgFeatureQueryOptions();

            $districtQuery->SetFilter("Autogenerated_SDF_ID = 1");

            $districtResId = new MgResourceIdentifier(

"Library://Samples/Sheboygan/Data/VotingDistricts.FeatureSource");

            $featureReader = $featureService->

               SelectFeatures($districtResId, "VotingDistricts",                $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.

 

            $featureResId = new MgResourceIdentifier(

"Library://Samples/Sheboygan/Data/Parcels.FeatureSource");

            $featureReader = $featureService->

               SelectFeatures($featureResId, "Parcels",

               $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>';

         }

         catch (MgException $e)

         {

            echo $e->GetMessage();

            echo $e->GetDetails();

         }

         ?>

   </body>

</html>