Select only lines that touch both sides of polygon - PostGIS

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I want to select lines that only touch both sides of a polygon. Is there a function in postgis that can do this? See image below. I only want to select lines from the circle on the left where the line touches both sides of the polygon.



enter image description here










share|improve this question























  • Is it right to say that both the start point and the end point of the line must touch the outer ring of the polygon?
    – user30184
    4 hours ago










  • and the line must be otherwise totally inside the polygon?
    – Spacedman
    4 hours ago










  • so that ST_Split postgis.net/docs/ST_Split.html "split polygon by line" creates two polygons and "split line by polygon" does not split the line
    – user30184
    4 hours ago










  • ...and the larger of both possible great circle segments between start/end points does not intersect the interior?
    – ThingumaBob
    4 hours ago














up vote
2
down vote

favorite












I want to select lines that only touch both sides of a polygon. Is there a function in postgis that can do this? See image below. I only want to select lines from the circle on the left where the line touches both sides of the polygon.



enter image description here










share|improve this question























  • Is it right to say that both the start point and the end point of the line must touch the outer ring of the polygon?
    – user30184
    4 hours ago










  • and the line must be otherwise totally inside the polygon?
    – Spacedman
    4 hours ago










  • so that ST_Split postgis.net/docs/ST_Split.html "split polygon by line" creates two polygons and "split line by polygon" does not split the line
    – user30184
    4 hours ago










  • ...and the larger of both possible great circle segments between start/end points does not intersect the interior?
    – ThingumaBob
    4 hours ago












up vote
2
down vote

favorite









up vote
2
down vote

favorite











I want to select lines that only touch both sides of a polygon. Is there a function in postgis that can do this? See image below. I only want to select lines from the circle on the left where the line touches both sides of the polygon.



enter image description here










share|improve this question















I want to select lines that only touch both sides of a polygon. Is there a function in postgis that can do this? See image below. I only want to select lines from the circle on the left where the line touches both sides of the polygon.



enter image description here







postgis polygon select linestring






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 1 hour ago









Vince

14.2k32445




14.2k32445










asked 4 hours ago









user1655130

606




606











  • Is it right to say that both the start point and the end point of the line must touch the outer ring of the polygon?
    – user30184
    4 hours ago










  • and the line must be otherwise totally inside the polygon?
    – Spacedman
    4 hours ago










  • so that ST_Split postgis.net/docs/ST_Split.html "split polygon by line" creates two polygons and "split line by polygon" does not split the line
    – user30184
    4 hours ago










  • ...and the larger of both possible great circle segments between start/end points does not intersect the interior?
    – ThingumaBob
    4 hours ago
















  • Is it right to say that both the start point and the end point of the line must touch the outer ring of the polygon?
    – user30184
    4 hours ago










  • and the line must be otherwise totally inside the polygon?
    – Spacedman
    4 hours ago










  • so that ST_Split postgis.net/docs/ST_Split.html "split polygon by line" creates two polygons and "split line by polygon" does not split the line
    – user30184
    4 hours ago










  • ...and the larger of both possible great circle segments between start/end points does not intersect the interior?
    – ThingumaBob
    4 hours ago















Is it right to say that both the start point and the end point of the line must touch the outer ring of the polygon?
– user30184
4 hours ago




Is it right to say that both the start point and the end point of the line must touch the outer ring of the polygon?
– user30184
4 hours ago












and the line must be otherwise totally inside the polygon?
– Spacedman
4 hours ago




and the line must be otherwise totally inside the polygon?
– Spacedman
4 hours ago












so that ST_Split postgis.net/docs/ST_Split.html "split polygon by line" creates two polygons and "split line by polygon" does not split the line
– user30184
4 hours ago




so that ST_Split postgis.net/docs/ST_Split.html "split polygon by line" creates two polygons and "split line by polygon" does not split the line
– user30184
4 hours ago












...and the larger of both possible great circle segments between start/end points does not intersect the interior?
– ThingumaBob
4 hours ago




...and the larger of both possible great circle segments between start/end points does not intersect the interior?
– ThingumaBob
4 hours ago










1 Answer
1






active

oldest

votes

















up vote
3
down vote













I would say that to fit your description, the line should be :



  • Completely inside the polygon

  • Have its start and end points touching the boundary of the polygon




SELECT line_id, geom
FROM line a
JOIN polygon b ON ST_Within(a.geom,b.geom)
AND ST_Intersects(ST_StartPoint(a.geom),ST_Boundary(b.geom))
AND ST_Intersects(ST_EndPoint(a.geom),ST_Boundary(b.geom))





