Example #1
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);
    }
}
Example #2
0
            $result->extents->maxx = $oMax->GetX();
            $result->extents->maxy = $oMax->GetY();
            /*keep the full extents of the selection when saving the selection in the session*/
            $properties->extents = NULL;
            $properties->extents->minx = $oMin->GetX();
            $properties->extents->miny = $oMin->GetY();
            $properties->extents->maxx = $oMax->GetX();
            $properties->extents->maxy = $oMax->GetY();
        }
        $result->layers = array();
        for ($i = 0; $i < $layers->GetCount(); $i++) {
            $layer = $layers->GetItem($i);
            $layerName = $layer->GetName();
            array_push($result->layers, $layerName);
            $layerClassName = $layer->GetFeatureClassName();
            $filter = $selection->GenerateFilter($layer, $layerClassName);
            $a = explode('OR', $filter);
            $result->{$layerName}->featureCount = count($a);
        }
        /*save selection in the session*/
        $_SESSION['selection_array'] = $properties;
    }
    echo var2json($result);
} catch (MgException $e) {
    echo "ERROR: " . $e->GetExceptionMessage() . "\n";
    echo $e->GetDetails() . "\n";
    echo $e->GetStackTrace() . "\n";
}
function selectionToArray($selection, $aLayers, $bToggle = true)
{
    $layers = $selection->GetLayers();
Example #3
0
 $map->Create($rsvc, $mapId, "NewMap");
 echo "Building Selection from Add()\n";
 $sel = new MgSelection($map);
 $slayer = $map->GetLayers()->GetItem(0);
 $sel->AddFeatureIdInt32($slayer, "IntKey", 1);
 $sel->AddFeatureIdInt32($slayer, "IntKey", 10);
 $sel->AddFeatureIdInt32($slayer, "IntKey", 20);
 echo "XML FeatureSet is\n" . $sel->ToXml() . "\n";
 echo "\nString Filter: " . $sel->GenerateFilter($slayer, "StringKey") . "\n\n";
 echo "Building Selection from XML\n";
 $sel2 = new MgSelection($map, $sel->ToXml());
 // 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);
Example #4
0
     //This is normally pre-stashed by LoadMap.php, but if the client is using the new
     //CREATERUNTIMEMAP shortcut, this information does not exist yet, so fetch and stash
     $mappings = GetLayerPropertyMappings($resourceService, $oLayer);
     $_SESSION['property_mappings'][$oLayer->GetObjectId()] = $mappings;
 }
 if (count($mappings) > 0) {
     foreach ($mappings as $name => $value) {
         if ($geomName != $name) {
             $queryOptions->AddFeatureProperty($name);
             //echo "$name $value <br>\n";
         }
     }
 }
 //Add geometry property in all cases.
 $queryOptions->AddFeatureProperty($geomName);
 $filter = $selection->GenerateFilter($oLayer, $class);
 $queryOptions->SetFilter($filter);
 $featureReader = $featureService->SelectFeatures($featureResId, $class, $queryOptions);
 //$featureReader = $selection->GetSelectedFeatures($oLayer, $class, true );//this doesn't seem to work but would replace much of the above code
 $layerName = $oLayer->GetName();
 array_push($properties->layers, $layerName);
 // TODO: Check if computed properties are needed?
 $bComputedProperties = false;
 $bNeedsTransform = false;
 $srsLayer = NULL;
 if ($bComputedProperties) {
     $spatialContext = $featureService->GetSpatialContexts($featureResId, true);
     $srsLayerWkt = false;
     if ($spatialContext != null && $spatialContext->ReadNext() != null) {
         $srsLayerWkt = $spatialContext->GetCoordinateSystemWkt();
         /* skip this layer if the srs is empty */
Example #5
0
 // Use the following code for AJAX Viewers only.
 // This does not require passing selection data via HTTP POST.
 //
 // $selection = new MgSelection($map);
 // $selection->Open($resourceService, $mapName);
 // $layers = $selection->GetLayers();
 // ---------------------------------------------------------
 if ($layers) {
     $queryOptions = new MgFeatureQueryOptions();
     for ($i = 0; $i < $layers->GetCount(); $i++) {
         // Only check selected features in the Parcels layer.
         $layer = $layers->GetItem($i);
         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);
             // Process each item in the MgFeatureReader, displaying the owner name
             while ($featureReader->ReadNext()) {
                 $val = $featureReader->GetString('NAME') . '<br />&nbsp;&nbsp;' . $featureReader->GetString('RPROPAD');
                 echo $val . '<br />';
             }
         }
     }
 } else {
Example #6
0
 //
 $dist = $srsDs->ConvertMetersToCoordinateSystemUnits($distance);
 // calculate great circle unless data source srs is arbitrary
 if (!$arbitraryDsSrs) {
     $measure = $srsDs->GetMeasure();
 } else {
     $measure = null;
 }
 // create a SRS transformer if necessary.
 if ($srsDefDs != $srsDefMap) {
     $srsXform = $srsFactory->GetTransform($srsDs, $srsMap);
 } else {
     $srsXform = null;
 }
 $featureClassName = $selLayer->GetFeatureClassName();
 $filter = $sel->GenerateFilter($selLayer, $featureClassName);
 if ($filter == "") {
     continue;
 }
 $query = new MgFeatureQueryOptions();
 $query->SetFilter($filter);
 $featureSource = new MgResourceIdentifier($selLayer->GetFeatureSourceId());
 $features = $featureSrvc->SelectFeatures($featureSource, $featureClassName, $query);
 if ($features->ReadNext()) {
     $classDef = $features->GetClassDefinition();
     $geomPropName = $classDef->GetDefaultGeometryPropertyName();
     do {
         if (strlen($geomPropName) == 0) {
             $geomPropName = $selLayer->GetFeatureGeometryName();
         }
         $geomReader = $features->GetGeometry($geomPropName);