Exemplo n.º 1
0
 function ShowSpatialFilter()
 {
     $result = true;
     $sdfResId = new MgResourceIdentifier('Session:' . $this->args['SESSION'] . '//Filter.FeatureSource');
     $resourceService = $this->site->CreateService(MgServiceType::ResourceService);
     $featureService = $this->site->CreateService(MgServiceType::FeatureService);
     $updateCommands = new MgFeatureCommandCollection();
     $map = new MgMap();
     $map->Open($resourceService, $this->args['MAPNAME']);
     $layer = null;
     $layers = $map->GetLayers();
     if ($layers->Contains('_QuerySpatialFilter')) {
         $layer = $layers->GetItem('_QuerySpatialFilter');
         $updateCommands->Add(new MgDeleteFeatures('Filter', "ID like '%'"));
     } else {
         // Create the Feature Source (SDF)
         $sdfSchema = $this->CreateFilterSchema();
         $sdfParams = new MgCreateSdfParams('MAPCS', $map->GetMapSRS(), $sdfSchema);
         $featureService->CreateFeatureSource($sdfResId, $sdfParams);
         // Create the Layer
         $layerResId = new MgResourceIdentifier('Session:' . $this->args['SESSION'] . '//Filter.LayerDefinition');
         $layerDefinition = file_get_contents("templates/filterlayerdefinition.xml");
         $layerDefinition = sprintf($layerDefinition, $sdfResId->ToString());
         $byteSource = new MgByteSource($layerDefinition, strlen($layerDefinition));
         $resourceService->SetResource($layerResId, $byteSource->GetReader(), null);
         $layer = new MgLayer($layerResId, $resourceService);
         $layer->SetName('_QuerySpatialFilter');
         $layer->SetLegendLabel('_QuerySpatialFilter');
         $layer->SetDisplayInLegend(false);
         $layer->SetSelectable(false);
         $layers->Insert(0, $layer);
     }
     // Make the layer visible
     $layer->SetVisible(true);
     $map->Save($resourceService);
     // Add the geometry to the filter feature source
     $polygon = $this->CreatePolygonFromGeomText($this->args['GEOMTEXT']);
     $agfWriter = new MgAgfReaderWriter();
     $byteReader = $agfWriter->Write($polygon);
     $propertyValues = new MgPropertyCollection();
     $propertyValues->Add(new MgGeometryProperty('Geometry', $byteReader));
     $updateCommands->Add(new MgInsertFeatures('Filter', $propertyValues));
     $featureService->UpdateFeatures($sdfResId, $updateCommands, false);
     return $result;
 }
