Select only lines that touch both sides of polygon - PostGIS
Clash 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.
postgis polygon select linestring
add a comment |Â
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.
postgis polygon select linestring
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
add a comment |Â
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.
postgis polygon select linestring
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.
postgis polygon select linestring
postgis polygon select linestring
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
add a comment |Â
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
add a comment |Â
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))
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
add a comment |Â
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))
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
add a comment |Â
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))
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
add a comment |Â
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))
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))
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
add a comment |Â
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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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