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

Matt Doggett mdoggett at coas.oregonstate.edu
Thu Apr 3 15:46:32 EST 2003


Thanks Antti!  Your click2map worked perfectly. I knew there was a
simple solution.  I did look at the Gmap version, but yours is much
easier to follow, understand, and customize for my specific application.

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
 

> -----Original Message-----
> From: Antti.Roppola at brs.gov.au [mailto:Antti.Roppola at brs.gov.au]
> Sent: Wednesday, April 02, 2003 8:31 PM
> To: mdoggett at coas.oregonstate.edu; mapserver-users at lists.gis.umn.edu
> Subject: RE: [Mapserver-users] convert pixel to world (georeferenced)
> coordinates
> 
> 
> 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




More information about the mapserver-users mailing list