[mapguide-users] Transform coordinates from a BC,
Canada Albers projection to geographic
Bruce A
bahall at eastlink.ca
Mon Mar 19 20:34:38 EDT 2007
I am trying to transform coordinates from a BC, Canada Albers projection to
geographic and I cannot get the correct results using Mapguide’s WKT and
transformation capabilities.
The PHP code below outlines the WKT for the reference systems above (I
believe) and the transformation code. I have tried several permutations of
the WKT for the projection without success. I am not certain that the
definition being used is correct… However, if I use what I believe to be the
“correct” definition – the transformation produces an error outlined below
and others although they do not produce an error produce incorrect results.
“ERROR: The coordinate system transform failed. PROJ4 failed to transform
the data.
- MgCoordinateSystemTransform.Transform line 98 file
c:\build_bond_area\mapguide_open_source\build_3.1\mgdev\common\geometry\CoordinateSystem/CoordinateSystemTransform.cpp”
Included in the file are sample coordinates to project and sample lat, lon
to indicate the correct range of values.
Can anyone indicate what is wrong with the below…
Thanks in advance,
Bruce
<html>
<head><title>Transform Albers to Geographic</title></head>
<body>
<p>
<?php
$installDir ='C:\Program Files\MapGuideOpenSource\\';
$extensionsDir = $installDir . 'WebServerExtensions\www\\';
$viewerDir = $extensionsDir . 'mapviewerphp\\';
include "../appconstants.php";
include "common.php";
try
{
// function alb2geo($point) {
try
{
$wktGeo = 'GEOGCS["Longitude/Latitude(NAD 83)",DATUM["NAD 83", SPHEROID
["GRS 80", 6378137, 298.257222101]], RRIMEM [ "Greenwich", 0.000000 ], UNIT
["Decimal Degree", 0.01745329251994330]]';
$wktAlb = 'PROJCS["BC_Albers",
GEOGCS["LL83",DATUM["NAD83",SPHEROID["GRS1980",6378137.000,298.257222101]],PRIMEM["Greenwich",
0],UNIT["Degree",0.01745329251994330]],PROJECTION["Albers_Conic_Equal_Area"],PARAMETER["false_easting",1000000.000],PARAMETER["false_northing",0.000],PARAMETER["standard_parallel_1",58.500000],PARAMETER["standard_parallel_2",50.0],PARAMETER["latitude_of_origin",45.0000],PARAMETER["central_meridian",-126.000000],UNIT["Meter",1.00000],AUTHORITY["EPSG","3005"]]';
//$wktAlb = 'PROJCS["BC_Albers",
GEOGCS["LL83",DATUM["NAD83",SPHEROID["GRS1980",6378137.000,298.257222101]],PRIMEM["Greenwich",
0],UNIT["Degree",0.01745329251994330]],PROJECTION["Albers_Conic_Equal_Area"],PARAMETER["false_easting",1000000.000],PARAMETER["false_northing",0.000],PARAMETER["standard_parallel_1",58.500000],PARAMETER["standard_parallel_2",50.0],PARAMETER["latitude_of_origin",45.0000],PARAMETER["central_meridian",-126.000000],UNIT["Meter",1.00000]]';
//$wktAlb = 'PROJCS["BC_Albers", DATUM["NAD83", SPHEROID["GRS1980",
6378137.000, 298.257222101]], PRIMEM["Greenwich", 0.000000], UNIT ["Degree",
0.01745329251994330]],
PROJECTION["Albers_Conic_Equal_Area"],PARAMETER["False_Easting",1000000.0],PARAMETER["False_Northing",0.0],PARAMETER["Standard_Parallel_1",50],PARAMETER["Standard_Parallel_2",58.5],PARAMETER["Latitude_Of_Origin",45],PARAMETER["Central_Meridian",-126.0],UNIT["Meter",1.0]]';
$coordSysFactory = new MgCoordinateSystemFactory();
$coordSysAlb = $coordSysFactory->Create($wktAlb);
$coordSysGeo = $coordSysFactory->Create($wktGeo);
//$xProj = $point.X;
//$yProj = $point.Y;
$xProj = 1094382;
$yProj = 448309;
$xLat = 49.05958;
$yLon = -122.8836876;
$geometryFactory = new MgGeometryFactory();
$coord_XY_IN = $geometryFactory->CreateCoordinateXY($xProj,$yProj);
$coord_LL_IN = $geometryFactory->CreateCoordinateXY($xLat,$yLon);
$point_XY_IN = $geometryFactory->CreatePoint($coord_XY_IN);
$point_LL_IN = $geometryFactory->CreatePoint($coord_LL_IN);
// Test 1 strate translate based on existing function
// $convertedCoordinate = $coordSysAlb->ConvertToLonLat($coord_XY_IN);
// $xConv = $convertedCoordinate->GetX() / $offset;
// $yConv = $convertedCoordinate->GetY() / $offset;
// echo '</p>';
// echo "***** ConvertToLonLat ***** ";
// echo '</p>';
// echo "($xProj, $yProj) to ($xConv, $yConv)";
// Setup of transformation.
$Alb2GeoTransform = new MgCoordinateSystemTransform($coordSysAlb,
$coordSysGeo);
$Geo2AlbTransform = new MgCoordinateSystemTransform($coordSysGeo,
$coordSysAlb);
$point_LL_OUT = $point_XY_IN->Transform($Alb2GeoTransform);
$point_XY_OUT = $point_LL_IN->Transform($Geo2AlbTransform);
// Output the points
echo '</p>';
echo " ***** LL2XY Output ***** ";
echo '</p>';
$X_LL = $point_XY_OUT->GetCoordinate()->GetX() * $offset;
echo " X_LL: ";
echo $X_LL;
$Y_LL = $point_XY_OUT->GetCoordinate()->GetY() * $offset;
echo " Y_LL: ";
echo $Y_LL;
//
echo '</p>';
echo " ***** XY2LL Output ***** ";
echo '</p>';
$X_XY = $point_LL_OUT->GetCoordinate()->GetX() / $offset;
echo " X_XY: ";
echo $X_XY;
$Y_XY = $point_LL_OUT->GetCoordinate()->GetY() / $offset;
echo " Y_XY: ";
echo $Y_XY;
}
catch (Exception $e)
{
echo "ERROR: " . $e->GetMessage() . "<br />";
$errorMsg = $e->GetMessage();
}
}
catch (MgException $e)
{
echo "ERROR: " . $e->GetMessage() . "<br />";
echo $e->GetStackTrace() . "<br />";
}
?>
</p>
</body>
</html>
--
View this message in context: http://www.nabble.com/Transform-coordinates-from-a-BC%2C-Canada-Albers-projection-to-geographic-tf3430756s16610.html#a9564014
Sent from the MapGuide Users mailing list archive at Nabble.com.
More information about the mapguide-users
mailing list