Exemplo n.º 2
0
$agf = new MgAgfReaderWriter();
$fact = new MgGeometryFactory();
echo "Created wkt/agf\n";
$count = 100;
$i = 0;
for ($i = 1; $i <= $count; $i++) {
    $bufferProps = new MgPropertyCollection();
    $nameProp = new MgStringProperty("NAME", "NewName_" . $i);
    $bufferProps->Add($nameProp);
    $x = 120 + $i / $count;
    $y = 100 + $i / $count;
    //$wktText = "POLYGON ((20 20, 20 100, {$x} {$y}, 140 20, 20 20))";
    //$geom = $wkt->Read($wktText);
    $coord = $fact->CreateCoordinateXY($x, $y);
    $geom = $fact->CreatePoint($coord);
    $geomReader = $agf->Write($geom);
    $geomProp = new MgGeometryProperty("GEOM", $geomReader);
    $bufferProps->Add($geomProp);
    $batchProp->Add($bufferProps);
}
echo "Created geometries via wkt\n";
$cmd = new MgInsertFeatures("Buffer", $batchProp);
$cmdColl = new MgFeatureCommandCollection();
$cmdColl->Add($cmd);
try {
    $svc->CreateFeatureSource($id, $params);
    $startTime = microtime(true);
    $props = $svc->UpdateFeatures($id, $cmdColl, false);
    $endTime = microtime(true);
    $diffTime = $endTime - $startTime;
    $reader = $props->GetItem(0)->GetValue();
Exemplo n.º 3
0
function MakeLine($name, $x0, $y0, $x1, $y1)
{
    $propertyCollection = new MgPropertyCollection();
    $nameProperty = new MgStringProperty("NAME", $name);
    $propertyCollection->Add($nameProperty);
    $wktReaderWriter = new MgWktReaderWriter();
    $agfReaderWriter = new MgAgfReaderWriter();
    $geometry = $wktReaderWriter->Read("LINESTRING XY ({$x0} {$y0}, {$x1} {$y1})");
    $geometryByteReader = $agfReaderWriter->Write($geometry);
    $geometryProperty = new MgGeometryProperty("SHPGEOM", $geometryByteReader);
    $propertyCollection->Add($geometryProperty);
    return $propertyCollection;
}
Exemplo n.º 4
0
 function InsertCommand($key)
 {
     $props = new MgPropertyCollection();
     $keyProp = new MgStringProperty("SKEY", $key);
     $props->Add($keyProp);
     $nameProp = new MgStringProperty("NAME", "StringKey" . $key);
     $props->Add($nameProp);
     $wkt = new MgWktReaderWriter();
     $agf = new MgAgfReaderWriter();
     $geom = $wkt->Read("POLYGON ((20 20, 20 100, 120 100, 140 20, 20 20))");
     $geomReader = $agf->Write($geom);
     $geomProp = new MgGeometryProperty("GEOM", $geomReader);
     $props->Add($geomProp);
     $cmd = new MgInsertFeatures("StringKey", $props);
     return $cmd;
 }
Exemplo n.º 5
0
 function AddPolygon()
 {
     $geometryFactory = new MgGeometryFactory();
     $agfWriter = new MgAgfReaderWriter();
     $vertices = explode(',', $this->args['GEOMETRY']);
     $count = $vertices[0];
     $coords = new MgCoordinateCollection();
     for ($i = 0; $i < $count; $i++) {
         $coord = $geometryFactory->CreateCoordinateXY((double) $vertices[$i * 2 + 1], (double) $vertices[$i * 2 + 2]);
         $coords->Add($coord);
     }
     // Add the first vertex to make the ring close
     if ($count > 2) {
         $coord = $geometryFactory->CreateCoordinateXY((double) $vertices[1], (double) $vertices[2]);
         $coords->Add($coord);
     }
     $linearRing = $geometryFactory->CreateLinearRing($coords);
     $polygon = $geometryFactory->CreatePolygon($linearRing, null);
     $trans = $this->GetTransform();
     if (null != $trans) {
         $polygon = $polygon->Transform($trans);
     }
     $byteReader = $agfWriter->Write($polygon);
     $propertyValues = new MgPropertyCollection();
     $propertyValues->Add(new MgStringProperty('Text', $this->args['TEXT']));
     $propertyValues->Add(new MgGeometryProperty('Geometry', $byteReader));
     $this->InsertMarkupFeature($propertyValues);
 }
Exemplo n.º 6
0
             }
             $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));
             }
             // Old way, pre MapGuide OS 2.0
             //$featureService->UpdateFeatures($bufferFeatureResId, $commands, false);
             // New way, post MapGuide OS 2.0
             $bufferLayer->UpdateFeatures($commands);
             $bufferLayer->SetVisible(true);
             $bufferLayer->ForceRefresh();
             $bufferLayer->SetDisplayInLegend(true);
             $map->Save();
         }
     }
 } else {
     echo 'No selected layers';
 }
