/** * Builds a coordinate system transform from the class definition's coordinate system to the target * coordinate system indicated by the given coordinate system code */ public static function GetTransform($featSvc, $resId, $schemaName, $className, $transformto, $bInvert = false) { $transform = null; $factory = new MgCoordinateSystemFactory(); $targetWkt = $factory->ConvertCoordinateSystemCodeToWkt($transformto); $clsDef = $featSvc->GetClassDefinition($resId, $schemaName, $className); //Has a designated geometry property, use it's spatial context if ($clsDef->GetDefaultGeometryPropertyName() !== "") { $props = $clsDef->GetProperties(); $idx = $props->IndexOf($clsDef->GetDefaultGeometryPropertyName()); if ($idx >= 0) { $geomProp = $props->GetItem($idx); $scName = $geomProp->GetSpatialContextAssociation(); $scReader = $featSvc->GetSpatialContexts($resId, false); while ($scReader->ReadNext()) { if ($scReader->GetName() === $scName) { if ($scReader->GetCoordinateSystemWkt() !== $targetWkt) { $targetCs = $factory->CreateFromCode($transformto); $sourceCs = $factory->Create($scReader->GetCoordinateSystemWkt()); if ($bInvert) { $transform = $factory->GetTransform($targetCs, $sourceCs); } else { $transform = $factory->GetTransform($sourceCs, $targetCs); } break; } } } $scReader->Close(); } } return $transform; }
$csFactory = new MgCoordinateSystemFactory(); $csCategories = $csFactory->EnumerateCategories(); for ($k = 0; $k < $csCategories->GetCount(); $k++) { $category = $csCategories->GetItem($k); echo ">>> Fetching CS-Map coordinate systems: {$category} <<<\n"; $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);
<!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: ConvertCoordinateSystemCodeToWkt</b><br><br>"; $factory = new MgCoordinateSystemFactory(); $code = $_GET['CODE']; $wkt = $factory->ConvertCoordinateSystemCodeToWkt($code); $status = "Pass"; } catch (MgException $e) { $errorMsg = $e->GetExceptionMessage(); $status = "Fail"; } catch (Exception $e) { $errorMsg = $e->getMessage(); $status = "Fail"; } echo "<b>Code:</b><br>"; echo "{$code}<br><br>"; echo "<b>OGC WKT:</b><br>"; echo "{$wkt}<br><br>"; echo "<b>Status:</b><br>"; echo "{$status}<br><br>"; if ($errorMsg != "") { echo "<b>Error:</b><br>"; echo $errorMsg;
public function ConvertCsCodeToWkt($cscode, $format) { //Check for unsupported representations $fmt = $this->ValidateRepresentation($format, array("xml", "json")); $factory = new MgCoordinateSystemFactory(); $wkt = $factory->ConvertCoordinateSystemCodeToWkt($cscode); $body = MgBoxedValue::String($wkt, $fmt); if ($fmt == "xml") { $this->app->response->header("Content-Type", MgMimeType::Xml); } else { $this->app->response->header("Content-Type", MgMimeType::Json); } $this->app->response->setBody($body); }