Esempio n. 1
0
 $queryOptions = new MgFeatureQueryOptions();
 $layers = $map->GetLayers();
 foreach ($aLayers as $szLayer => $aLayer) {
     $oLayer = $layers->GetItem($szLayer);
     foreach ($aLayer as $szClass => $aFilter) {
         /* get the feature source from the layer */
         $featureResId = new MgResourceIdentifier($oLayer->GetFeatureSourceId());
         $featureGeometryName = $oLayer->GetFeatureGeometryName();
         $szFilter = implode(' OR ', $aFilter);
         $queryOptions->setFilter($szFilter);
         /* the class that is used for this layer will be used to select
            features */
         $class = $oLayer->GetFeatureClassName();
         /* select the features */
         $featureReader = $featureService->SelectFeatures($featureResId, $class, $queryOptions);
         $selection->AddFeatures($oLayer, $featureReader, $maxFeatures);
         $layerName = $oLayer->GetName();
         if (!in_array($layerName, $properties->layers)) {
             array_push($properties->layers, $layerName);
         }
         $featureReader->Close();
         $featureReader = $featureService->SelectFeatures($featureResId, $class, $queryOptions);
         $spatialContext = $featureService->GetSpatialContexts($featureResId, true);
         $srsLayerWkt = false;
         if ($spatialContext != null && $spatialContext->ReadNext() != null) {
             $srsLayerWkt = $spatialContext->GetCoordinateSystemWkt();
             /* skip this layer if the srs is empty */
         }
         if ($srsLayerWkt == null) {
             $srsLayerWkt = $srsDefMap;
         }
Esempio n. 2
0
    $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 1';
} catch (MgException $e) {
    echo $e->GetExceptionMessage();
    echo $e->GetDetails();
}
?>

  </body>

  <script language="javascript">

    <!-- Emit this function and assocate it with the onLoad event for the -->
    <!-- page so that it gets executed when this page loads in the        -->
    <!-- browser. The function calls the SetSelectionXML method on the    -->
Esempio n. 3
0
    // Test basic methods
    $layerColl = $sel2->GetLayers();
    $newLayer = $layerColl->GetItem(0);
    echo "First layer selected is " . $newLayer->GetName() . "\n";
    echo "BadKey Filter: " . $sel2->GenerateFilter($slayer, "BadKey") . "\n";
    $filter = $sel2->GenerateFilter($slayer, "IntKey");
    echo "\nString Filter: " . $filter . "\n\n";
    $query = new MgFeatureQueryOptions();
    $query->AddFeatureProperty("KEY");
    $query->AddFeatureProperty("NAME");
    $query->SetFilter($filter);
    echo "Selected features\n";
    $reader = $fsvc->SelectFeatures($id, "IntKey", $query);
    while ($reader->ReadNext() == true) {
        echo $reader->GetString("NAME") . "\n";
    }
    echo "MgSelection from Reader\n";
    $reader = $fsvc->SelectFeatures($id, "IntKey", $query);
    $selection = new MgSelection($map);
    $layer1 = $map->GetLayers()->GetItem(0);
    $selection->AddFeatures($layer1, $reader, 0);
    echo $selection->ToXml();
    $envelope = $selection->GetExtents($fsvc);
    $ll = $envelope->GetLowerLeftCoordinate();
    $ur = $envelope->GetUpperRightCoordinate();
    echo "(" . $ll->GetX() . "," . $ll->GetY() . ") - (" . $ur->GetX() . "," . $ur->GetY() . ")\n";
} catch (MgException $exc) {
    echo $exc->GetExceptionMessage() . "\n";
    echo $exc->GetDetails() . "\n";
}
echo "Done.\n";
Esempio n. 4
0
 private function TranslateToSelectionXml($siteConn, $mapName, $featFilter, $bAppend)
 {
     $resSvc = $siteConn->CreateService(MgServiceType::ResourceService);
     $map = new MgMap($siteConn);
     $map->Open($mapName);
     $sel = new MgSelection($map);
     $layers = $map->GetLayers();
     //If appending, load the current selection first
     if ($bAppend) {
         $sel->Open($resSvc, $mapName);
     }
     $doc = new DOMDocument();
     $doc->loadXML($featFilter);
     /*
             Document structure
             
             /SelectionUpdate
        /Layer
            /Name
            /Feature [0...n]
                /ID
                    /Name
                    /Value
            /SelectionFilter [0...n]
     */
     $root = $doc->documentElement;
     if ($root->tagName != "SelectionUpdate") {
         $this->BadRequest($this->app->localizer->getText("E_INVALID_DOCUMENT"), MgMimeType::Xml);
     }
     $layerNodes = $root->childNodes;
     for ($i = 0; $i < $layerNodes->length; $i++) {
         $layerNode = $layerNodes->item($i);
         if ($layerNode->tagName == "Layer") {
             //$this->app->log->debug("Found //SelectionUpdate/Layer");
             $featureNodes = $layerNode->childNodes;
             for ($j = 0; $j < $featureNodes->length; $j++) {
                 $featureNode = $featureNodes->item($j);
                 if ($featureNode->tagName == "Name") {
                     //$this->app->log->debug("Found //SelectionUpdate/Layer/Name");
                     $layerName = $featureNode->nodeValue;
                     $lidx = $layers->IndexOf($layerName);
                     if ($lidx < 0) {
                         $this->BadRequest($this->app->localizer->getText("E_LAYER_NOT_FOUND_IN_MAP", $layerName), MgMimeType::Xml);
                     }
                     $layer = $layers->GetItem($lidx);
                     $clsDef = $layer->GetClassDefinition();
                     $clsIdProps = $clsDef->GetIdentityProperties();
                 } else {
                     if ($featureNode->tagName == "SelectionFilter") {
                         $query = new MgFeatureQueryOptions();
                         $query->SetFilter($featureNode->nodeValue);
                         $fr = $layer->SelectFeatures($query);
                         $sel->AddFeatures($layer, $fr, 0);
                     } else {
                         if ($featureNode->tagName == "Feature") {
                             //$this->app->log->debug("Found //SelectionUpdate/Layer/Feature");
                             $idNodes = $featureNode->childNodes;
                             if ($idNodes->length == 1) {
                                 $idNode = $idNodes->item(0);
                                 if ($idNode->tagName == "ID") {
                                     //$this->app->log->debug("Found //SelectionUpdate/Layer/Feature/ID");
                                     $nameNode = null;
                                     $valueNode = null;
                                     for ($nv = 0; $nv < $idNode->childNodes->length; $nv++) {
                                         $children = $idNode->childNodes;
                                         $child = $children->item($nv);
                                         if ($child->tagName == "Name") {
                                             //$this->app->log->debug("Found //SelectionUpdate/Layer/Feature/ID/Name");
                                             $nameNode = $child;
                                         } else {
                                             if ($child->tagName == "Value") {
                                                 //$this->app->log->debug("Found //SelectionUpdate/Layer/Feature/ID/Value");
                                                 $valueNode = $child;
                                             }
                                         }
                                     }
                                     //Name/Value nodes must be specified
                                     if ($nameNode == null || $valueNode == null) {
                                         $this->BadRequest($this->app->localizer->getText("E_INVALID_DOCUMENT"), MgMimeType::Xml);
                                     }
                                     //Property must exist
                                     $pidx = $clsIdProps->IndexOf($nameNode->nodeValue);
                                     if ($pidx < 0) {
                                         $this->BadRequest($this->app->localizer->getText("E_PROPERTY_NOT_FOUND_IN_CLASS", $nameNode->nodeValue, $clsDef->GetName()), MgMimeType::Xml);
                                     }
                                     $propDef = $clsIdProps->GetItem($pidx);
                                     $value = $valueNode->nodeValue;
                                     $propType = $propDef->GetDataType();
                                     //$this->app->log->debug("Value is: $value");
                                     //$this->app->log->debug("Property type: $propType");
                                     switch ($propType) {
                                         case MgPropertyType::Int16:
                                             //$this->app->log->debug("=== ADD INT16: $value ===");
                                             $sel->AddFeatureIdInt16($layer, $layer->GetFeatureClassName(), intval($value));
                                             break;
                                         case MgPropertyType::Int32:
                                             //$this->app->log->debug("=== ADD INT32: $value ===");
                                             $sel->AddFeatureIdInt32($layer, $layer->GetFeatureClassName(), intval($value));
                                             break;
                                         case MgPropertyType::Int64:
                                             //$this->app->log->debug("=== ADD INT64: $value ===");
                                             $sel->AddFeatureIdInt64($layer, $layer->GetFeatureClassName(), intval($value));
                                             break;
                                         case MgPropertyType::String:
                                             //$this->app->log->debug("=== ADD STRING: $value ===");
                                             $sel->AddFeatureIdString($layer, $layer->GetFeatureClassName(), $value);
                                             break;
                                         case MgPropertyType::Single:
                                         case MgPropertyType::Double:
                                             //$this->app->log->debug("=== ADD DOUBLE: $value ===");
                                             $sel->AddFeatureIdInt64($layer, $layer->GetFeatureClassName(), floatval($value));
                                             break;
                                             //case MgPropertyType::DateTime:
                                             //    break;
                                     }
                                 }
                             } else {
                                 if ($idNodes->length > 1) {
                                     throw new Exception($this->app->localizer->getText("E_MULTIPLE_IDENTITY_PROPS_NOT_SUPPORTED"));
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $sel->ToXml();
 }