2

I want to segmentate a country (denmmark) by using barriers such as larger roads, railroads and the border/ coastline as the delimiting lines of the polygonise function in QGIS. But as most roads and railroads ends well before hitting the coastline I get some very long polygons along the coast. A very long polygon along the coast

I would like to split these long polygons when using the polygonise function by extending road segments close to the border out to the coast. But I only want to select start and end nodes of segments that don't share more than one start and end node with the road network. I've written some SQL for PostGIS that is supposed to solve the problem by utilising that the segments share geometry in the start and end nodes, unless they fulfill my requirements:

create table snaplines3 as
select st_makeline(st_endpoint(a.geom),st_closestpoint(b.geom,st_endpoint(a.geom)))
from vej_jernbane_multi_to_single a,dk_graense b
where st_dwithin(st_endpoint(a.geom),b.geom,50)
and st_touches(a.geom,b.geom) is false
and st_asbinary(st_endpoint(a.geom))!=st_asbinary(st_startpoint(a.geom))
union
select st_makeline(st_startpoint(a.geom),st_closestpoint(b.geom,st_startpoint(a.geom)))
from vej_jernbane_multi_to_single a,dk_graense b
where st_dwithin(st_startpoint(a.geom),b.geom,50)
and st_touches(a.geom,b.geom) is false
and st_asbinary(st_endpoint(a.geom))!=st_asbinary(st_startpoint(a.geom)) 

Unfurtunately my code doesn't work as the part st_asbinary(st_endpoint(a.geom))!=st_asbinary(st_startpoint(a.geom)) doesn't seem to do anything. Two new lines that I don't want and one that is correct

Does anybody have an idea as to why it doesn't work and alternatively another solution.

  • I'm now thinking that I'm always comparing the same row.geometry in my where statement, so that startpoint and endpoint is of course never the same. Still not sure how to solve my problem though. – JonasPedersen Oct 22 '15 at 9:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.