MySQL and Grass

Robb Hill vortextube at
Wed Nov 10 21:05:54 EST 1999


I have a bunch (500k) of line segments(related to a 'polygon' table) and
around 70k points, both in a MySQL database.  I need to do a
point-in-polygon query. i.e. I want to know which polygons contain each
of the 70k points.  I decided to use MySQL because it is fast and
Postgres would not handle the size of polygons I have. (Among some other
apparently built-in limits of Postgres)

Anyway, I have been trying to do this query and it is eating my lunch. 
This is what I tried...

I have a polygon table that contains the name of the entity that has a
one to many relationship with the segment table.

So trying the "vertical line to infinity and count the intersections
approach" I figured I could query for the segments that bounded the x
coord of the point where the segment was "above" the point.  This gives
in SQL

"select count(*) from segment where segment.x <= x and segment.x >= x
where segment.y >=y group by segment.polygon_name"

I do get back the count of the "crossings" but I am not sure it is
correct.  My polygons are supposed to be distinct and I get multiple
polygons reporting to contain the point.

Can anyone offer advice?  Any good books on these types of algorithms or

I would love a lot of GIS related tools as Perl modules that connect to
MySQL, shapelib, and GRASS. But if I can't get this thing going I think
I will save my pennies for ArcInfo.

Thanks in advance.

More information about the grass-user mailing list