[mapserver-users] Get a pixel's RGB by latlon?

Gregor Mosheh gregor at hostgis.com
Thu Feb 14 13:41:21 EST 2008


Fawcett, David wrote:
> Did you go with CGI or MapScript?  Care to share a snippet?

Still, here are all the steps in one place. Hopefully this will get 
archived and spidered, and the next Google user will have an easier time 
than I did! (though a missing - sign in my coords was the true culprit 
in many of my tribulations)

I used Mapserver's built-in CGI query mechanism, as it provides 
sufficient abstraction to automagically convert latlon and layer into a 
image file and pixel, even crossing tileindexes. That would've been 90% 
of the hard stuff, done already!

The mapfile does need a query template for the raster layer, as is 
documented:
LAYER
   NAME "avhrr"
   STATUS on
   TYPE raster
   DATA "AVHRR_SST/avhrr-today.tif"
   TEMPLATE "/maps/wms/pixel.template.html"
END

And pixel.template.html is simply this one word, the raw pixel value 
from whatever point was selected, from band 0.
[value_0]

The query was intended, as you can see, for a given latlon as opposed to 
a point-click and pixels within an image of known height. And since this 
was within PHP, I really did want to use 'localhost'

http://localhost/cgi-bin/mapserv?map=/maps/wms/sst.map&mode=query&layers=%s&mapxy=%f+%f

Now in PHP, I simply do file_get_contents($url) and I have the raw pixel 
value. In many cases, the pixel value is not the same as the desired 
data value but that conversion varies with your particular dataset.

-- 
Gregor Mosheh / Greg Allensworth, BS, A+
System Administrator
HostGIS cartographic development & hosting services
http://www.HostGIS.com/

"Remember that no one cares if you can back up,
  only if you can restore." - AMANDA


More information about the mapserver-users mailing list