views:

46

answers:

2

Suppose you are given an image of the earth's surface and that it is stored in the database as a polygon defined by the latitude/longitude pairs of its corners.

Now suppose there are millions of images covering the earth's surface that are also stored similarly. What is a good strategy to find those images which intersect with your given image?

I have a working basic algorithm that is based on the "bounding radius" of the images. But it is not optimal and finds more images than ought to be returned.

I have looked at the GIS spacial functions of MySQL but all of the calculations in that appear to be done in Euclidean geometry.

Essentially, I just need a function that returns "true" or "false" depending on if two polygons (on the sphere and defined by lat/long points) intersect. Seems simple but I have not found an implementation yet. And the thought of figuring this out myself is tiring.

+1  A: 

I personally use PostGIS and GEOS (via geodjango) to solve this problem.

Seth
Do they natively handle spherical coordinates? PostGIS is, for the moment, out because I am already using MySQL. geodjandro's poly.intersects(pnt) might be doing what I need. I'm still not sure if it does true lat/long calculations or if it is linear. I'm reading the docs now. Thanks.
Dr. Person Person II
Seth
If you are going to do spatial operations then you really should ditch MySQL. Most of their spatial functions are not implemented, just stubbed out. PostGIS just recently added support for geoid calculations rather than a projection.
TheSteve0
I'm been reading documentation for about a two hours now. I have not found any mention of non-Euclidean coordinates systems yet. From what I gather GEOS is just a C implementation of JTS Topology Suite. There are several other projects that port the JTS Topology Suite. Nothing in the documentation for JTS Topology Suite mentions anything about projections, WGS84, or coordinate systems. All the topology appears to be occurring in 2-D Euclidean space. Maybe I'm not seeing the forest through the trees, but I do not see any spherical geometry at all in these packages.
Dr. Person Person II
I'm now investigating PostGIS. It seems to do WGS84 for latitude/longitude data.
Dr. Person Person II
+2  A: 

Using PostGIS, you could run something like:

SELECT b.* 
FROM images AS a
 JOIN images AS b
 ON ST_Intersects(a.the_geom,b.the_geom)
WHERE a.name = "The image you are interested in"

This assumes that all image boundaries are contained in the same PostGIS table "images".

underdark
This appears like it may be what I was asking for. The documentation page here (http://postgis.refractions.net/docs/ST_Intersects.html) says that it works on the sphere for a geography object. I am actually interested in the spherical case more than the ellipsoidal case so that's a plus. I've found surprisingly few APIs in *any* language that handle this seemingly simple question. I will wait a good while and if no further answers are given, you will eventually get a green check.
Dr. Person Person II