Exemple #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);
    }
}
Exemple #2
0
                 $inputGeometries->Add($geom);
             }
         } while ($features->ReadNext());
         $features->Close();
     }
 }
 if ($merge) {
     if ($inputGeometries->GetCount() > 0) {
         $dist = $srsMap->ConvertMetersToCoordinateSystemUnits($distance);
         if (!$arbitraryMapSrs) {
             $measure = $srsMap->GetMeasure();
         } else {
             $measure = null;
         }
         $geomFactory = new MgGeometryFactory();
         $geomBuffer = $geomFactory->CreateMultiGeometry($inputGeometries)->Buffer($dist, $measure);
         if ($geomBuffer != null) {
             AddFeatureToCollection($propCollection, $agfRW, $featId, $geomBuffer);
             $bufferFeatures = 1;
         }
     }
 }
 if ($propCollection->GetCount() > 0) {
     $commands->Add(new MgInsertFeatures($featureName, $propCollection));
     //Insert the features in the temporary data source
     //
     $res = $featureSrvc->UpdateFeatures($dataSourceId, $commands, false);
 }
 // Save the new map state
 //
 $layer->ForceRefresh();
Exemple #3
0
 $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();
 for ($bufferRing = 0; $bufferRing < $bufferRingCount; $bufferRing++) {
     $bufferDist = $srs->ConvertMetersToCoordinateSystemUnits($bufferRingSize * ($bufferRing + 1));
     $bufferGeometry = $mergedGeometries->Buffer($bufferDist, $srsMeasure);
     $properties = new MgPropertyCollection();
     $properties->Add(new MgGeometryProperty('BufferGeometry', $agfReaderWriter->Write($bufferGeometry)));
     $commands->Add(new MgInsertFeatures('BufferClass', $properties));
 }
Exemple #4
0
    }
    if ($merge) {
        if ($inputGeometries->GetCount() > 0) {
            $dist = $srsMap->ConvertMetersToCoordinateSystemUnits($distance);
            if (!$arbitraryMapSrs) {
                $verMajor = subStr(GetSiteVersion(), 0, 1);
                if ($verMajor == '1') {
                    $measure = new MgCoordinateSystemMeasure($srsMap);
                } else {
                    $measure = $srsMap->GetMeasure();
                }
            } else {
                $measure = null;
            }
            $geomFactory = new MgGeometryFactory();
            $oGeom = $geomFactory->CreateMultiGeometry($inputGeometries);
            $oNewGeom = $oGeom->Buffer($dist, $measure);
            $geomProp = new MgGeometryProperty("GEOM", $agfRW->Write($oNewGeom));
            $oPropertyColl = new MgPropertyCollection();
            $oPropertyColl->Add($geomProp);
            $oCommandsColl->Add(new MgInsertFeatures($schemaName . ':' . $layerName, $oPropertyColl));
        }
    }
    $result = $featureService->UpdateFeatures($featureSourceId, $oCommandsColl, false);
    $layer->ForceRefresh();
    $map->Save($resourceService);
    echo "<Buffer>";
    echo "<Layer>" . $layerId->ToString();
    echo "</Layer>";
    echo "</Buffer>";
} catch (MgException $e) {