[mapguide-internals] new projection in csmap
Jason Birch
Jason.Birch at nanaimo.ca
Wed Apr 29 16:16:24 EDT 2009
In what context?
Do you need it to be accessible in MapGuide Studio's drop-downs? If not, you can just attach a WKT CS to the relevant MapGuide resources (data source override, map, whatever).
Your WKT looks to be PROJ.4 specific. I think the native version looks something like this:
PROJCS["Popular Visualisation CRS / Mercator",GEOGCS["Popular Visualisation CRS",DATUM["Popular_Visualisation_Datum",SPHEROID["Popular Visualisation Sphere",6378137,0,AUTHORITY["EPSG","7059"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6055"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4055"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],PROJECTION["Mercator_1SP"],PARAMETER["central_meridian",0],PARAMETER["scale_factor",1],PARAMETER["false_easting",0],PARAMETER["false_northing",0],AUTHORITY["EPSG","3785"],AXIS["X",EAST],AXIS["Y",NORTH]]
I've attached a simple PHP script I threw together to calculate extents of a layer in LL84 and Popular ("Google") projections.
If you do need it to be selectable in Studio, I'm not sure how you would do it. The preliminary users guide for CS-MAP mentions the CS_COMP.exe, which is generated as part of the open source build. I wonder if it is as easy as editing the .asc files and (maybe?) recompiling?
Jason
-----Original Message-----
From: Paul Spencer
Sent: Wednesday, April 29, 2009 12:26 PM
To: MapGuide Internals Mail List
Subject: [mapguide-internals] new projection in csmap
How do I add a new projection to CSMap? Specifically, the spherical
mercator projection used by the commercial web mapping folks:
PROJCS["unnamed",GEOGCS["unnamed
ellipse",DATUM["unknown",SPHEROID["unnamed",
6378137,0]],PRIMEM["Greenwich",0],UNIT["degree",
0.0174532925199433
]],PROJECTION["Mercator_2SP"],PARAMETER["standard_parallel_1",
0],PARAMETER["central_meridian",0],PARAMETER["false_easting",
0],PARAMETER["false_northing",0],UNIT["Meter",
1],EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0
+lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext
+no_defs"]]
-------------- next part --------------
<?php
$featureResource = "Library://ParcelData.FeatureSource";
$installDir = 'C:/Program Files/OSGeo/MapGuide Web/';
$wktGoogle = 'PROJCS["Popular Visualisation CRS / Mercator",GEOGCS["Popular Visualisation CRS",DATUM["Popular_Visualisation_Datum",SPHEROID["Popular Visualisation Sphere",6378137,0,AUTHORITY["EPSG","7059"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6055"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4055"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],PROJECTION["Mercator_1SP"],PARAMETER["central_meridian",0],PARAMETER["scale_factor",1],PARAMETER["false_easting",0],PARAMETER["false_northing",0],AUTHORITY["EPSG","3785"],AXIS["X",EAST],AXIS["Y",NORTH]]';
$wktLL84 = 'GEOGCS["LL84",DATUM["WGS84",SPHEROID["WGS84",6378137.000,298.25722293]],PRIMEM["Greenwich",0],UNIT["Degree",0.01745329251994]]';
function getExtents($geom)
{
try
{
$ll = $geom->GetLowerLeftCoordinate();
$ur = $geom->GetUpperRightCoordinate();
return array (
'x1' => $ll->GetX(),
'y1' => $ll->GetY(),
'x2' => $ur->GetX(),
'y2' => $ur->GetY()
);
}
catch (MgException $e) {
return NULL;
}
}
try
{
require($installDir."/www/mapviewerphp/constants.php");
MgInitializeWebTier($installDir."www/webconfig.ini");
$agfReaderWriter = new MgAgfReaderWriter();
$wktReaderWriter = new MgWktReaderWriter();
$csFactory = new MgCoordinateSystemFactory();
$csGoogle = $csFactory->Create($wktGoogle);
$csLL84 = $csFactory->Create($wktLL84);
$user = new MgUserInformation("Anonymous", "");
$siteConnection = new MgSiteConnection();
$siteConnection->Open($user);
$featureService = $siteConnection->CreateService(MgServiceType::FeatureService);
$resourceID = new MgResourceIdentifier($featureResource);
$scReader = $featureService->GetSpatialContexts($resourceID,false);
$scReader->ReadNext();
$wktSourceCs = $scReader->GetCoordinateSystemWkt();
$csSource = $csFactory->Create($wktSourceCs);
$extentBinary = $scReader->GetExtent();
$extentAgfSource = $agfReaderWriter->Read($extentBinary)->Envelope();
$extentAgfLL84 = $agfReaderWriter->Read($extentBinary, $csFactory->GetTransform($csSource,$csLL84))->Envelope();
$extentAgfGoogle = $agfReaderWriter->Read($extentBinary, $csFactory->GetTransform($csSource,$csGoogle))->Envelope();
header('Content-type: text/plain');
print "Feature Source:\r\n\r\n";
print $featureResource;
print "\r\n\r\nSource Coordinates:\r\n\r\n";
print_r(getExtents($extentAgfSource));
print "\r\n\r\nLL84 Coordinates:\r\n\r\n";
print_r(getExtents($extentAgfLL84));
print "\r\n\r\nGoogle Coordinates:\r\n\r\n";
print_r(getExtents($extentAgfGoogle));
}
catch (MgException $e) {
echo "ERROR: " . $e->GetMessage() . "\n";
echo $e->GetDetails() . "\n";
echo $e->GetStackTrace() . "\n";
exit;
}
?>
More information about the mapguide-internals
mailing list