[mapserver-dev] count points in polygon
Dan Little
danlittle at yahoo.com
Tue Jan 20 08:30:43 EST 2009
If you can add a Geometry column to your MySQL database you could at least use the st_contains operator to get a smaller list of points. MySQL implements this function as a bounding-box based query, but it would at least be faster than going through the entire dataset.
----- Original Message ----
> From: Stephen Woodbridge <woodbri at swoodbridge.com>
> To: Mathias Tobler <mtlist at gmx.net>
> Cc: mapserver-dev at lists.osgeo.org
> Sent: Monday, January 19, 2009 10:24:09 PM
> Subject: Re: [mapserver-dev] count points in polygon
>
> Mathias Tobler wrote:
> > For a system showing dynamic species distributino maps I am looking for a
> way to count the number of points in each polygon of a polygon layer. I am using
> MapScript to dynamically add the points from data stored in MySQL. The polygon
> layer is a regular shapefile that can either be a regular grid or a shapefile of
> countries or regions. Due to the larger application this will be part of I am
> limited to MySQL and won't be able to use PostGIS or any other spatial database.
> I could probably loop through all points and polygon in MapScript and use the
> $status = $polygon->contains($point); function, but considering that there can
> be 100'000 or more points this can get really slow. Is there any function that
> will do this?
>
> I think I would recommend that you add a column to your points table and then
> cycle through each point, determine what polygon it is in and update the column
> with the polygon's uid. Then you can do a query like:
>
> select polygon_uid, count(*) from points group by polygon_uid;
>
> -Steve W
> _______________________________________________
> mapserver-dev mailing list
> mapserver-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapserver-dev
More information about the mapserver-dev
mailing list