map coordinates' of a rectangle
Sandeep Bashyal
gis at UNDPHAIS.ORG.NP
Mon Nov 8 03:27:21 PST 2004
On Thu, 4 Nov 2004 16:20:28 +0200, temiz <temiz at DEPREM.GOV.TR> wrote:
> hello
>
> my trials yield no correct result.
> I have image coordinates of a rectangle (rubber band).
> how can I get map coordinates' of this rectangle in the form of
> minx,miny,maxx,maxy?
>
> kind regards
>
> Ahmet Temiz
>
> ______________________________________
> Inflex - installed on mailserver for domain @deprem.gov.tr
> Queries to: postmaster at deprem.gov.tr
>
> ______________________________________
> The views and opinions expressed in this e-mail message are the sender's
> own
> and do not necessarily represent the views and the opinions of
> Earthquake Research Dept.
> of General Directorate of Disaster Affairs.
>
> Bu e-postadaki fikir ve gorusler gonderenin sahsina ait olup, yasal
> olarak T.C.
> B.I.B. Afet Isleri Gn.Mud. Deprem Arastirma Dairesi'ni baglayici
> nitelikte degildir.
>
I'm assuming that you want the coordinates of the rubberband in geographic
coordinates...
Here's what I do:
(from the wiki)
/**
* converts pixel units into map units
*
* @param int $click_x coordinate X in pixels
* @param int $click_y coordinate Y in pixels
* @param array $current_extent holds the current extent of the map (XMin,
YMin, XMax, YMax)
* @global map object
* @return array [0]=> X in map units; [1]=> Y in map units
*/
function click2map ($click_x, $click_y, $current_extent) {
global $map;
$x_pct = ($click_x / $map->width);
$y_pct = 1 - ($click_y / $map->height);
$x_map = $current_extent[0] + ( ($current_extent[2] - $current_extent[0])
* $x_pct);
$y_map = $current_extent[1] + ( ($current_extent[3] - $current_extent[1])
* $y_pct);
return array($x_map, $y_map);
}
//convert clicked points into geographic coordinates
$query_rect_min_xy =
click2map($_POST['mapa_x']-$_POST['w'],$_POST['mapa_y'],$current_extent);
$query_rect_max_xy =
click2map($_POST['mapa_x'],$_POST['mapa_y']-$_POST['h'],$current_extent);
where mapa_x and mapa_y are the coordinates of the clicked point; and h
and w are the height and width of the rubberband zoom box.
$query_rect = ms_newRectObj();
$query_rect->setextent($query_rect_min_xy[0],$query_rect_min_xy[1],$query_rect_max_xy[0],$query_rect_max_xy[1]);
..and so on
--
Sandeep Bashyal
--
National GIS Officer
Humanitarian Assistance Information System (HAIS)
United Nations (NEP/01/008)
UN House, Pulchowk
G.P.O. Box 107
Kathmandu, Nepal
Tel: (+977) 01 5543957
(+977) 01 5554304
Cell:(+977) 9841270854
Fax: (+977) 01 5528059
--------------------------------------------------
mailto:gis at undphais.org.np
mailto:sandeep at earthmapping.com
http://www.undp.org.np
More information about the MapServer-users
mailing list