[postgis-users] Buffer on linestring

Paul Ramsey pramsey at refractions.net
Fri Jan 5 09:13:10 PST 2007


You have also fallen into the "buffer trap", which is the belief that 
you need to build an actual buffer in order to find all the objects 
"within a distance of" another object.

What you want is distance().

SELECT *
FROM streets_db_edges_big_3
WHERE
  the_geom && expand(setsrid(makeline(makepoint(-1.68445, 
8.10753),makepoint(4.8291,45.75936)),4326),1)
AND
  Distance(the_geom,setsrid(makeline(makepoint(-1.68445, 
8.10753),makepoint(4.8291,45.75936)),4326)) < 1

You also appear to have a mixed units problem, since you're in SRID=4326 
and doing a "1 unit" buffer, which implies a 1 DEGREE buffer, which is 
quite large. It's also not a planar unit, which means your results would 
map quite funny (covering more results the farther south you get).

Paul

Nicolas Ribot wrote:
>> Hello,
>>
>> I 've strange results with using buffer on linestring.
>>
>> When I tried to extract streets segments contains in the buffer, I've 
>> these
>> results:
>>
>> select  * FROM streets_db_edges_big_3    where
>> the_geom && buffer(setsrid(makeline('POINT(-1.68445 
>> 48.10753)','POINT(4.8291
>> 45.75936)'),4326),0.1,1)
>>
> 
>> 126599 records
>>
>>
>> If I did the thame thing with a Box3D with 0.1 degree more around my
>> reference points:
>>
>> select  * FROM streets_db_edges_big_3    where
>> setsrid('BOX3D(-1.78448 45.65923,4.92955 48.20667)'::BOX3D,4326)  &&
>> the_geom
>>
>> 127449 records
>>
>> I don't understand why the difference between the 2 results is so 
>> short. The
>> first query should return something like a corridor with less result. The
>> area of selection  should be more restrict than for the BoxD.
>>
>> If I look at the polygon extract with astext:
>>
>> select  astext(buffer(setsrid(makeline('POINT(-1.68445
>> 48.10753)','POINT(4.8291 45.75936)'),4326),0.1,1))
>>
>> result:
>> "POLYGON((4.86301403403245 45.8534335791583,4.92317357915826
>> 45.7254459659676,4.79518596596755 45.6652864208417,-1.71836403403245
>> 48.0134564208417,-1.71836403403245 48.0134564208417,-1.77852357915826
>> 48.1414440340324,-1.65053596596755 48.2016035791583,4.86301403403245
>> 45.8534335791583))"
>>
>>
>> area =1.4
>>
>> for the Box3D:
>> select astext(setsrid('BOX3D(-1.78448 45.65923,4.92955
>> 48.20667)'::BOX3D,4326))
>>
>> result:
>> "POLYGON((-1.78448 45.65923,-1.78448 48.20667,4.92955 48.20667,4.92955
>> 45.65923,-1.78448 45.65923))"
>>
>> area=17.1
>>
>>
> 
> Hi Eric,
> You are using the && operator to restrict your search. This operator
> only works on objects' bbox.
> So you are not searching for objects inside your corridor, but inside
> the corridor's bbox, which is much bigger.
> 
> Add an operator working on objects in your first query, something like:
> 
> select  *
> FROM streets_db_edges_big_3
> where
> the_geom && buffer(setsrid(makeline('POINT(-1.68445
> 48.10753)','POINT(4.8291 45.75936)'),4326),0.1,1)
> and intersects(the_geom, buffer(setsrid(makeline('POINT(-1.68445
> 48.10753)','POINT(4.8291 45.75936)'),4326),0.1,1))
> 
> Choose the right operator to find candidates (intersects, overlaps, etc.).
> 
> Nicolas
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users




More information about the postgis-users mailing list