Creating Geometry Objects From Features
 
 

You may want to use an existing feature as part of a spatial query. To retrieve the feature’s geometry and convert it into an appropriate format for a query, perform the following steps:

For example, the following sequence creates an MgGeometry object representing the boundaries of District 1 in the sample data.

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

$agfReaderWriter = new MgAgfReaderWriter();

$districtGeometry = $agfReaderWriter->Read($districtGeometryData);

To convert an MgGeometry object into its WKT representation, use the MgWktReaderWriter::Write() method, as in the following example:

$wktReaderWriter = new MgWktReaderWriter();

$districtWkt = $wktReaderWriter->Write($districtGeometry);