[postgis-users] Distance in spherical reference system

Rico Hauke rico.hauke at gmail.com
Sat Nov 10 21:19:26 PST 2007


Hi list,

I am trying to write a SQL query that returns all features (rows) of
my feature table (ID, NAME, GEOMETRY) that are within a certain
distance (radius) of a given geometry.

The problem is that I am using a spherical reference system (EPSG
4326) and that I am not limited to Point geometries, which means I
can't use the distance_sphere() and distance_spheroid() functions.
Geometries that I am using are Point, Linestring and Polygon, so it
could be totally possible that I need to calculate the distance
between two polygons (in a spherical reference system, as mentioned
above).
I am pretty much desperate and wanted to ask if anyone has an idea how
I could do that?

Also, to make the SQL query more efficient, I wanted to use the &&
operator to make use of the GiST index and narrow the result set down
before applying the distance function. My basic idea was to calculate
the Bounding Box of the given geometry via Envelope(), expand the
calculated Bounding Box by the amount of the given radius (in meters)
and intersect (&&) it with the bounding boxes of the geometries in my
feature table (using the GiST index bounding boxes). The problem is
again that expand() doesn't really work well for spherical reference
systems (since it expands in degrees and not in meters).
Again, does anyone have an idea what I could do?

Thanks a lot!

Cheers,
Rico



More information about the postgis-users mailing list