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
             } else {
                 $srsTarget = null;
                 $srsXform = null;
                 $bNeedsTransform = $srsLayer->GetUnitScale() != 1.0;
             }
             $properties = BuildSelectionArray($featureReader, $layerName, $properties, $bComputedProperties, $srsLayer, $bNeedsTransform, $oLayer, true);
             $featureReader->Close();
         }
     }
 }
 $selection->Save($resourceService, $mapName);
 //print_r($properties);
 //echo "/* SelectionXML:".$selection->ToXML()."*/";
 header('Content-type: application/json');
 header('X-JSON: true');
 $layers = $selection->GetLayers();
 $result = NULL;
 $result->hasSelection = false;
 if ($layers && $layers->GetCount() >= 0) {
     $result->hasSelection = true;
     $oExtents = $selection->GetExtents($featureService);
     if ($oExtents) {
         $oMin = $oExtents->GetLowerLeftCoordinate();
         $oMax = $oExtents->GetUpperRightCoordinate();
         $result->extents = NULL;
         $result->extents->minx = $oMin->GetX();
         $result->extents->miny = $oMin->GetY();
         $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;
Example #3
0
     $sdfParams = new MgCreateSdfParams("LatLong", $srsDefMap, $schema);
     $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++) {
Example #4
0
 $fsvc->UpdateFeatures($id, $cmdColl, false);
 $mapId = new MgResourceIdentifier("Library://TrevorWekel/NewSdf.MapDefinition");
 $map = new MgMap();
 $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";
Example #5
0
 public function GetSelectedFeatures($sessionId, $mapName, $layerName, $format)
 {
     $fmt = $this->ValidateRepresentation($format, array("xml", "geojson", "html"));
     $propList = $this->GetRequestParameter("properties", "");
     $pageSize = $this->GetRequestParameter("pagesize", -1);
     $pageNo = $this->GetRequestParameter("page", -1);
     $orientation = $this->GetRequestParameter("orientation", "h");
     //Internal debugging flag
     $chunk = $this->GetBooleanRequestParameter("chunk", true);
     try {
         $this->EnsureAuthenticationForSite($sessionId);
         $siteConn = new MgSiteConnection();
         $siteConn->Open($this->userInfo);
         $resSvc = $siteConn->CreateService(MgServiceType::ResourceService);
         $featSvc = $siteConn->CreateService(MgServiceType::FeatureService);
         $map = new MgMap($siteConn);
         $map->Open($mapName);
         $selection = new MgSelection($map);
         $selection->Open($resSvc, $mapName);
         $layers = $selection->GetLayers();
         if ($layers != null) {
             $lidx = -1;
             $layerCount = $layers->GetCount();
             for ($i = 0; $i < $layerCount; $i++) {
                 $currentlayer = $layers->GetItem($i);
                 if ($currentlayer->GetName() == $layerName) {
                     $lidx = $i;
                     break;
                 }
             }
             if ($lidx < 0) {
                 $this->NotFound($this->app->localizer->getText("E_LAYER_NOT_IN_SELECTION", $layerName), $this->GetMimeTypeForFormat($fmt));
             } else {
                 $layer = $layers->GetItem($lidx);
                 $bMapped = $this->GetBooleanRequestParameter("mappedonly", "0") == "1";
                 $transformto = $this->GetRequestParameter("transformto", "");
                 $transform = null;
                 if ($transformto !== "") {
                     $resId = new MgResourceIdentifier($layer->GetFeatureSourceId());
                     $tokens = explode(":", $layer->GetFeatureClassName());
                     $transform = MgUtils::GetTransform($featSvc, $resId, $tokens[0], $tokens[1], $transformto);
                 }
                 $owriter = null;
                 if ($chunk === "0") {
                     $owriter = new MgSlimChunkWriter($this->app);
                 } else {
                     $owriter = new MgHttpChunkWriter();
                 }
                 //NOTE: This does not do a query to ascertain a total, this is already a pre-computed property of the selection set.
                 $total = $selection->GetSelectedFeaturesCount($layer, $layer->GetFeatureClassName());
                 if (strlen($propList) > 0) {
                     $tokens = explode(",", $propList);
                     $propNames = new MgStringCollection();
                     foreach ($tokens as $propName) {
                         $propNames->Add($propName);
                     }
                     $reader = $selection->GetSelectedFeatures($layer, $layer->GetFeatureClassName(), $propNames);
                 } else {
                     $reader = $selection->GetSelectedFeatures($layer, $layer->GetFeatureClassName(), $bMapped);
                 }
                 if ($pageSize > 0) {
                     $pageReader = new MgPaginatedFeatureReader($reader, $pageSize, $pageNo, $total);
                     $result = new MgReaderChunkedResult($featSvc, $pageReader, -1, $owriter, $this->app->localizer);
                 } else {
                     $result = new MgReaderChunkedResult($featSvc, $reader, -1, $owriter, $this->app->localizer);
                 }
                 $result->CheckAndSetDownloadHeaders($this->app, $format);
                 if ($transform != null) {
                     $result->SetTransform($transform);
                 }
                 if ($fmt === "html") {
                     $result->SetAttributeDisplayOrientation($orientation);
                     $result->SetHtmlParams($this->app);
                 }
                 $result->Output($format);
             }
         } else {
             $owriter = new MgHttpChunkWriter();
             $reader = new MgNullFeatureReader();
             $result = new MgReaderChunkedResult($featSvc, $reader, -1, $owriter, $this->app->localizer);
             if ($fmt === "html") {
                 $result->SetAttributeDisplayOrientation($orientation);
                 $result->SetHtmlParams($this->app);
             }
             $result->Output($format);
         }
     } catch (MgException $ex) {
         $this->OnException($ex, $this->GetMimeTypeForFormat($format));
     }
 }