Exemplo n.º 1
0
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
<?php 
include "initwebtier.php";
$code = "";
$wkt = "";
$errorMsg = "";
$status = "";
try {
    echo "<b>Coordinate System API: ConvertWktToCoordinateSystemCode</b><br><br>";
    $factory = new MgCoordinateSystemFactory();
    $wkt = $_GET['WKT'];
    $code = $factory->ConvertWktToCoordinateSystemCode($wkt);
    $status = "Pass";
} catch (MgException $e) {
    $errorMsg = $e->GetExceptionMessage();
    $status = "Fail";
} catch (Exception $e) {
    $errorMsg = $e->getMessage();
    $status = "Fail";
}
echo "<b>OGC WKT:</b><br>";
echo "{$wkt}<br><br>";
echo "<b>Code:</b><br>";
echo "{$code}<br><br>";
echo "<b>Status:</b><br>";
echo "{$status}<br><br>";
if ($errorMsg != "") {
    echo "<b>Error:</b><br>";
    echo $errorMsg;
Exemplo n.º 2
0
 public static function GetFeatureClassMBR($app, $featureSrvc, $featuresId, $schemaName, $className, $geomName = null, $transformToCsCode = null)
 {
     $extentGeometryAgg = null;
     $extentGeometrySc = null;
     $extentByteReader = null;
     $mbr = new stdClass();
     $csFactory = new MgCoordinateSystemFactory();
     $clsDef = $featureSrvc->GetClassDefinition($featuresId, $schemaName, $className);
     $props = $clsDef->GetProperties();
     if ($geomName == null) {
         $geomName = $clsDef->GetDefaultGeometryPropertyName();
     }
     $geomProp = $props->GetItem($geomName);
     if ($geomProp->GetPropertyType() != MgFeaturePropertyType::GeometricProperty) {
         throw new Exception($app->localizer->getText("E_NOT_GEOMETRY_PROPERTY", $geomName));
     }
     $spatialContext = $geomProp->GetSpatialContextAssociation();
     // Finds the coordinate system
     $agfReaderWriter = new MgAgfReaderWriter();
     $spatialcontextReader = $featureSrvc->GetSpatialContexts($featuresId, false);
     while ($spatialcontextReader->ReadNext()) {
         if ($spatialcontextReader->GetName() == $spatialContext) {
             $mbr->coordinateSystem = $spatialcontextReader->GetCoordinateSystemWkt();
             $mbr->csCode = $csFactory->ConvertWktToCoordinateSystemCode($mbr->coordinateSystem);
             $mbr->epsg = $csFactory->ConvertWktToEpsgCode($mbr->coordinateSystem);
             // Finds the extent
             $extentByteReader = $spatialcontextReader->GetExtent();
             break;
         }
     }
     $spatialcontextReader->Close();
     if ($extentByteReader != null) {
         // Get the extent geometry from the spatial context
         $extentGeometrySc = $agfReaderWriter->Read($extentByteReader);
     }
     // Try to get the extents using the selectaggregate as sometimes the spatial context
     // information is not set
     $aggregateOptions = new MgFeatureAggregateOptions();
     $featureProp = 'SPATIALEXTENTS("' . $geomName . '")';
     $aggregateOptions->AddComputedProperty('EXTENTS', $featureProp);
     try {
         $dataReader = $featureSrvc->SelectAggregate($featuresId, $className, $aggregateOptions);
         if ($dataReader->ReadNext()) {
             // Get the extents information
             $byteReader = $dataReader->GetGeometry('EXTENTS');
             $extentGeometryAgg = $agfReaderWriter->Read($byteReader);
         }
         $dataReader->Close();
     } catch (MgException $e) {
         if ($extentGeometryAgg == null) {
             //We do have one last hope. EXTENT() is an internal MapGuide custom function that's universally supported
             //as it operates against an underlying select query result. This raw-spins the reader server-side so there
             //is no server -> web tier transmission overhead involved.
             try {
                 $aggregateOptions = new MgFeatureAggregateOptions();
                 $aggregateOptions->AddComputedProperty("COMP_EXTENT", "EXTENT(" . $geomName . ")");
                 $dataReader = $featureSrvc->SelectAggregate($featuresId, $className, $aggregateOptions);
                 if ($dataReader->ReadNext()) {
                     // Get the extents information
                     $byteReader = $dataReader->GetGeometry('COMP_EXTENT');
                     $extentGeometryAgg = $agfReaderWriter->Read($byteReader);
                 }
                 $dataReader->Close();
             } catch (MgException $e2) {
             }
         }
     }
     $mbr->extentGeometry = null;
     // Prefer SpatialExtents() of EXTENT() result over spatial context extent
     if ($extentGeometryAgg != null) {
         $mbr->extentGeometry = $extentGeometryAgg;
     }
     if ($mbr->extentGeometry == null) {
         //Stil null? Now try spatial context
         if ($extentGeometrySc != null) {
             $mbr->extentGeometry = $extentGeometrySc;
         }
     }
     if ($transformToCsCode != null) {
         $sourceCs = $csFactory->CreateFromCode($mbr->csCode);
         $targetCs = $csFactory->CreateFromCode($transformToCsCode);
         $xform = $csFactory->GetTransform($sourceCs, $targetCs);
         $mbr->extentGeometry = $mbr->extentGeometry->Transform($xform);
         $mbr->csCode = $targetCs->GetCsCode();
         $mbr->epsg = $targetCs->GetEpsgCode();
     }
     return $mbr;
 }