coordinate systems transformations

Gregor Mosheh stigmata_blackangel at YAHOO.COM
Sat Mar 26 14:40:43 EST 2005


--- Mauricio Leon <mleon at SCIENTIFICINFORMATICS.COM>
> I still have the problem of transforming coordinates
> in degrees into map extents.  Specifically, I need
> to create maps around points given in
> latitude-longitude coordinates

Ah, I see. All the maps we deal with use UTM as the
output projection - we found that doing any kind of
math on degrees is a real pain, since the linear size
of a degree is not constant. My advice would be to
project the data out of DD into a planar coordinate
system, by setting a different output projection in
your mapfile.

If you're talking about a search program you wrote
that looks up a point whose coords are latlong, and
you want to convert those points into a planar system,
it depends on the language you're using to fetch the
points. If you're using PHP/MapScript, it goes
something like this:

- the SQL query to fetch the data included
"AsText(the_geom) AS the_geom" so that the geometry
info would be in an easy-to-parse format.

      // fetch the projection string
      $projection = 'init=epsg:26710';

      // the_geom is in that fetched record, and
      // fetching it depends on your DB code,
      // e.g. ADOdb
      $the_geom = $records->fields['the_geom'];

      // figure out $x and $y, the coords of the point
      $coords = array();
      preg_match('/POINT\((\-?\d+\.?\d*)
(\-?\d+\.?\d*)\)/',$the_geom,$coords);
      $x = $coords[1];
      $y = $coords[2];
      // reproject the point into the map's target
projection
      $projInObj  =
ms_newprojectionobj("proj=latlong");
      $projOutObj =
ms_newprojectionobj(preg_replace('/\s+/',',',$projection));
      $poPoint    = ms_newpointobj();
      $poPoint->setXY($x, $y);
      $poPoint->project($projInObj, $projOutObj);
      $x = $poPoint->x;
      $y = $poPoint->y;
      // the extent to zoom to: that point
      // with a very tiny buffer
      $extent =
sprintf("%s+%s+%s+%s",$x-0.1,$y-0.1,$x+0.1,$y+0.1);

This method, as you can see on that last line, makes
for a 0.1-meter buffer around the point.
Realistically, your map's minscale will keep the zoom
from being that extreme. Or you can specify a larger
padding distance.




__________________________________
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.
http://promotions.yahoo.com/new_mail



More information about the mapserver-users mailing list