[Mapserver-users] convert pixel to world (georeferenced) coordinates

Steve Lime steve.lime at dnr.state.mn.us
Fri Apr 4 11:56:30 EST 2003


If not done already, this snippet should be added to the WIKI...

Steve

>>> <Antti.Roppola at brs.gov.au> 04/02/03 10:31PM >>>

Here's a little one that I wrote for PHP/Mapscript:

	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);
	}

GMap has a much fancier one, but I have got by OK.

current_extent is an array of current XMin, YMin, XMax, YMax.

Cheers,

Antti



-----Original Message-----
From: Matt Doggett [mailto:mdoggett at coas.oregonstate.edu] 
Sent: Thursday, 3 April 2003 11:08 AM
To: mapserver-users at lists.gis.umn.edu 
Subject: [Mapserver-users] convert pixel to world (georeferenced)
coordinates


I noticed that most mapscript functions require x,y in georeferenced
coordinates.  However, I also noticed there are NO functions that will
translate the img_x,img_y (pixel) coordinates that the user clicked on
the image into georeferenced coordinates.  Can  anyone provide
pointers
on how this translation can be done?

Thanks,

Matt

Matt Doggett
Spatial Climate Analysis Service
Oregon State University
316 Strand Ag Hall
Corvallis, OR 97331
(541)737-9153
mdoggett at coas.oregonstate.edu 
 


_______________________________________________
Mapserver-users mailing list
Mapserver-users at lists.gis.umn.edu 
http://lists.gis.umn.edu/mailman/listinfo/mapserver-users 

_______________________________________________
Mapserver-users mailing list
Mapserver-users at lists.gis.umn.edu 
http://lists.gis.umn.edu/mailman/listinfo/mapserver-users



More information about the mapserver-users mailing list