Exemplo n.º 1
0
function EmitAddressResults($featureService, $addressMarkerDataResId, $mgSessionId)
{
    echo '<table class="RegText" border="0" cellspacing="0" width="100%">';
    echo '<tr><td class="SubTitle">Previous Results</td></tr>';
    $geometryReaderWriter = new MgAgfReaderWriter();
    $featureReader = $featureService->SelectFeatures($addressMarkerDataResId, 'AddressMarker', null);
    while ($featureReader->ReadNext()) {
        $address = $featureReader->GetString('Address');
        $byteReader = $featureReader->GetGeometry('Location');
        $geometry = $geometryReaderWriter->Read($byteReader);
        $x = $geometry->GetCoordinate()->GetX();
        $y = $geometry->GetCoordinate()->GetY();
        echo '<tr><td>';
        echo '<img src="../images/pushpinblue.jpg">';
        echo '<a href="gotopoint.php?X=' . $x . '&Y=' . $y . '&Scale=2000" target="scriptFrame"> ' . $address . '</a></td></tr>';
    }
    $featureReader->Close();
    echo '</table>';
    echo '<form action="clearaddressresults.php" method="get" target="scriptFrame">';
    echo '<input type="hidden" name="SESSION" value="' . $mgSessionId . '">';
    echo '<input type="button" class="Ctrl" value="Clear Results" onClick="javascript:submit()">';
    echo '</form>';
    echo '<hr>';
}
Exemplo n.º 2
0
function MultiGeometryFromSelection($featureSrvc, $map, $selText)
{
    $sel = new MgSelection($map, $selText);
    $selLayers = $sel->GetLayers();
    $geomColl = new MgGeometryCollection();
    $agfRW = new MgAgfReaderWriter();
    $simplyPolygonOnly = true;
    for ($i = 0; $i < $selLayers->GetCount(); $i++) {
        $layer = $selLayers->GetItem($i);
        $filter = $sel->GenerateFilter($layer, $layer->GetFeatureClassName());
        $query = new MgFeatureQueryOptions();
        $query->SetFilter($filter);
        $featureSource = new MgResourceIdentifier($layer->GetFeatureSourceId());
        $features = $featureSrvc->SelectFeatures($featureSource, $layer->GetFeatureClassName(), $query);
        if ($features) {
            $classDef = $features->GetClassDefinition();
            $geomPropName = $classDef->GetDefaultGeometryPropertyName();
            $j = 0;
            while ($features->ReadNext()) {
                $geomReader = $features->GetGeometry($geomPropName);
                $geom = $agfRW->Read($geomReader);
                $type = $geom->GetGeometryType();
                if ($type == MgGeometryType::MultiPolygon || $type == MgGeometryType::CurvePolygon || $type == MgGeometryType::MultiCurvePolygon) {
                    $simplyPolygonOnly = false;
                } else {
                    if ($type != MgGeometryType::Polygon) {
                        continue;
                    }
                }
                $geomColl->Add($geom);
            }
        }
    }
    if ($geomColl->GetCount() == 0) {
        return null;
    }
    $gf = new MgGeometryFactory();
    if ($simplyPolygonOnly) {
        $polyColl = new MgPolygonCollection();
        for ($i = 0; $i < $geomColl->GetCount(); $i++) {
            $polyColl->Add($geomColl->GetItem($i));
        }
        return $gf->CreateMultiPolygon($polyColl);
    } else {
        return $gf->CreateMultiGeometry($geomColl);
    }
}
Exemplo n.º 3
0
 function InsertCommand($key)
 {
     $props = new MgPropertyCollection();
     $keyProp = new MgStringProperty("SKEY", $key);
     $props->Add($keyProp);
     $nameProp = new MgStringProperty("NAME", "StringKey" . $key);
     $props->Add($nameProp);
     $wkt = new MgWktReaderWriter();
     $agf = new MgAgfReaderWriter();
     $geom = $wkt->Read("POLYGON ((20 20, 20 100, 120 100, 140 20, 20 20))");
     $geomReader = $agf->Write($geom);
     $geomProp = new MgGeometryProperty("GEOM", $geomReader);
     $props->Add($geomProp);
     $cmd = new MgInsertFeatures("StringKey", $props);
     return $cmd;
 }
