[mapguide-users] Converting Coordinate values (LL83) to (UTM83 -17)

Micallef, Michael (MTO) Michael.Micallef at ontario.ca
Thu Mar 12 13:26:02 EDT 2009


Hello Everyone:

 

I am reading the coordinate values from the selected features and
creating an inset map for each.  The features are in LL83 and I need to
specify the map coordinates in UTM83-17 with the scale to produce the
maps via URL.

 

Existing code  - works if map is in LL83

 

 

$agfReaderWriter = new MgAgfReaderWriter();

$MikeSelected_feat_geom_data =
$agfReaderWriter->Read($mike_GeometryData);

$firstTime = true;

 

                    $extentGeometry =
$agfReaderWriter->Read($mike_GeometryData);

                    $iterator = $extentGeometry->GetCoordinates();

                    while($iterator->MoveNext())

                        {

                              $x = $iterator->GetCurrent()->GetX();

                        

                              $y = $iterator->GetCurrent()->GetY();

                        

                              if($firstTime)

                              {

                                    $maxX = $x;

                                    $minX = $x;

                                    $maxY = $y;

                                    $minY = $y;

                                    $firstTime = false;

                              }

                              if($maxX>$x)

                                    $maxX = $x;

                              if($minX<$x||$minX==0)

                                    $minX = $x;

                              if($maxY<$y)

                                    $maxY = $y;

                              if($minY>$y||$minY==0)

                                    $minY = $y;

                        }

 

$mike_x = ($minX + (($minX - $maxX)* -1)/2);

$mike_y = ($maxY + $minY)/2;

 

      //Echo $x;

//    Echo "<br>" . $y; 

 

 

$masterscale = $map->GetViewScale();

$mscale = "15000";

 

if ($shpArea < 3)

$mscale = "5000";

 

$mapdef = $map->GetMapDefinition();

$mapdef_name = $mapdef->GetName();

$mapdef_path = $mapdef->GetPath();

 

   echo "<Hr><Hr>";

   echo "Scale:   " . $mscale;

   echo "<br>";

//----------------------------------switch coordinates

 

//HERE is where I need the code to switch $mike_x and $mike_y to
UTM83-17 coordinates!

 

 

//-------------------------------------- SWITCH Coords END

 

$mapdef_path_enc = urlencode("Library://" . $mapdef_path . "/" .
$mapdef_name . ".MapDefinition");

 

 

   echo "<br>";

 

 

echo "<img align='center' border='1'
bordercolor='FFCC33'src='http://142.142.41.157:8008/mapguide/mapagent/ma
pagent.fcgi?OPERATION=GETMAPIMAGE&VERSION=1.0.0&MAPNAME=$mapName&LOCALE=
en&MAPDEFINITION=$mapdef_path_enc&FORMAT=PNG&SETVIEWCENTERX=$mike_x&SETV
IEWCENTERY=$mike_y&SETVIEWSCALE=$mscale&SETDISPLAYDPI=140&SETDISPLAYWIDT
H=650&SETDISPLAYHEIGHT=500&HIDELAYERS=$high_layer&USERNAME=Administrator
&PASSWORD=admin'>";

 

 

 

I have tried a few of the examples including:

     $xGeog = -71.061342;
        $yGeog = 42.355892;
        $geometryFactory = new MgGeometryFactory
<http://mapguide.osgeo.org/files/mapguide/docs/webapi/d4/d46/class_mg_ge
ometry_factory.htm> ();
        $coordinate = $geometryFactory->CreateCoordinateXY($xGeog,
$yGeog);
        // See the example code for the creation of the $coordSys object
        // in the comments on the Create method of the
MgCoordinateSystemFactory class.
        $convertedCoordinate =
$coordSys->ConvertFromLonLat($coordinate);
        $xConv = $convertedCoordinate->GetX();
        $yConv = $convertedCoordinate->GetY();
        echo  "($xGeog, $yGeog) to ($xConv, $yConv)\n";

 

With supporting coordinate systems - not working for me - 

 

 

Any help would be appreciated.

 

Mike

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapguide-users/attachments/20090312/120c2b51/attachment.html


More information about the mapguide-users mailing list