Skip to content
Advertisement

How to get the intersection length of touching geometries with ST_Touches

I am trying to develop a query in Postgis, where it can solve this problem:

I have a geometry and I wanna know which of the polygons that touches it, there is the highest contact area of this geometry. After I recognize this polygon I will take its value in a specific column and put this value in the same column but in my geometry.

Someone know how can I do that? I am a new user in postgresql/postgis.

Advertisement

Answer

As pointed out by @JGH in the comments, the overlapping area will be zero if you use ST_Touches alone. What you can do is to filter out only the geometries that do touch your reference geometry and then use ST_Intersection to get the intersection area, so that you can finally calculate the length of the intersection with ST_Length.

Data Sample

enter image description here

The geometry values depicted above are inside the CTE:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement