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; }
$csCodes = $csFactory->EnumerateCoordinateSystems($category); $mapped = 0; $grandTotal += $csCodes->GetCount(); for ($i = 0; $i < $csCodes->GetCount(); $i++) { $csProps = $csCodes->GetItem($i); for ($j = 0; $j < $csProps->GetCount(); $j++) { $prop = $csProps->GetItem($j); if (strcmp(strtolower($prop->GetName()), "code") == 0) { try { $csCode = $prop->GetValue(); $csWkt = $csFactory->ConvertCoordinateSystemCodeToWkt($csCode); if (strlen(trim($csWkt)) == 0) { echo "Skipping {$csCode}: Empty WKT\n"; continue; } $epsg = $csFactory->ConvertWktToEpsgCode($csWkt); if ($epsg <= 0) { echo "Skipping {$csCode}: Invalid EPSG code - {$epsg}\n"; continue; } if ($epsg == 3785 || $epsg == 4269 || $epsg == 4326 || $epsg == 102113 || $epsg == 900913 || $epsg == 3857) { echo "Skipping {$csCode}: EPSG code already defined by Proj4js - {$epsg}\n"; continue; } try { $proj4 = get_proj4_string($epsg); if ($proj4 != null) { $line = "Proj4js.defs[\"EPSG:{$epsg}\"] = \"{$proj4}\"; //Mentor: {$csCode}\n"; fwrite($file, $line); echo "Got proj4 string for: {$csCode} (EPSG:{$epsg})\n"; $mapped++;
$map = new MgMap(); $map->Open($resourceService, $mapName); $mapTitle = $map->GetName(); $mapid = $map->GetMapDefinition()->ToString(); } $extents = $map->GetMapExtent(); @($oMin = $extents->GetLowerLeftCoordinate()); @($oMax = $extents->GetUpperRightCoordinate()); @($srs = $map->GetMapSRS()); $epsgCode = ""; if ($srs != "") { @($csFactory = new MgCoordinateSystemFactory()); @($cs = $csFactory->Create($srs)); @($metersPerUnit = $cs->ConvertCoordinateSystemUnitsToMeters(1.0)); try { $epsgCode = $csFactory->ConvertWktToEpsgCode($srs); // Convert EPSG code 3857 to the equivalent code 900913 that is understood by OpenLayers if ($epsgCode == 3857) { $epsgCode = 900913; // We need to set the srs code to null because OpenLayers doesn't know the srs code. $srs = ""; } } catch (MgException $e) { //just catch the exception and set epsgCode to empty string } // $unitsType = $cs->GetUnits(); } else { $metersPerUnit = 1.0; //$unitsType = "Meters"; } header('Content-type: application/json');
<!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: ConvertWktToEpsgCode</b><br><br>"; $factory = new MgCoordinateSystemFactory(); $wkt = $_GET['WKT']; $code = $factory->ConvertWktToEpsgCode($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>EPSG 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;