[postgis-users] Finding records withing XX distance from a geometry in the same table

Alexander W. Rolek a.rolek at gmail.com
Tue Jul 8 20:36:14 PDT 2014


I'm trying to query all the records within XX distance from a geometry. I
would like to be able to reference the subject geometry via it's id, and
then find every geometry that is either:

A) within XX distance from a x/y coordinate of the geometry
B) within XX distance from the edge of the geometry on all sides. (ideal)

What is the best way to accomplish this? My current query:

SELECT *
FROM sdgis.parcels4326 AS parcels
WHERE ST_Distance_Sphere(
parcels.geom,

ST_Transform(ST_SetSRID(ST_MakePoint('6255896.314288','1898596.929109'),2230),4326)
) < 100.0;

This takes a few minutes to run on a table with just over 1 million
records. I would like to swap out the ST_MakePoint, with a multipolygon
from a record that is looked up via it's id.

Any suggestions are greatly appreciated.

-- 
Alexander W. Rolek
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20140708/5a8433ee/attachment.html>


More information about the postgis-users mailing list