[postgis-users] help with ST_DWithin query

Nicolas Ribot nicolas.ribot at gmail.com
Wed May 5 10:29:13 PDT 2010


> Hello,
>
>
>
> I have a table of parcels and the projection is epsg 102728
> (NAD_1983_StatePlane_Pennsylvania_North_FIPS_3701_Feet). I am trying to
> select certain parcels that are within 1 mile of the host parcel.  I select
> the centriod of the host parcels as follows:
>
>
>
> SELECT ST_AsText(ST_Centroid(the_geom)) FROM public.pa42089_parcels WHERE
> rpd_property_id = 123456;
>
>
>
> And with that centroid ( POINT(2611084.52017283 293875.803135596 ) I am
> doing the following:
>
>
>
> SELECT gid, pin, ST_AsGML(the_geom) FROM public.pa42089_parcels WHERE
> ST_DWithin(the_geom,ST_GeomFromText('POINT(2611084.52017283
> 293875.803135596)'),5280.0) AND property_type ='Building' AND sale_date >=
> '05/05/2001' AND ( acreage >= 0.75 AND acreage <= 1.25 )
>
> My results are not as expected, I am suspect of the centroid point as used
> in the ST_DWithing function (the wrong srid?) … the mapped results (in
> openlayers) from this query show a concentration parcels in another area
> (not around the host parcel).
>
>
>
> Any help would be greatly appreciated..
>

Hi,

Why do you extract the text representation of the point to use it in
the second query ? You could self-join the  table to use the initial
geometry:

SELECT p1.gid, p1.pin, ST_AsGML(p1.the_geom)
FROM public.pa42089_parcels p1, public.pa42089_parcels p2
WHERE
p2.rpd_property_id = 123456 AND
ST_DWithin(
	p1.the_geom,
	p2.the_geom,
	5280.0) AND
p1.property_type ='Building' AND
p1.sale_date >= '05/05/2001' AND
p1.acreage >= 0.75 AND
p1.acreage <= 1.25

If you use the text representation, you should set the srid in the
geomFromText function:
 ST_GeomFromText('POINT(2611084.52017283 293875.803135596)', 102728)

Nicolas



More information about the postgis-users mailing list