Ejemplo n.º 1
0
}
$format = isset($_REQUEST['format']) ? $_REQUEST['format'] : 'PNG';
$layout = isset($_REQUEST['layout']) ? $_REQUEST['layout'] : null;
$scale = isset($_REQUEST['scale']) ? $_REQUEST['scale'] : null;
$imgWidth = isset($_REQUEST['width']) ? $_REQUEST['width'] : null;
$imgHeight = isset($_REQUEST['height']) ? $_REQUEST['height'] : null;
$pageHeight = isset($_REQUEST['pageheight']) ? $_REQUEST['pageheight'] : 11;
$pageWidth = isset($_REQUEST['pagewidth']) ? $_REQUEST['pagewidth'] : 8.5;
$aMargins = isset($_REQUEST['margins']) ? explode(',', $_REQUEST['margins']) : array(0, 0, 0, 0);
try {
    $mappingService = $siteConnection->CreateService(MgServiceType::MappingService);
    $renderingService = $siteConnection->CreateService(MgServiceType::RenderingService);
    $map = new MgMap();
    $map->Open($resourceService, $mapName);
    $selection = new MgSelection($map);
    $selection->Open($resourceService, $mapName);
    //get current center as a coordinate
    $center = $map->GetViewCenter()->GetCoordinate();
    //plot with the passed scale, if provided
    $scale = isset($_REQUEST['scale']) ? $_REQUEST['scale'] : $map->GetViewScale();
    if ($format == 'DWF') {
        $oLayout = null;
        if ($layout) {
            $layoutId = new MgResourceIdentifier($layout);
            $layoutId->Validate();
            $oLayout = new MgLayout($layoutId, 'Map', 'meters');
        }
        $oPlotSpec = new MgPlotSpecification($pageWidth, $pageHeight, MgPageUnitsType::Inches, $aMargins[0], $aMargins[1], $aMargins[2], $aMargins[3]);
        $dwfVersion = new MgDwfVersion('6.01', '1.2');
        $oImg = $mappingService->GeneratePlot($map, $center, $scale, $oPlotSpec, $oLayout, $dwfVersion);
    } else {
Ejemplo n.º 2
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);
 $sel->Open($resourceSrvc, $mapName);
 $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();
Ejemplo n.º 3
0
function MultiGeometryFromSelection($featureSrvc, $resourceSrvc, $map, $mapName)
{
    $sel = new MgSelection($map);
    $sel->Open($resourceSrvc, $mapName);
    $selLayers = $sel->GetLayers();
    if ($selLayers == null) {
        return null;
    }
    $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();
            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;
                $trans = GetLayerToMapCSTrans($classDef, $geomPropName, $featureSrvc, $featureSource, $map);
                $geomColl->Add($geom->Transform($trans));
            }
            $features->Close();
        }
    }
    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);
}
Ejemplo n.º 4
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));
     }
 }