counting pixel values within polygons

Stephen Lime steve.lime at dnr.state.mn.us
Fri Jan 26 14:04:22 EST 2001


MapServer has a point-in-poly routine that was adapted from code in the
comp.graphics.algorithms news group/FAQ. The code is short and sweet.
I added a wrapper to account for islands and multiple parts. The source
is in mapseach.c. The algorithm considers only inside/outside and is
ambiguous on edges. Since we're not dealing with exact input it's not
an issue in processing queries from a web user. For more information:

http://www.ecse.rpi.edu/Homepages/wrf/geom/pnpoly.html

Steve

Stephen Lime
Internet Applications Analyst

Minnesota DNR
500 Lafayette Road
St. Paul, MN 55155
651-297-2937

>>> Michael Hearne <Michael.Hearne at noaa.gov> 01/26/01 12:27PM >>>
Mapserver users - We're in the midst of planning a project here dealing
with raster data analysis.

I wrote a quick (read: cheesy) C routine that counts the pixels in an
image that have the value X.  I can (and probably will) extend this to
be able to get some subset of that image and count the pixels in that
subset.  This all should be easy.  My users, however, would like to see
all of the pixels inside of a particular polygon (shapefile).  There is
an article on the web talking about various solutions to the
"point-in-a-polygon" problem - 

http://home.earthlink.net/~bobstein/inpoly/ 

and just stealing that code looks pretty easy.

What I am more uncertain about is the process of extracting all of the
nodes (is that the right word?) of a shapefile polygon and passing them
to one of these "point-in-a-polygon" routines.  Does the mapserver
source code include a routine that would make this simple, or is there
other stuff out there to simplify this process?

I have a fairly short amount of time that I'll be allowed to devote to
this process, so the easier the better.

Thanks!
-- 
Michael G. Hearne     	  	email: Michael.Hearne at noaa.gov  
Coastal Remote Sensing  		phone: 843 740-1281             
TPMC/NOAA Coastal Services Center	fax:   843 740-1312       
2234 S. Hobson Ave.,    Charleston, SC 29407




More information about the mapserver-users mailing list