map coordinates
Pietro Giannini
pgiannini at BYTEWISE.IT
Tue Jan 23 09:01:51 PST 2007
Hi Ben,
Finally I found time to think about this problem: how to
store the geographic coordinates of a mouse clik on the map image, and
thank to you I found a solution; I'm happy to share it.
I use
the php-mapscript '$map->cellsize' property to get the delta of a pixel
in projected coordinates, both in x and y.
A piece of code:
/* $_REQUEST['mapimg_x'] and $_REQUEST['mapimg_y'] are the coordinates in pixel of the
<INPUT TYPE=IMAGE> of a form on my page that contains the image of
the map.
I multiply the X & Y for the $oMap->cellsize to obtain
the projected coordinates relatively to the current extent
of the image, and I sum the result to the $oMap->extent->minx, for the
X, and substract to $oMap->extent->miny for the Y,
to obtain the absolute coordinates. */
$newPoint =
ms_newpointobj();
$newPoint->setXY(($oMap->extent->minx +
($oMap->cellsize*$_REQUEST['mapimg_x'])),($oMap->extent->maxy -
($oMap->cellsize * $_REQUEST['mapimg_y'])));
/* I get two new
Projection objects, first is a lat/lon projection and second is projection
of the map. */
$olatlonProj =
ms_newprojectionobj("proj=latlong,ellps=WGS84");
$osProj =
$oMap->getProjection();
$omapProj = ms_newprojectionobj($osProj);
/* I project the point from the map
projection to the lat/lon projection */
$newPoint->project($omapProj,$olatlonProj);
/* now I can store the point
(in this case in a mysql db) */
$myconn =
mysql_connect("host","usr","pw");
mysql_select_db("db");
$sql = "INSERT INTO clickpoints (lon,lat) VALUES
(".$newPoint->x.",".$newPoint->y.")";
$res = mysql_query($sql);
mysql_close($myconn);
Limitedly to the accuracy due of the scale of the map,
result is good. I tried in lat/lon projection and also in Mercator,
Mollweide, Sanson-flamsteed, UTM, orthographic, geostationary satellite
... !
cheers
...............................pg
--
Pietro Giannini
Bytewise srl - Area GIS
41°50'38.58"N 12°29'13.39"E
On
Gio, 14 Dicembre 2006 7:18 am, Ben Madin wrote:
> Pietro,
>
> I noticed your question re map coordinates vs pixels.
There may be a
> better way, but I compare the proportion of the
pixels with the
> proportion of the map extents, for each of X
& Y / Long & Lat /
> Easting & Northing or
whatever.
>
> So,
>
> if the pixels is
400,200 (when the map is 600 x 300 pixels), then we
> are 400/600
of the way from the minimum extent to the maximum extent
> on the
map (in this case in both directions).
>
> I'm sure
someone else will be more articulate about this, or have a
>
better idea, which I will be happy to see.
>
> Actually,
here is a really good resource: (don't forget to have a
> look on
the mapserver website first!)
>
>
http://mapserver.gis.umn.edu/docs/howto/phpmapscript-byexample
>
> cheers
>
> Ben
>
>
>
--
>
> Ben Madin
> REMOTE INFORMATION
>
> t : +61 8 9192 5455
> f : +61 8 9192 5535
> m :
0448 887 220
> Broome WA 6725
>
>
ben at remoteinformation.com.au
>
>
>
>
>
> Out here, it pays to know...
>
>
>
>
>
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20070123/cb269915/attachment.htm>
More information about the MapServer-users
mailing list