[mapserver-dev] count points in polygon
Steve Lime
Steve.Lime at dnr.state.mn.us
Tue Jan 20 13:53:04 EST 2009
If you can't add spatial support you can still use your looping idea. Assuming you have
the point x,y in MySQL you can do a bounding box query against the points using the
bbox of each polygon (in MySQL). Then only do the "contains" test for those in that
result set (in MapScript).
Steve
>>> On 1/19/2009 at 10:24 PM, in message <497551E9.5010100 at swoodbridge.com>,
Stephen Woodbridge <woodbri at swoodbridge.com> wrote:
> 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