Exemplo n.º 7
0
        } else {
            if ($addressLayer->GetVisible()) {
                // If the layer exists and is visible, then display the
                // previous results.
                EmitAddressResults($featureService, $addressMarkerDataResId, $mgSessionId);
            }
        }
        // Insert the results of the Geo-Code into the temporary
        // feature source and ensure the address marker layer
        // is visible.
        $geometryReaderWriter = new MgAgfReaderWriter();
        $geometryFactory = new MgGeometryFactory();
        $addrPoint = $geometryFactory->CreatePoint($geometryFactory->CreateCoordinateXY((double) $long, (double) $lat));
        $properties = new MgPropertyCollection();
        $properties->Add(new MgStringProperty('Address', $address1));
        $properties->Add(new MgGeometryProperty('Location', $geometryReaderWriter->Write($addrPoint)));
        $commands = new MgFeatureCommandCollection();
        $commands->Add(new MgInsertFeatures('AddressMarker', $properties));
        $featureService->UpdateFeatures($addressMarkerDataResId, $commands, false);
        $addressLayer->SetVisible(true);
        $addressLayer->ForceRefresh();
        $map->Save($resourceService);
        $success = true;
    } else {
        echo '<tr><td>Address not found: ' . $address . '<hr></td></tr>';
        $success = false;
    }
} catch (MgException $e) {
    echo $e->GetExceptionMessage();
    echo '<br>';
    echo $e->GetDetails();
Exemplo n.º 8
0
         } else {
             $srsXform = $srsFactory->GetTransform($layerCs, $srsMap);
         }
     } else {
         $srsXform = null;
     }
     while ($featureReader->ReadNext()) {
         $oGeomAgf = $featureReader->GetGeometry($geomPropName);
         $oGeom = $agfRW->Read($oGeomAgf);
         $wktReaderWriter = new MgWktReaderWriter();
         $agfTextPoint = $wktReaderWriter->Write($oGeom);
         //echo "<!-- wkt: ".$agfTextPoint." -->\n";
         if (!$merge) {
             /* use measure to accomodate differences in SRS */
             $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));
         } else {
             if ($srsXform == null) {
                 $oNewGeom = $oGeom;
             } else {
                 $oNewGeom = $oGeom->Transform($srsXform);
             }
             $inputGeometries->Add($oNewGeom);
         }
     }
     $featureReader->Close();
 }
 if ($merge) {
Exemplo n.º 9
0
 // New way, post MapGuide OS 2.0
 $featureReader = $layer->SelectFeatures($queryOptions);
 // Get the features from the feature source,
 // determine the centroid of each selected feature, and
 // add a point to the ParcelMarker layer to mark the
 // centroid.
 // Collect all the points into an MgFeatureCommandCollection,
 // so they can all be added in one operation.
 $parcelMarkerCommands = new MgFeatureCommandCollection();
 while ($featureReader->ReadNext()) {
     $byteReader = $featureReader->GetGeometry('SHPGEOM');
     $geometry = $agfReaderWriter->Read($byteReader);
     $point = $geometry->GetCentroid();
     // Create an insert command for this parcel.
     $properties = new MgPropertyCollection();
     $properties->Add(new MgGeometryProperty('ParcelLocation', $agfReaderWriter->Write($point)));
     $parcelMarkerCommands->Add(new MgInsertFeatures('ParcelMarkerClass', $properties));
 }
 $featureReader->Close();
 if ($parcelMarkerCommands->GetCount() > 0) {
     // Old way, pre MapGuide OS 2.0. Kept here for reference
     //$featureService->UpdateFeatures($parcelFeatureResId, $parcelMarkerCommands, false);
     // New way, post MapGuide OS 2.0
     $parcelMarkerLayer->UpdateFeatures($parcelMarkerCommands);
 } else {
     echo '</p><p>No parcels within the buffer area match.';
 }
 // Create a feature in the buffer feature source to show the area covered by the buffer.
 $properties = new MgPropertyCollection();
 $properties->Add(new MgGeometryProperty('BufferGeometry', $agfReaderWriter->Write($bufferGeometry)));
 $commands = new MgFeatureCommandCollection();
function MakePoint($name, $x, $y)
{
    $propertyCollection = new MgPropertyCollection();
    $nameProperty = new MgStringProperty("NAME", $name);
    $propertyCollection->Add($nameProperty);
    $wktReaderWriter = new MgWktReaderWriter();
    $agfReaderWriter = new MgAgfReaderWriter();
    $geometry = $wktReaderWriter->Read("POINT XY ({$x} {$y})");
    $geometryByteReader = $agfReaderWriter->Write($geometry);
    $geometryProperty = new MgGeometryProperty("GEOM", $geometryByteReader);
    $propertyCollection->Add($geometryProperty);
    return $propertyCollection;
}