[postgis-commits] svn - r2847 - trunk/doc
postgis-commits at postgis.refractions.net
postgis-commits at postgis.refractions.net
Mon Jul 14 09:30:43 PDT 2008
Author: robe
Date: 2008-07-14 09:30:42 -0700 (Mon, 14 Jul 2008)
New Revision: 2847
Modified:
trunk/doc/reference.xml
Log:
Example use case of ST_DWithin
Modified: trunk/doc/reference.xml
===================================================================
--- trunk/doc/reference.xml 2008-07-14 11:40:41 UTC (rev 2846)
+++ trunk/doc/reference.xml 2008-07-14 16:30:42 UTC (rev 2847)
@@ -81,8 +81,21 @@
<listitem>
<para>Returns true if geometries are within the specified sriddistance
- of one another. sriddistance is in units defined by the spatial reference system.
+ of one another. sriddistance is in units defined by the spatial reference system and both
+ geometries must have the same SRID.
Uses indexes if available.</para>
+
+ <programlisting>
+--Find the nearest hospital to each school
+--that is within 3000 units of the school.
+-- We do an ST_DWithin search to utilize indexes to limit our search list
+-- that the non-indexable ST_Distance needs to process
+--If the units of the spatial reference is meters then units would be meters
+SELECT DISTINCT ON (s.gid) s.gid, s.school_name, s.the_geom, h.hospital_name
+ FROM schools s
+ LEFT JOIN hospitals h ON ST_DWithin(s.the_geom, h.the_geom, 3000)
+ ORDER BY s.gid, ST_Distance(s.the_geom, h.the_geom);
+ </programlisting>
</listitem>
</varlistentry>
More information about the postgis-commits
mailing list