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); } }
$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) { $inputLayer = true; break; } } if ($inputLayer == false) { continue; }
} $results = $featureService->UpdateFeatures($bufferFeatureResId, $commands, false); $bufferLayer->SetVisible(true); $bufferLayer->ForceRefresh(); $bufferLayer->SetDisplayInLegend(true); $map->Save($resourceService); */ // New way, post MapGuide 2.0 // Get the selected features from the MgSelection object $featureReader = $selection->GetSelectedFeatures($layer, $layer->GetFeatureClassName(), false); // Process each item in the MgFeatureReader. Get the // geometries from all the selected features and // merge them into a single geometry. $inputGeometries = new MgGeometryCollection(); while ($featureReader->ReadNext()) { $featureGeometryData = $featureReader->GetGeometry('SHPGEOM'); $featureGeometry = $agfReaderWriter->Read($featureGeometryData); $inputGeometries->Add($featureGeometry); } $geometryFactory = new MgGeometryFactory(); $mergedGeometries = $geometryFactory->CreateMultiGeometry($inputGeometries); // Add buffer features to the temporary feature source. // Create multiple concentric buffers to show area. // If the stylization for the layer draws the features // partially transparent, the concentric rings will be // progressively darker towards the center. // The stylization is set in the layer template file, which // is used in function CreateBufferLayer(). $commands = new MgFeatureCommandCollection();
BuildLayerContent($resourceService, $layerId, $featureSourceName, $schemaName, $layerName, $fillColor, $borderColor); $layer = new MGLayer($layerId, $resourceService); $layer->SetName($layerName); $layer->SetLegendLabel($layerName); $layer->SetDisplayInLegend(true); $layer->SetSelectable(true); $layers->Insert(0, $layer); } //loop through the selection of the input layer. If no selection, select all features $queryOptions = new MgFeatureQueryOptions(); $selection = new MgSelection($map); $selection->Open($resourceService, $mapName); $selLayers = $selection->GetLayers(); /* if we are merging, put all the geometries into a single geometry collection */ $inputGeometries = new MgGeometryCollection(); /* store the insert commands for creating buffers */ $oCommandsColl = new MgFeatureCommandCollection(); $nCount = $selLayers->GetCount(); for ($i = 0; $i < $nCount; $i++) { $selLayer = $selLayers->GetItem($i); $featureClassName = $selLayer->GetFeatureClassName(); $filter = $selection->GenerateFilter($selLayer, $featureClassName); if ($filter == '') { continue; } $queryOptions->SetFilter($filter); $featureSource = new MgResourceIdentifier($selLayer->GetFeatureSourceId()); $featureReader = $featureService->SelectFeatures($featureSource, $featureClassName, $queryOptions); $classDef = $featureReader->GetClassDefinition(); $geomPropName = $classDef->GetDefaultGeometryPropertyName();