[postgis-users] extent of properties within a specified distance

User Map map.user at yahoo.com
Wed May 21 05:27:17 PDT 2008


hi there,
thanks for the immediate reply. i have tried what you have suggested, and its now taking no more longer time spans :) but i dont know how it is calculating the distance, because the extent returned by the query when used in the mapfile for mapserver with a scalebar, it is giving much larger area of about 800m in total, which should be about 100 m in actual as defined in the query.
i have this query
________________________________________________________________________
SELECT ST_Extent(geom) as ext, count (*),Max(Distance(geom,GeomFromText('POINT(530525.056494402 191742.597993273)',27700))) as max_dist
FROM tarea
WHERE ST_DWithin(geom,GeomFromText('POINT(530525.056494402 191742.597993273)',27700), 50)
__________________________________________________________________________
POINT(530525..056494402 191742.597993273) is got from AsText(Centroid(geom))
i have OSGB36 data, and srid= 27700, which i have set in the query. 
the extent returned is much larger. but the max_dist is returning 49.5, which is fine.
do you know why it is not matching the scalebar in the mapserver. does the mapserver scalebar works differently then the Distance query.
any help will be appriciated
regards


----- Original Message ----
From: "Obe, Regina" <robe.dnd at cityofboston.gov>
To: PostGIS Users Discussion <postgis-users at postgis.refractions.net>
Sent: Wednesday, May 21, 2008 11:38:57 AM
Subject: RE: [postgis-users] extent of properties within a specified distance


Have you tried using ST_DWithin(...)  ?
 
 
- even with Within (neither Distance nor Within use spatial indexes so you are essentially always doing a table scan.  You would still need an && for those to make them use indexes.  So try:
 
SELECT ST_Extent(geom) as ext, Max(ST_Distance(geom, '<center of polygon>')) as max_dist
FROM tarea
WHERE  ST_DWithin(geom,'<center of polygon>', 50);
 
If you are using an older version of Postgis that doesn't have the ST_ (e.g.. pre 1.3)
 
Do the following instead
 
 
 


________________________________
From: postgis-users-bounces at postgis.refractions.net [mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of User Map
Sent: Wednesday, May 21, 2008 5:19 AM
To: PostGIS Users Discussion
Subject: Re: [postgis-users] extent of properties within a specified distance


hi, 
thanks, but the problem is still there, the time Distance() query is taking. the concept behind using within() is only to minimize the number of time the distance function executes. it works ok without using within() also, but the time is still much longer. is there any way to minimize the time it is taking to perform distance(), or any other way to do the same task without using distance().
 
regards.


----- Original Message ----
From: Andy Anderson <aanderson at amherst.edu>
To: PostGIS Users Discussion <postgis-users at postgis.refractions.net>
Sent: Tuesday, May 20, 2008 10:09:27 PM
Subject: Re: [postgis-users] extent of properties within a specified distance


On May 19, 2008, at 5:01 AM, User Map wrote:
hi,
thanks for reply. i think i have to clarify my problem a bit more. i want to get the records from my table within a specified distance for e.g 50 meters. For this i have to calculate the extent first to get the image in mapserver. what i have is just a polygon geom, which area as you know can vary from property to property. i dont want to take into account the area/distance the property holds, but a center point for that polygon, so to calculate the distance equally on each side of that point, and then calculate the extent of those records, for the image to be generated. what i have done uptil now is:
SELECT extent(geom),max(Distance('<center of polygon>',geom))as distance
from tarea
where within(geom,'<expand(geom,50)from the given geom>')
and Distance('<center of polygon>',geom)<=50
but this query is taking about 25-26 mins which is quite a large time span. and also when i get the results and on showing through the map server, the scale bar is not matching, i mean it has to show a 100 meter bar scale, but, it is showing more then 100 meters on the scalebar, about 192 or so.

A couple of thoughts, upon which the more experienced may correct or elaborate:

1) It looks to me like you are performing a duplicate calculation. I'm not sure if Postgres is smart enough to avoid this by itself, but just in case you should take advantage of a subexpression to perform the calculation once for each geom:

SELECT extent(geom), distance from (SELECT geom, Distance('<center of polygon>', geom)) from tarea) as tdistance where distance <= 50.

2) Seems like

within(geom,'<expand(geom,50)from the given geom>')

is unnecessary, it will always be true. Or do you mean something different than the simpler form:

within(geom, expand(geom,50))

-- Andy


________________________________

The substance of this message, including any attachments, may be confidential, legally privileged and/or exempt from disclosure pursuant to Massachusetts law. It is intended solely for the addressee. If you received this in error, please contact the sender and delete the material from any computer. 
________________________________

Help make the earth a greener place. If at all possible resist printing this email and join us in saving paper. 
SELECT Extent(geom) as ext, Max(Distance(geom, '<center of polygon>')) as max_dist
FROM tarea
WHERE  geom && Expand('<center of polygon>',50)  AND Distance(geom, '<center of polygon>') < 50;
 
Hope that helps,
Regina



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20080521/dbe5df39/attachment.html>


More information about the postgis-users mailing list