[postgis-users] Line within range of another line?

Regina Obe lr at pcorp.us
Sun Oct 30 00:55:36 PDT 2016


Use ST_DWithin  (works for both geography and geometry) and any kind of geometry, not just lines .  

My example is for geography since units are always in meters.  For geometry units you have to specify based on your spatial_ref_sys and geometries have to have same spatial ref sys

 

something like below will return all roads that are within 100 meters of a fault line

 

SELECT l.gid, l.geog

FROM roads As l

WHERE EXISTS (SELECT 1 FROM fault_lines As fl WHERE ST_DWithin(fl.geog, l.geog, 100) );

 

If you need to know the exact fault lines, do a JOIN instead – keep in mind if a road is close enough to more than one fault line, it will be duplicated

 

SELECT l.gid, l.geog, fl.name, ST_Distance(l.geog, fl.geog) AS dist

FROM roads AS l INNER JOIN fault_lines AS fl ON (ST_DWithin(fl.geog, l.geog, 100) );

 

 

 

If you want jus the closes fault line within 100 meters use DISTINCT ON

 

SELECT DISTINCT ON(l.gid)  l.gid, l.geog, fl.name, ST_Distance(l.geog, fl.geog) AS dist

FROM roads AS l INNER JOIN fault_lines AS fl ON (ST_DWithin(fl.geog, l.geog, 100) )

ORDER BY l.gid, dist;

 

 

 

Hope that helps,

Regina

http://www.postgis.us

http://www.paragoncorporation.com

 

http://postgis.net

 

 

From: postgis-users [mailto:postgis-users-bounces at lists.osgeo.org] On Behalf Of Ahmet Temiz
Sent: Sunday, October 30, 2016 2:59 AM
To: PostGIS Users Discussion <postgis-users at lists.osgeo.org>; PostGIS Users Discussion <postgis-users at postgis.refractions.net>
Subject: [postgis-users] Line within range of another line?

 

Hi,

How can I find Line within range of another line?

I mean I try to find line section within certain range of another line.

For example, road lines close to fault lines.

 

Ps : I know that using st_buffer causes performance issue.

Can you give any advice?

 

Regards

 



-- 

Ahmet Temiz
Jeoloji Müh.
Afet ve Acil Durum Yönetimi Başkanlığı
Bilgi İşlem  Dairesi Başkanlığı-CBS Grubu


________________________

Ahmet Temiz
Geological Eng.
Information Systems - GIS Group
Disaster and Emergency Management
of Presidency

 

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


More information about the postgis-users mailing list