Exemplo n.º 4
0
 $map->Open($mapName);
 // Check for selection data passed via HTTP POST
 if (isset($_POST['SELECTION']) && $_POST['SELECTION'] != '') {
     $selection = new MgSelection($map, $_POST['SELECTION']);
     $selectedLayers = $selection->GetLayers();
 } else {
     $selectedLayers = 0;
 }
 if ($selectedLayers) {
     include 'bufferfunctions.php';
     $bufferRingSize = 100;
     // measured in metres
     $bufferRingCount = 5;
     // Set up some objects for coordinate conversion
     $mapWktSrs = $map->GetMapSRS();
     $agfReaderWriter = new MgAgfReaderWriter();
     $wktReaderWriter = new MgWktReaderWriter();
     $coordinateSystemFactory = new MgCoordinateSystemFactory();
     $srs = $coordinateSystemFactory->Create($mapWktSrs);
     $srsMeasure = $srs->GetMeasure();
     // Check for a buffer layer. If it exists, delete
     // the current features.
     // If it does not exist, create a feature source and
     // a layer to hold the buffer.
     /*
     // Old way, pre MapGuide OS 2.0. Kept here for reference
     try
     {
       $bufferLayer = $map->GetLayers()->GetItem('Buffer');
       $bufferFeatureResId = new MgResourceIdentifier($bufferLayer->GetFeatureSourceId());
     
Exemplo n.º 5
0
     $addressLayer = GetLayerByName($map, 'AddressMarker');
     if ($addressLayer == null) {
         CreateAddressMarkerFeatureSource($featureService, $addressMarkerDataResId);
         $addressLayer = CreateAddressMarkerLayer($resourceService, $addressMarkerDataResId, $mgSessionId);
         $map->GetLayers()->Insert(0, $addressLayer);
     } else {
         if ($addressLayer->GetVisible()) {
             // If the layer exists and is visible, then display the
             // previous results.
             EmitAddressResults($featureService, $addressMarkerDataResId, $mgSessionId);
         }
     }
     // Insert the results of the Geo-Code into the temporary
     // feature source and ensure the address marker layer
     // is visible.
     $geometryReaderWriter = new MgAgfReaderWriter();
     $geometryFactory = new MgGeometryFactory();
     $addrPoint = $geometryFactory->CreatePoint($geometryFactory->CreateCoordinateXY((double) $long, (double) $lat));
     $properties = new MgPropertyCollection();
     $properties->Add(new MgStringProperty('Address', $address1));
     $properties->Add(new MgGeometryProperty('Location', $geometryReaderWriter->Write($addrPoint)));
     $commands = new MgFeatureCommandCollection();
     $commands->Add(new MgInsertFeatures('AddressMarker', $properties));
     $featureService->UpdateFeatures($addressMarkerDataResId, $commands, false);
     $addressLayer->SetVisible(true);
     $addressLayer->ForceRefresh();
     $map->Save($resourceService);
     $success = true;
 } else {
     echo '<tr><td>Address not found: ' . $address . '<hr></td></tr>';
     $success = false;
Exemplo n.º 6
0
            if ($layer == null) {
                $legendName = GetLocalizedString("MEASURELAYER", $locale);
                $layer = new MgLayer($layerDefId, $resourceSrvc);
                $layer->SetDisplayInLegend(true);
                $layer->SetLegendLabel($legendName);
                $layers->Insert(0, $layer);
            }
        }
        // create a feature representing this segment and insert it into the data source
        //
        $measureProps = new MgPropertyCollection();
        $partialProp = new MgDoubleProperty("PARTIAL", $distance);
        $measureProps->Add($partialProp);
        $totalProp = new MgDoubleProperty("TOTAL", $total);
        $measureProps->Add($totalProp);
        $agf = new MgAgfReaderWriter();
        $geomReader = $agf->Write($geom);
        $geomProp = new MgGeometryProperty("GEOM", $geomReader);
        $measureProps->Add($geomProp);
        $cmd = new MgInsertFeatures($featureName, $measureProps);
        $commands = new MgFeatureCommandCollection();
        $commands->Add($cmd);
        ReleaseReader($featureSrvc->UpdateFeatures($dataSourceId, $commands, false));
    }
    if ($layer != null) {
        $layer->ForceRefresh();
    }
    $map->Save($resourceSrvc);
} catch (MgException $e) {
    OnError(GetLocalizedString("MEASUREERROR", $locale), $e->GetDetails());
    return;
Exemplo n.º 7
0
 function Execute()
 {
     $result = array();
     $resourceService = $this->site->CreateService(MgServiceType::ResourceService);
     $map = new MgMap();
     $map->Open($resourceService, $this->args['MAPNAME']);
     $layer = $map->GetLayers()->GetItem($this->args['LAYERNAME']);
     $featureService = $this->site->CreateService(MgServiceType::FeatureService);
     $resId = new MgResourceIdentifier($layer->GetFeatureSourceId());
     $featureClass = $layer->GetFeatureClassName();
     $featureGeometry = $layer->GetFeatureGeometryName();
     // Initialize the coordinate system transform
     $schemaAndClass = explode(":", $featureClass);
     $classDef = $featureService->GetClassDefinition($resId, $schemaAndClass[0], $schemaAndClass[1]);
     $geomProp = $classDef->GetProperties()->GetItem($featureGeometry);
     $spatialContext = $geomProp->GetSpatialContextAssociation();
     $csTransform = null;
     $csInverseTransform = null;
     $coordSysFactory = new MgCoordinateSystemFactory();
     $scReader = $featureService->GetSpatialContexts($resId, false);
     while ($scReader->ReadNext() && $csTransform == null) {
         if ($scReader->GetName() == $spatialContext) {
             $source = $coordSysFactory->Create($scReader->GetCoordinateSystemWkt());
             $target = $coordSysFactory->Create($map->GetMapSRS());
             $csTransform = new MgCoordinateSystemTransform($source, $target);
             $csInverseTransform = new MgCoordinateSystemTransform($target, $source);
         }
     }
     $scReader->Close();
     // Execute the query
     $queryMax = (int) $this->args['QUERYMAX'];
     $queryOptions = new MgFeatureQueryOptions();
     if ($this->args['USEPROPERTYFILTER'] == 'true') {
         $propertyFilter = $this->args['PROPERTYNAME'];
         if ($this->args['ISSTRING'] == 'true') {
             $propertyFilter .= sprintf($this->strExpressions[$this->args['OPERATOR']], $this->args['VALUE']);
         } else {
             $propertyFilter .= sprintf($this->numExpressions[$this->args['OPERATOR']], $this->args['VALUE']);
         }
         $queryOptions->SetFilter($propertyFilter);
     }
     if ($this->args['USESPATIALFILTER'] == 'true') {
         $polygon = $this->CreatePolygonFromGeomText($this->args['GEOMTEXT']);
         $polygon = $polygon->Transform($csInverseTransform);
         $queryOptions->SetSpatialFilter($featureGeometry, $polygon, MgFeatureSpatialOperations::Intersects);
     }
     $count = 0;
     $geometryReaderWriter = new MgAgfReaderWriter();
     $featureReader = $featureService->SelectFeatures($resId, $layer->GetFeatureClassName(), $queryOptions);
     while ($featureReader->ReadNext() && ($queryMax <= 0 || $count < $queryMax)) {
         $displayValue = $this->GetFeaturePropertyValue($featureReader, $this->args['OUTPUTPROPERTY']);
         $byteReader = $featureReader->GetGeometry($featureGeometry);
         $geometry = $geometryReaderWriter->Read($byteReader);
         $centerPoint = $geometry->GetCentroid();
         $centerPoint = $centerPoint->Transform($csTransform);
         $idList = $this->GetFeatureIdList($map, $layer, $featureReader);
         array_push($result, new Feature($displayValue, $centerPoint, $idList));
         $count++;
     }
     return $result;
 }
Exemplo n.º 8
0
echo "Created sdfparams\n";
$layerName = 'Library://TrevorWekel/NewSdf.FeatureSource';
$id = new MgResourceIdentifier($layerName);
try {
    $svc->CreateFeatureSource($id, $params);
} catch (MgException $exc) {
    echo $exc->GetExceptionMessage() . "\n";
    echo $exc->GetDetails() . "\n";
    return;
}
echo "Created featuresource\n";
// We need to add some data to the sdf before using it.  The spatial context
// reader must have an extent.
$batchProp = new MgBatchPropertyCollection();
$wkt = new MgWktReaderWriter();
$agf = new MgAgfReaderWriter();
$fact = new MgGeometryFactory();
echo "Created wkt/agf\n";
$count = 100;
$i = 0;
for ($i = 1; $i <= $count; $i++) {
    $bufferProps = new MgPropertyCollection();
    $nameProp = new MgStringProperty("NAME", "NewName_" . $i);
    $bufferProps->Add($nameProp);
    $x = 120 + $i / $count;
    $y = 100 + $i / $count;
    //$wktText = "POLYGON ((20 20, 20 100, {$x} {$y}, 140 20, 20 20))";
    //$geom = $wkt->Read($wktText);
    $coord = $fact->CreateCoordinateXY($x, $y);
    $geom = $fact->CreatePoint($coord);
    $geomReader = $agf->Write($geom);
Exemplo n.º 9
0
 function AddPolygon()
 {
     $geometryFactory = new MgGeometryFactory();
     $agfWriter = new MgAgfReaderWriter();
     $vertices = explode(',', $this->args['GEOMETRY']);
     $count = $vertices[0];
     $coords = new MgCoordinateCollection();
     for ($i = 0; $i < $count; $i++) {
         $coord = $geometryFactory->CreateCoordinateXY((double) $vertices[$i * 2 + 1], (double) $vertices[$i * 2 + 2]);
         $coords->Add($coord);
     }
     // Add the first vertex to make the ring close
     if ($count > 2) {
         $coord = $geometryFactory->CreateCoordinateXY((double) $vertices[1], (double) $vertices[2]);
         $coords->Add($coord);
     }
     $linearRing = $geometryFactory->CreateLinearRing($coords);
     $polygon = $geometryFactory->CreatePolygon($linearRing, null);
     $trans = $this->GetTransform();
     if (null != $trans) {
         $polygon = $polygon->Transform($trans);
     }
     $byteReader = $agfWriter->Write($polygon);
     $propertyValues = new MgPropertyCollection();
     $propertyValues->Add(new MgStringProperty('Text', $this->args['TEXT']));
     $propertyValues->Add(new MgGeometryProperty('Geometry', $byteReader));
     $this->InsertMarkupFeature($propertyValues);
 }
Exemplo n.º 10
0
 private function OutputXml($schemas)
 {
     $read = 0;
     $agfRw = new MgAgfReaderWriter();
     $wktRw = new MgWktReaderWriter();
     $this->writer->SetHeader("Content-Type", MgMimeType::Xml);
     $this->writer->StartChunking();
     $output = "<?xml version=\"1.0\" encoding=\"utf-8\"?><FeatureSet>";
     if (!$this->IsEmpty($schemas)) {
         $classXml = $this->featSvc->SchemaToXml($schemas);
         $classXml = substr($classXml, strpos($classXml, "<xs:schema"));
         $output .= $classXml;
     }
     $hasMoreFeatures = $this->reader->ReadNext();
     $writeXmlFooter = false;
     if ($hasMoreFeatures) {
         $output .= "<Features>";
         $this->writer->WriteChunk($output);
         $output = "";
         $writeXmlFooter = true;
     }
     $propCount = $this->reader->GetPropertyCount();
     while ($hasMoreFeatures) {
         $read++;
         if ($this->limit > 0 && $read > $this->limit) {
             break;
         }
         $output = "<Feature>";
         for ($i = 0; $i < $propCount; $i++) {
             $name = $this->reader->GetPropertyName($i);
             $propType = $this->reader->GetPropertyType($i);
             $output .= "<Property><Name>{$name}</Name>";
             if (!$this->reader->IsNull($i)) {
                 $output .= "<Value>";
                 switch ($propType) {
                     case MgPropertyType::Boolean:
                         //NOTE: It appears PHP booleans are not string-able
                         $output .= $this->reader->GetBoolean($i) ? "true" : "false";
                         break;
                     case MgPropertyType::Byte:
                         $output .= $this->reader->GetByte($i);
                         break;
                     case MgPropertyType::DateTime:
                         $dt = $this->reader->GetDateTime($i);
                         $output .= $dt->ToString();
                         break;
                     case MgPropertyType::Decimal:
                     case MgPropertyType::Double:
                         $output .= $this->reader->GetDouble($i);
                         break;
                     case MgPropertyType::Geometry:
                         try {
                             $agf = $this->reader->GetGeometry($i);
                             $geom = $this->transform != null ? $agfRw->Read($agf, $this->transform) : $agfRw->Read($agf);
                             $output .= $wktRw->Write($geom);
                         } catch (MgException $ex) {
                         }
                         break;
                     case MgPropertyType::Int16:
                         $output .= $this->reader->GetInt16($i);
                         break;
                     case MgPropertyType::Int32:
                         $output .= $this->reader->GetInt32($i);
                         break;
                     case MgPropertyType::Int64:
                         $output .= $this->reader->GetInt64($i);
                         break;
                     case MgPropertyType::Single:
                         $output .= $this->reader->GetSingle($i);
                         break;
                     case MgPropertyType::String:
                         $output .= MgUtils::EscapeXmlChars($this->reader->GetString($i));
                         break;
                 }
                 $output .= "</Value>";
             }
             $output .= "</Property>";
         }
         $output .= "</Feature>";
         $this->writer->WriteChunk($output);
         $output = "";
         $hasMoreFeatures = $this->reader->ReadNext();
     }
     if ($writeXmlFooter) {
         $output .= "</Features>";
     }
     $output .= "</FeatureSet>";
     $this->writer->WriteChunk($output);
     $this->writer->EndChunking();
     $this->reader->Close();
 }
Exemplo n.º 11
0
 $borderColor = $_REQUEST['bordercolor'];
 $schemaName = 'BufferSchema';
 $map = new MgMap();
 $map->Open($resourceService, $mapName);
 /* Get the map SRS - we use this to convert distances */
 $srsFactory = new MgCoordinateSystemFactory();
 //safely get an SRS ... (in Utilities)
 $srsDefMap = GetMapSRS($map);
 $mapSrsUnits = "";
 $srsMap = $srsFactory->Create($srsDefMap);
 $arbitraryMapSrs = $srsMap->GetType() == MgCoordinateSystemType::Arbitrary;
 if ($arbitraryMapSrs) {
     $mapSrsUnits = $srsMap->GetUnits();
 }
 $featureService = $siteConnection->CreateService(MgServiceType::FeatureService);
 $agfRW = new MgAgfReaderWriter();
 $layers = $map->GetLayers();
 try {
     /* if the layer already exists, we'll clear the existing features
      * from it and reset the content
      */
     $bValidLayer = false;
     $j = 2;
     while (!$bValidLayer) {
         $layer = $layers->GetItem($layerName);
         $featureClassName = $layer->GetFeatureClassName();
         if ($featureClassName != $schemaName . ':' . $layerName) {
             $layerName = $layerName . ' (' . $j . ')';
         } else {
             $bValidLayer = true;
         }
Exemplo n.º 12
0
 private function CollectQueryMapFeaturesResult($resSvc, $reqData, $featInfo, $selection, $bRequestAttributes, $inlineSelectionImg)
 {
     $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<FeatureInformation>\n";
     $tooltip = "";
     $hyperlink = "";
     if ($featInfo != null) {
         $tooltip = $featInfo->GetTooltip();
         $hyperlink = $featInfo->GetHyperlink();
     }
     $selXml = $selection->ToXml();
     if (strlen($selXml) > 0) {
         //Need to strip the XML prolog from this fragment
         $fsdoc = new DOMDocument();
         $fsdoc->loadXML($selXml);
         $selXml = $fsdoc->saveXML($fsdoc->documentElement);
         $xml .= $selXml;
     } else {
         $xml .= "<FeatureSet />\n";
     }
     if (($reqData & self::REQUEST_TOOLTIP) == self::REQUEST_TOOLTIP && strlen($tooltip) > 0) {
         $xml .= "<Tooltip>" . MgUtils::EscapeXmlChars($tooltip) . "</Tooltip>\n";
     } else {
         $xml .= "<Tooltip />\n";
     }
     if (($reqData & self::REQUEST_HYPERLINK) == self::REQUEST_HYPERLINK && strlen($hyperlink) > 0) {
         $xml .= "<Hyperlink>" . MgUtils::EscapeXmlChars($hyperlink) . "</Hyperlink>\n";
     } else {
         $xml .= "<Hyperlink />\n";
     }
     if (($reqData & self::REQUEST_INLINE_SELECTION) == self::REQUEST_INLINE_SELECTION && $inlineSelectionImg != null) {
         $xml .= "<InlineSelectionImage>\n";
         $xml .= "<MimeType>" . $inlineSelectionImg->GetMimeType() . "</MimeType>\n";
         $b64 = MgUtils::ByteReaderToBase64($inlineSelectionImg);
         $xml .= "<Content>{$b64}</Content>\n";
         $xml .= "</InlineSelectionImage>\n";
     }
     if ($bRequestAttributes) {
         $agfRw = new MgAgfReaderWriter();
         $layerDoc = new DOMDocument();
         $xml .= "<SelectedFeatures>";
         $selLayers = $selection->GetLayers();
         if ($selLayers != null) {
             $selLayerCount = $selLayers->GetCount();
             for ($i = 0; $i < $selLayerCount; $i++) {
                 $selLayer = $selLayers->GetItem($i);
                 $layerName = $selLayer->GetName();
                 $xml .= "<SelectedLayer id=\"" . $selLayer->GetObjectId() . "\" name=\"{$layerName}\">";
                 $xml .= "<LayerMetadata>\n";
                 $ldfId = $selLayer->GetLayerDefinition();
                 $layerContent = $resSvc->GetResourceContent($ldfId);
                 $layerDoc->loadXML($layerContent->ToString());
                 $propMapNodes = $layerDoc->getElementsByTagName("PropertyMapping");
                 $clsDef = $selLayer->GetClassDefinition();
                 $clsProps = $clsDef->GetProperties();
                 $propMappings = array();
                 for ($j = 0; $j < $propMapNodes->length; $j++) {
                     $propMapNode = $propMapNodes->item($j);
                     $propName = $propMapNode->getElementsByTagName("Name")->item(0)->nodeValue;
                     $pidx = $clsProps->IndexOf($propName);
                     if ($pidx >= 0) {
                         $propDispName = MgUtils::EscapeXmlChars($propMapNode->getElementsByTagName("Value")->item(0)->nodeValue);
                         $propDef = $clsProps->GetItem($pidx);
                         $propType = MgPropertyType::Null;
                         if ($propDef->GetPropertyType() == MgFeaturePropertyType::DataProperty) {
                             $propType = $propDef->GetDataType();
                         } else {
                             if ($propDef->GetPropertyType() == MgFeaturePropertyType::DataProperty) {
                                 $propType = MgPropertyType::Geometry;
                             }
                         }
                         $xml .= "<Property>\n";
                         $xml .= "<Name>{$propName}</Name>\n<Type>{$propType}</Type>\n<DisplayName>{$propDispName}</DisplayName>\n";
                         $xml .= "</Property>\n";
                         $propMappings[$propName] = $propDispName;
                     }
                 }
                 $xml .= "</LayerMetadata>\n";
                 $reader = $selection->GetSelectedFeatures($selLayer, $selLayer->GetFeatureClassName(), false);
                 $rdrClass = $reader->GetClassDefinition();
                 $geomPropName = $rdrClass->GetDefaultGeometryPropertyName();
                 while ($reader->ReadNext()) {
                     $xml .= "<Feature>\n";
                     $bounds = "";
                     if (!$reader->IsNull($geomPropName)) {
                         $agf = $reader->GetGeometry($geomPropName);
                         $geom = $agfRw->Read($agf);
                         $env = $geom->Envelope();
                         $ll = $env->GetLowerLeftCoordinate();
                         $ur = $env->GetUpperRightCoordinate();
                         $bounds = $ll->GetX() . " " . $ll->GetY() . " " . $ur->GetX() . " " . $ur->GetY();
                     }
                     $xml .= "<Bounds>{$bounds}</Bounds>\n";
                     foreach ($propMappings as $propName => $displayName) {
                         $value = MgUtils::EscapeXmlChars(MgUtils::GetBasicValueFromReader($reader, $propName));
                         $xml .= "<Property>\n";
                         $xml .= "<Name>{$displayName}</Name>\n";
                         if (!$reader->IsNull($propName)) {
                             $xml .= "<Value>{$value}</Value>\n";
                         }
                         $xml .= "</Property>\n";
                     }
                     $xml .= "</Feature>\n";
                 }
                 $reader->Close();
                 $xml .= "</SelectedLayer>";
             }
         }
         $xml .= "</SelectedFeatures>";
     }
     $xml .= "</FeatureInformation>";
     return $xml;
 }
Exemplo n.º 13
0
 $map = new MgMap($siteConnection);
 $map->Open($mapName);
 // Check for selection data passed via HTTP POST
 if (isset($_POST['SELECTION']) && $_POST['SELECTION'] != '') {
     $selection = new MgSelection($map, $_POST['SELECTION']);
     $selectedLayers = $selection->GetLayers();
 } else {
     $selectedLayers = 0;
 }
 if ($selectedLayers) {
     include 'bufferfunctions.php';
     $bufferRingSize = 500;
     // measured in metres
     // Set up some objects for coordinate conversion
     $mapWktSrs = $map->GetMapSRS();
     $agfReaderWriter = new MgAgfReaderWriter();
     $wktReaderWriter = new MgWktReaderWriter();
     $coordinateSystemFactory = new MgCoordinateSystemFactory();
     $srs = $coordinateSystemFactory->Create($mapWktSrs);
     $srsMeasure = $srs->GetMeasure();
     // Check for a buffer layer. If it exists, delete
     // the current features.
     // If it does not exist, create a feature source and
     // a layer to hold the buffer.
     /*
     // Old way, pre MapGuide OS 2.0. Kept here for reference
     try
     {
       $bufferLayer = $map->GetLayers()->GetItem('Buffer');
       $bufferFeatureResId = new MgResourceIdentifier($bufferLayer->GetFeatureSourceId());
     
Exemplo n.º 14
0
                if ($layer && $layer->GetName() == 'Parcels') {
                    // Create a filter containing the IDs of the selected features on this layer
                    $layerClassName = $layer->GetFeatureClassName();
                    $selectionString = $selection->GenerateFilter($layer, $layerClassName);
                    // Get the feature resource for the selected layer
                    $layerFeatureId = $layer->GetFeatureSourceId();
                    $layerFeatureResource = new MgResourceIdentifier($layerFeatureId);
                    // Apply the filter to the feature resource for the selected layer. This returns
                    // an MgFeatureReader of all the selected features.
                    $queryOptions->SetFilter($selectionString);
                    $featureReader = $featureService->SelectFeatures($layerFeatureResource, $layerClassName, $queryOptions);
                    // Create the report details using the first selected parcel. Position the image so the
                    // centroid of the selected parcel is in the center of the map.
                    $featureReader->ReadNext();
                    $featureAgfGeometry = $featureReader->GetGeometry('SHPGEOM');
                    $agfReaderWriter = new MgAgfReaderWriter();
                    $featureGeometry = $agfReaderWriter->Read($featureAgfGeometry);
                    $centroid = $featureGeometry->GetCentroid();
                    $mapCenterX = $centroid->GetCoordinate()->GetX();
                    $mapCenterY = $centroid->GetCoordinate()->GetY();
                    $owner = $featureReader->GetString('RNAME');
                    $address = $featureReader->GetString('RPROPAD');
                    $billingAddress = $featureReader->GetString('RBILAD');
                    $description = $featureReader->GetString('RLDESCR1') . '<br/>' . $featureReader->GetString('RLDESCR2') . '<br/>' . $featureReader->GetString('RLDESCR3') . '<br/>';
                }
            }
        }
    }
} catch (MgException $e) {
    echo '<p>' . $e->GetExceptionMessage() . '</p>';
    echo '<p>' . $e->GetDetails() . '</p>';
Exemplo n.º 15
0
 private static function GetLayerExtent($csFactory, $doc, $csObj, $featSvc, $resSvc)
 {
     $agfRw = new MgAgfReaderWriter();
     $vlNodes = $doc->getElementsByTagName("VectorLayerDefinition");
     $glNodes = $doc->getElementsByTagName("GridLayerDefinition");
     $dlNodes = $doc->getElementsByTagName("DrawingLayerDefinition");
     if ($vlNodes->length == 1 || $glNodes->length == 1) {
         $node = null;
         if ($vlNodes->length == 1) {
             $node = $vlNodes->item(0);
         } else {
             if ($glNodes->length == 1) {
                 $node = $glNodes->item(0);
             }
         }
         $resIdStr = $node->getElementsByTagName("ResourceId")->item(0)->nodeValue;
         $qClsName = $node->getElementsByTagName("FeatureName")->item(0)->nodeValue;
         $geom = $node->getElementsByTagName("Geometry")->item(0)->nodeValue;
         $tokens = explode(":", $qClsName);
         $fsId = new MgResourceIdentifier($resIdStr);
         $clsDef = $featSvc->GetClassDefinition($fsId, $tokens[0], $tokens[1]);
         $clsProps = $clsDef->GetProperties();
         $scReader = $featSvc->GetSpatialContexts($fsId, false);
         $pi = $clsProps->IndexOf($geom);
         $scName = null;
         if ($pi >= 0) {
             $prop = $clsProps->GetItem($pi);
             if (is_callable(array($prop, "GetSpatialContextAssociation"))) {
                 $scName = $prop->GetSpatialContextAssociation();
             }
         }
         if ($scName == null) {
             if ($scReader->ReadNext()) {
                 $sourceCs = $csFactory->Create($scReader->GetCoordinateSystemWkt());
                 $transform = $csFactory->GetTransform($sourceCs, $csObj);
                 $scExtent = $scReader->GetExtent();
                 if ($scExtent != null) {
                     $geom = $agfRw->Read($scExtent);
                     if ($geom != null) {
                         return $geom->Envelope();
                     }
                 }
             }
         } else {
             while ($scReader->ReadNext()) {
                 if ($scReader->GetName() == $scName) {
                     $sourceCs = $csFactory->Create($scReader->GetCoordinateSystemWkt());
                     $transform = $csFactory->GetTransform($sourceCs, $csObj);
                     $scExtent = $scReader->GetExtent();
                     if ($scExtent != null) {
                         $geom = $agfRw->Read($scExtent);
                         if ($geom != null) {
                             return $geom->Envelope();
                         }
                     }
                 }
             }
         }
     } else {
         if ($dlNodes->length == 1) {
             $dsId = new MgResourceIdentifier($dlNodes->item(0)->getElementsByTagName("ResourceId")->item(0)->nodeValue);
             $sheetName = $dlNodes->item(0)->getElementsByTagName("Sheet")->nodeValue;
             $dsContent = $resSvc->GetResourceContent($dsId);
             $dsDoc = new DOMDocument();
             $dsDoc->loadXML($dsContent->ToString());
             $csNodes = $dsDoc->getElementsByTagName("CoordinateSpace");
             $csTrans = null;
             if ($csNodes->length == 1) {
                 $srcCs = $csFactory->Create($csNodes->item(0)->nodeValue);
                 $csTrans = $csFactory->GetTransform($srcCs, $csObj);
                 $csTrans->IgnoreDatumShiftWarning(true);
                 $csTrans->IgnoreOutsideDomainWarning(true);
             }
             $shtNodes = $dlNodes->item(0)->getElementsByTagName("Sheet");
             if ($shtNodes->length > 0) {
                 for ($i = 0; $i < $shtNodes->length; $i++) {
                     $shtNode = $shtNodes->item($i);
                     $shtName = $shtNode->getElementsByTagName("Name")->item(0)->nodeValue;
                     if ($sheetName == $shtName) {
                         $extNodes = $shtNode->getElementsByTagName("Extent");
                         if ($extNodes->length == 1) {
                             $minX = $extNodes->item(0)->getElementsByTagName("MinX")->item(0)->nodeValue;
                             $minY = $extNodes->item(0)->getElementsByTagName("MinY")->item(0)->nodeValue;
                             $maxX = $extNodes->item(0)->getElementsByTagName("MaxX")->item(0)->nodeValue;
                             $maxY = $extNodes->item(0)->getElementsByTagName("MaxY")->item(0)->nodeValue;
                             $env = new MgEnvelope($minX, $minY, $maxX, $maxY);
                             if ($csTrans != null) {
                                 return $env->Transform($csTrans);
                             } else {
                                 return $env;
                             }
                         }
                     }
                 }
             }
         }
     }
     return null;
 }
Exemplo n.º 16
0
     $featureSrvc->CreateFeatureSource($dataSourceId, $sdfParams);
     //Add layer to map
     $layer = new MgLayer($layerDefId, $resourceSrvc);
     $layer->SetName($bufferName);
     $layer->SetLegendLabel($bufferName);
     $layer->SetDisplayInLegend(true);
     $layer->SetSelectable(true);
     $layers->Insert(0, $layer);
 } else {
     //data source already exist. clear its content
     //
     ClearDataSource($featureSrvc, $dataSourceId, $featureName);
 }
 $sel = new MgSelection($map, $selText);
 $selLayers = $sel->GetLayers();
 $agfRW = new MgAgfReaderWriter();
 $bufferGeometries = new MgGeometryCollection();
 $commands = new MgFeatureCommandCollection();
 $featId = 0;
 $propCollection = new MgBatchPropertyCollection();
 $excludedLayers = 0;
 $srsDs = null;
 $inputGeometries = new MgGeometryCollection();
 $bufferFeatures = 0;
 $allCompatible = false;
 for ($li = 0; $li < $selLayers->GetCount(); $li++) {
     $selLayer = $selLayers->GetItem($li);
     $inputLayer = false;
     $selLayerName = $selLayer->GetName();
     for ($il = 0; $il < count($layerNames); $il++) {
         if ($layerNames[$il] == $selLayerName) {
Exemplo n.º 17
0
 protected function OutputMgPropertyCollection($props, $mimeType = MgMimeType::Xml)
 {
     $content = "<?xml version=\"1.0\" encoding=\"utf-8\"?><PropertyCollection />";
     $count = $props->GetCount();
     $agfRw = null;
     $wktRw = null;
     $this->app->response->header("Content-Type", $mimeType);
     if ($count > 0) {
         $content = "<PropertyCollection>";
         for ($i = 0; $i < $count; $i++) {
             $prop = $props->GetItem($i);
             $name = $prop->GetName();
             $type = null;
             $propType = $prop->GetPropertyType();
             switch ($propType) {
                 case MgPropertyType::Boolean:
                     $type = "boolean";
                     break;
                 case MgPropertyType::Byte:
                     $type = "byte";
                     break;
                 case MgPropertyType::DateTime:
                     $type = "datetime";
                     break;
                 case MgPropertyType::Decimal:
                 case MgPropertyType::Double:
                     $type = "double";
                     break;
                 case MgPropertyType::Geometry:
                     $type = "geometry";
                     break;
                 case MgPropertyType::Int16:
                     $type = "int16";
                     break;
                 case MgPropertyType::Int32:
                     $type = "int32";
                     break;
                 case MgPropertyType::Int64:
                     $type = "int64";
                     break;
                 case MgPropertyType::Single:
                     $type = "single";
                     break;
                 case MgPropertyType::String:
                     $type = "string";
                     break;
             }
             if ($prop->IsNull()) {
                 $content .= "<Property><Name>{$name}</Name><Type>{$type}</Type></Property>";
             } else {
                 $value = "";
                 if ($propType === MgPropertyType::DateTime) {
                     $dt = $prop->GetValue();
                     $value = $dt->ToString();
                 } else {
                     if ($propType === MgPropertyType::Geometry) {
                         if ($wktRw == null) {
                             $wktRw = new MgWktReaderWriter();
                         }
                         if ($agfRw == null) {
                             $agfRw = new MgAgfReaderWriter();
                         }
                         try {
                             $agf = $prop->GetValue();
                             $geom = $agfRw->Read($agf);
                             if ($geom != null) {
                                 $value = $wktRw->Write($geom);
                             }
                         } catch (MgException $ex) {
                             $value = "";
                         }
                     } else {
                         $value = $prop->GetValue();
                     }
                 }
                 $content .= "<Property><Name>{$name}</Name><Type>{$type}</Type><Value>{$value}</Value></Property>";
             }
         }
         $content .= "</PropertyCollection>";
     }
     if ($mimeType === MgMimeType::Json) {
         $content = MgUtils::Xml2Json($content);
     }
     $this->app->response->header("Content-Type", $mimeType);
     $this->app->response->setBody($content);
 }
Exemplo n.º 18
0
/**
  keep all the attributes of selected features in an array
*/
function BuildSelectionArray($featureReader, $layerName, $properties, $bComputedProperties, $srsLayer, $bNeedsTransform, $layerObj, $isLayerNameEncoded)
{
    $agf = new MgAgfReaderWriter();
    $srsFactory = new MgCoordinateSystemFactory();
    if ($isLayerNameEncoded) {
        // Add prefix to avoid layer name beginning with number
        // So $isLayerNameEncoded should be true when and only when the properties will be stored in session
        $layerName = GetEncodedLayerName($layerName);
    }
    $properties->{$layerName}->propertynames = array();
    $properties->{$layerName}->propertyvalues = array();
    $properties->{$layerName}->propertytypes = array();
    $properties->{$layerName}->numelements = 0;
    $properties->{$layerName}->values = array();
    $properties->{$layerName}->metadatanames = array();
    array_push($properties->{$layerName}->metadatanames, 'dimension');
    array_push($properties->{$layerName}->metadatanames, 'bbox');
    array_push($properties->{$layerName}->metadatanames, 'center');
    array_push($properties->{$layerName}->metadatanames, 'area');
    array_push($properties->{$layerName}->metadatanames, 'length');
    if (isset($_SESSION)) {
        $mappings = $_SESSION['property_mappings'][$layerObj->GetObjectId()];
        foreach ((array) $mappings as $name => $value) {
            $propType = $featureReader->GetPropertyType($name);
            array_push($properties->{$layerName}->propertynames, $name);
            array_push($properties->{$layerName}->propertyvalues, $value);
            array_push($properties->{$layerName}->propertytypes, $propType);
        }
    }
    $srsTarget = null;
    $srsXform = null;
    while ($featureReader->ReadNext()) {
        $properties->{$layerName}->values[$properties->{$layerName}->numelements] = array();
        $properties->{$layerName}->metadata[$properties->{$layerName}->numelements] = array();
        $dimension = '';
        $bbox = '';
        $center = '';
        $area = '';
        $length = '';
        if ($bComputedProperties) {
            $classDef = $featureReader->GetClassDefinition();
            $geomName = $classDef->GetDefaultGeometryPropertyName();
            if ($geomName != '') {
                $geomByteReader = $featureReader->GetGeometry($geomName);
                /* is this needed? We declare one outside the loop too?*/
                $agf = new MgAgfReaderWriter();
                $geom = $agf->Read($geomByteReader);
                $envelope = $geom->Envelope();
                $ll = $envelope->GetLowerLeftCoordinate();
                $ur = $envelope->GetUpperRightCoordinate();
                $bbox = $ll->GetX() . ',' . $ll->GetY() . ',' . $ur->GetX() . ',' . $ur->GetY();
                $centroid = $geom->GetCentroid()->GetCoordinate();
                $center = $centroid->GetX() . ',' . $centroid->GetY();
                /* 0 = point, 1 = curve, 2 = surface */
                $dimension = $geom->GetDimension();
                if ($geom->GetDimension() > 0) {
                    //conver the geometry to UTM auto so that local measurements
                    //are accruate in meters
                    if ($bNeedsTransform && $srsTarget == null && $srsXform == null) {
                        $wkt = getUtmWkt($centroid->GetX(), $centroid->GetY());
                        $srsTarget = $srsFactory->Create($wkt);
                        $verMajor = subStr(GetSiteVersion(), 0, 1);
                        if ($verMajor == '1') {
                            $srsXform = new MgCoordinateSystemTransform($srsLayer, $srsTarget);
                        } else {
                            $srsXform = $srsFactory->GetTransform($srsLayer, $srsTarget);
                        }
                    }
                    if ($srsXform != null) {
                        try {
                            $ageom = $geom->Transform($srsXform);
                            $geom = $ageom;
                        } catch (MgException $ee) {
                            echo "/*transform exception:";
                            echo "ERROR: " . $ee->GetExceptionMessage() . "\n";
                            echo $ee->GetDetails() . "\n*/";
                        }
                    }
                    if ($geom->GetDimension() > 1) {
                        $area = $geom->GetArea();
                    }
                    if ($geom->GetDimension() > 0) {
                        $length = $geom->GetLength();
                    }
                }
            }
        }
        array_push($properties->{$layerName}->metadata[$properties->{$layerName}->numelements], $dimension);
        array_push($properties->{$layerName}->metadata[$properties->{$layerName}->numelements], $bbox);
        array_push($properties->{$layerName}->metadata[$properties->{$layerName}->numelements], $center);
        array_push($properties->{$layerName}->metadata[$properties->{$layerName}->numelements], $area);
        array_push($properties->{$layerName}->metadata[$properties->{$layerName}->numelements], $length);
        $numproperties = count($properties->{$layerName}->propertynames);
        for ($j = 0; $j < $numproperties; $j++) {
            $propname = $properties->{$layerName}->propertynames[$j];
            $value = GetPropertyValueFromFeatReader($featureReader, $properties->{$layerName}->propertytypes[$j], $propname);
            $value = htmlentities($value, ENT_COMPAT, 'UTF-8');
            $value = addslashes($value);
            $value = preg_replace("/\r?\n/", "<br>", $value);
            array_push($properties->{$layerName}->values[$properties->{$layerName}->numelements], $value);
            //$properties->$layerName->values[$properties->$layerName->numelements][$propname] = $value;
        }
        $properties->{$layerName}->numelements = $properties->{$layerName}->numelements + 1;
    }
    return $properties;
}
Exemplo n.º 19
0
 // the Web Extensions session identifier stored in PHP session state.
 MgInitializeWebTier($webconfigFilePath);
 $userInfo = new MgUserInformation($sessionId);
 $siteConnection = new MgSiteConnection();
 $siteConnection->Open($userInfo);
 $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);
 // 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&nbsp;1';
Exemplo n.º 20
0
function MakeLine($name, $x0, $y0, $x1, $y1)
{
    $propertyCollection = new MgPropertyCollection();
    $nameProperty = new MgStringProperty("NAME", $name);
    $propertyCollection->Add($nameProperty);
    $wktReaderWriter = new MgWktReaderWriter();
    $agfReaderWriter = new MgAgfReaderWriter();
    $geometry = $wktReaderWriter->Read("LINESTRING XY ({$x0} {$y0}, {$x1} {$y1})");
    $geometryByteReader = $agfReaderWriter->Write($geometry);
    $geometryProperty = new MgGeometryProperty("SHPGEOM", $geometryByteReader);
    $propertyCollection->Add($geometryProperty);
    return $propertyCollection;
}
Exemplo n.º 21
0
 public static function GetFeatureClassMBR($app, $featureSrvc, $featuresId, $schemaName, $className, $geomName = null, $transformToCsCode = null)
 {
     $extentGeometryAgg = null;
     $extentGeometrySc = null;
     $extentByteReader = null;
     $mbr = new stdClass();
     $csFactory = new MgCoordinateSystemFactory();
     $clsDef = $featureSrvc->GetClassDefinition($featuresId, $schemaName, $className);
     $props = $clsDef->GetProperties();
     if ($geomName == null) {
         $geomName = $clsDef->GetDefaultGeometryPropertyName();
     }
     $geomProp = $props->GetItem($geomName);
     if ($geomProp->GetPropertyType() != MgFeaturePropertyType::GeometricProperty) {
         throw new Exception($app->localizer->getText("E_NOT_GEOMETRY_PROPERTY", $geomName));
     }
     $spatialContext = $geomProp->GetSpatialContextAssociation();
     // Finds the coordinate system
     $agfReaderWriter = new MgAgfReaderWriter();
     $spatialcontextReader = $featureSrvc->GetSpatialContexts($featuresId, false);
     while ($spatialcontextReader->ReadNext()) {
         if ($spatialcontextReader->GetName() == $spatialContext) {
             $mbr->coordinateSystem = $spatialcontextReader->GetCoordinateSystemWkt();
             $mbr->csCode = $csFactory->ConvertWktToCoordinateSystemCode($mbr->coordinateSystem);
             $mbr->epsg = $csFactory->ConvertWktToEpsgCode($mbr->coordinateSystem);
             // Finds the extent
             $extentByteReader = $spatialcontextReader->GetExtent();
             break;
         }
     }
     $spatialcontextReader->Close();
     if ($extentByteReader != null) {
         // Get the extent geometry from the spatial context
         $extentGeometrySc = $agfReaderWriter->Read($extentByteReader);
     }
     // Try to get the extents using the selectaggregate as sometimes the spatial context
     // information is not set
     $aggregateOptions = new MgFeatureAggregateOptions();
     $featureProp = 'SPATIALEXTENTS("' . $geomName . '")';
     $aggregateOptions->AddComputedProperty('EXTENTS', $featureProp);
     try {
         $dataReader = $featureSrvc->SelectAggregate($featuresId, $className, $aggregateOptions);
         if ($dataReader->ReadNext()) {
             // Get the extents information
             $byteReader = $dataReader->GetGeometry('EXTENTS');
             $extentGeometryAgg = $agfReaderWriter->Read($byteReader);
         }
         $dataReader->Close();
     } catch (MgException $e) {
         if ($extentGeometryAgg == null) {
             //We do have one last hope. EXTENT() is an internal MapGuide custom function that's universally supported
             //as it operates against an underlying select query result. This raw-spins the reader server-side so there
             //is no server -> web tier transmission overhead involved.
             try {
                 $aggregateOptions = new MgFeatureAggregateOptions();
                 $aggregateOptions->AddComputedProperty("COMP_EXTENT", "EXTENT(" . $geomName . ")");
                 $dataReader = $featureSrvc->SelectAggregate($featuresId, $className, $aggregateOptions);
                 if ($dataReader->ReadNext()) {
                     // Get the extents information
                     $byteReader = $dataReader->GetGeometry('COMP_EXTENT');
                     $extentGeometryAgg = $agfReaderWriter->Read($byteReader);
                 }
                 $dataReader->Close();
             } catch (MgException $e2) {
             }
         }
     }
     $mbr->extentGeometry = null;
     // Prefer SpatialExtents() of EXTENT() result over spatial context extent
     if ($extentGeometryAgg != null) {
         $mbr->extentGeometry = $extentGeometryAgg;
     }
     if ($mbr->extentGeometry == null) {
         //Stil null? Now try spatial context
         if ($extentGeometrySc != null) {
             $mbr->extentGeometry = $extentGeometrySc;
         }
     }
     if ($transformToCsCode != null) {
         $sourceCs = $csFactory->CreateFromCode($mbr->csCode);
         $targetCs = $csFactory->CreateFromCode($transformToCsCode);
         $xform = $csFactory->GetTransform($sourceCs, $targetCs);
         $mbr->extentGeometry = $mbr->extentGeometry->Transform($xform);
         $mbr->csCode = $targetCs->GetCsCode();
         $mbr->epsg = $targetCs->GetEpsgCode();
     }
     return $mbr;
 }
Exemplo n.º 22
0
function GetFeatureClassMBR($featuresId, $className, $geomProp, $featureSrvc)
{
    $extentGeometryAgg = null;
    $extentGeometrySc = null;
    $extentByteReader = null;
    $mbr = new MBR();
    $geomName = $geomProp->GetName();
    $spatialContext = $geomProp->GetSpatialContextAssociation();
    // Finds the coordinate system
    $agfReaderWriter = new MgAgfReaderWriter();
    $spatialcontextReader = $featureSrvc->GetSpatialContexts($featuresId, false);
    while ($spatialcontextReader->ReadNext()) {
        if ($spatialcontextReader->GetName() == $spatialContext) {
            $mbr->coordinateSystem = $spatialcontextReader->GetCoordinateSystemWkt();
            // Finds the extent
            $extentByteReader = $spatialcontextReader->GetExtent();
            break;
        }
    }
    $spatialcontextReader->Close();
    if ($extentByteReader != null) {
        // Get the extent geometry from the spatial context
        $extentGeometrySc = $agfReaderWriter->Read($extentByteReader);
    }
    // Try to get the extents using the selectaggregate as sometimes the spatial context
    // information is not set
    $aggregateOptions = new MgFeatureAggregateOptions();
    $featureProp = 'SPATIALEXTENTS("' . $geomName . '")';
    $aggregateOptions->AddComputedProperty('EXTENTS', $featureProp);
    try {
        $dataReader = $featureSrvc->SelectAggregate($featuresId, $className, $aggregateOptions);
        if ($dataReader->ReadNext()) {
            // Get the extents information
            $byteReader = $dataReader->GetGeometry('EXTENTS');
            $extentGeometryAgg = $agfReaderWriter->Read($byteReader);
        }
        $dataReader->Close();
    } catch (MgException $e) {
        if ($extentGeometryAgg == null) {
            //We do have one last hope. EXTENT() is an internal MapGuide custom function that's universally supported
            //as it operates against an underlying select query result. This raw-spins the reader server-side so there
            //is no server -> web tier transmission overhead involved.
            try {
                $aggregateOptions = new MgFeatureAggregateOptions();
                $aggregateOptions->AddComputedProperty("COMP_EXTENT", "EXTENT(" . $geomName . ")");
                $dataReader = $featureSrvc->SelectAggregate($featuresId, $className, $aggregateOptions);
                if ($dataReader->ReadNext()) {
                    // Get the extents information
                    $byteReader = $dataReader->GetGeometry('COMP_EXTENT');
                    $extentGeometryAgg = $agfReaderWriter->Read($byteReader);
                }
                $dataReader->Close();
            } catch (MgException $e2) {
            }
        }
    }
    $mbr->extentGeometry = null;
    // Prefer SpatialExtents() of EXTENT() result over spatial context extent
    if ($extentGeometryAgg != null) {
        $mbr->extentGeometry = $extentGeometryAgg;
    }
    if ($mbr->extentGeometry == null) {
        //Stil null? Now try spatial context
        if ($extentGeometrySc != null) {
            $mbr->extentGeometry = $extentGeometrySc;
        }
    }
    return $mbr;
}
function MakePoint($name, $x, $y)
{
    $propertyCollection = new MgPropertyCollection();
    $nameProperty = new MgStringProperty("NAME", $name);
    $propertyCollection->Add($nameProperty);
    $wktReaderWriter = new MgWktReaderWriter();
    $agfReaderWriter = new MgAgfReaderWriter();
    $geometry = $wktReaderWriter->Read("POINT XY ({$x} {$y})");
    $geometryByteReader = $agfReaderWriter->Write($geometry);
    $geometryProperty = new MgGeometryProperty("GEOM", $geometryByteReader);
    $propertyCollection->Add($geometryProperty);
    return $propertyCollection;
}