share|improve this answer


















  • 1




    The ST_Intersects relationship may not find all points which are "on" a line. Using ST_DWithin with a small tolerance will be more reliable.
    – Vince
    1 hour ago










  • I think, a combination of st_contains (postgis.net/docs/ST_Contains.html) and st_touches (postgis.net/docs/ST_Touches.html) will do the job
    – PieterB
    1 hour ago










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "79"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f299319%2fselect-only-lines-that-touch-both-sides-of-polygon-postgis%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote













I would say that to fit your description, the line should be :



  • Completely inside the polygon

  • Have its start and end points touching the boundary of the polygon




SELECT line_id, geom
FROM line a
JOIN polygon b ON ST_Within(a.geom,b.geom)
AND ST_Intersects(ST_StartPoint(a.geom),ST_Boundary(b.geom))
AND ST_Intersects(ST_EndPoint(a.geom),ST_Boundary(b.geom))





share|improve this answer


















  • 1




    The ST_Intersects relationship may not find all points which are "on" a line. Using ST_DWithin with a small tolerance will be more reliable.
    – Vince
    1 hour ago










  • I think, a combination of st_contains (postgis.net/docs/ST_Contains.html) and st_touches (postgis.net/docs/ST_Touches.html) will do the job
    – PieterB
    1 hour ago














up vote
3
down vote













I would say that to fit your description, the line should be :



  • Completely inside the polygon

  • Have its start and end points touching the boundary of the polygon




SELECT line_id, geom
FROM line a
JOIN polygon b ON ST_Within(a.geom,b.geom)
AND ST_Intersects(ST_StartPoint(a.geom),ST_Boundary(b.geom))
AND ST_Intersects(ST_EndPoint(a.geom),ST_Boundary(b.geom))





share|improve this answer


















  • 1




    The ST_Intersects relationship may not find all points which are "on" a line. Using ST_DWithin with a small tolerance will be more reliable.
    – Vince
    1 hour ago










  • I think, a combination of st_contains (postgis.net/docs/ST_Contains.html) and st_touches (postgis.net/docs/ST_Touches.html) will do the job
    – PieterB
    1 hour ago












up vote
3
down vote










up vote
3
down vote









I would say that to fit your description, the line should be :



  • Completely inside the polygon

  • Have its start and end points touching the boundary of the polygon




SELECT line_id, geom
FROM line a
JOIN polygon b ON ST_Within(a.geom,b.geom)
AND ST_Intersects(ST_StartPoint(a.geom),ST_Boundary(b.geom))
AND ST_Intersects(ST_EndPoint(a.geom),ST_Boundary(b.geom))





share|improve this answer














I would say that to fit your description, the line should be :



  • Completely inside the polygon

  • Have its start and end points touching the boundary of the polygon




SELECT line_id, geom
FROM line a
JOIN polygon b ON ST_Within(a.geom,b.geom)
AND ST_Intersects(ST_StartPoint(a.geom),ST_Boundary(b.geom))
AND ST_Intersects(ST_EndPoint(a.geom),ST_Boundary(b.geom))






share|improve this answer














share|improve this answer



share|improve this answer








edited 1 hour ago

























answered 4 hours ago









Busu

715




715







  • 1




    The ST_Intersects relationship may not find all points which are "on" a line. Using ST_DWithin with a small tolerance will be more reliable.
    – Vince
    1 hour ago










  • I think, a combination of st_contains (postgis.net/docs/ST_Contains.html) and st_touches (postgis.net/docs/ST_Touches.html) will do the job
    – PieterB
    1 hour ago












  • 1




    The ST_Intersects relationship may not find all points which are "on" a line. Using ST_DWithin with a small tolerance will be more reliable.
    – Vince
    1 hour ago










  • I think, a combination of st_contains (postgis.net/docs/ST_Contains.html) and st_touches (postgis.net/docs/ST_Touches.html) will do the job
    – PieterB
    1 hour ago







1




1




The ST_Intersects relationship may not find all points which are "on" a line. Using ST_DWithin with a small tolerance will be more reliable.
– Vince
1 hour ago




The ST_Intersects relationship may not find all points which are "on" a line. Using ST_DWithin with a small tolerance will be more reliable.
– Vince
1 hour ago












I think, a combination of st_contains (postgis.net/docs/ST_Contains.html) and st_touches (postgis.net/docs/ST_Touches.html) will do the job
– PieterB
1 hour ago




I think, a combination of st_contains (postgis.net/docs/ST_Contains.html) and st_touches (postgis.net/docs/ST_Touches.html) will do the job
– PieterB
1 hour ago

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f299319%2fselect-only-lines-that-touch-both-sides-of-polygon-postgis%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

What does second last employer means? [closed]

List of Gilmore Girls characters

Confectionery