Is there a way to clip a layer with a shape from another layer in `sf`? The 2019 Stack Overflow Developer Survey Results Are InHow to clip a lines vector layer to a polygon layer in QGIS?Clipping a raster with a shape layer fails by returning an empty raster (nan - 0)Why is ArcMap not clipping to Polygon?Troubleshoot with “Split selected features with selected line from another layer”Clip shapefile with shapefileRemoving points which fall outside of selected polygons using QGIS?Clip tool output does not follow the shape of the output extent and raster values are simplifiedClip rasters and vectors simultaneously in QGIS 2.18clip and/or intersect tools giving me the wrong results in qgis 2.18.16Cannot clip a raster excluding dataset
"What time...?" or "At what time...?" - what is more grammatically correct?
Geography at the pixel level
Realistic Alternatives to Dust: What Else Could Feed a Plankton Bloom?
How to deal with fear of taking dependencies
"Riffle" two strings
It's possible to achieve negative score?
The difference between dialogue marks
How was Skylab's orbit inclination chosen?
Is bread bad for ducks?
Why do UK politicians seemingly ignore opinion polls on Brexit?
Extreme, unacceptable situation and I can't attend work tomorrow morning
What could be the right powersource for 15 seconds lifespan disposable giant chainsaw?
How to answer pointed "are you quitting" questioning when I don't want them to suspect
What does "sndry explns" mean in one of the Hitchhiker's guide books?
How to change the limits of integration
Limit the amount of RAM Mathematica may access?
Can distinct morphisms between curves induce the same morphism on singular cohomology?
"To split hairs" vs "To be pedantic"
Why could you hear an Amstrad CPC working?
Spanish for "widget"
On the insanity of kings as an argument against Monarchy
Are USB sockets on wall outlets live all the time, even when the switch is off?
Where does the "burst of radiance" from Holy Weapon originate?
Is flight data recorder erased after every flight?
Is there a way to clip a layer with a shape from another layer in `sf`?
The 2019 Stack Overflow Developer Survey Results Are InHow to clip a lines vector layer to a polygon layer in QGIS?Clipping a raster with a shape layer fails by returning an empty raster (nan - 0)Why is ArcMap not clipping to Polygon?Troubleshoot with “Split selected features with selected line from another layer”Clip shapefile with shapefileRemoving points which fall outside of selected polygons using QGIS?Clip tool output does not follow the shape of the output extent and raster values are simplifiedClip rasters and vectors simultaneously in QGIS 2.18clip and/or intersect tools giving me the wrong results in qgis 2.18.16Cannot clip a raster excluding dataset
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I would like to get the greens polygons that intersects (or overlapsed) the red outlined polygon (see image below).
I tried sf::st_intersection()
but the polygon in yellow (yes that just one polygon) was not taken in account.
In QGIS, the clip (cut) tool did exactly what I wanted. Is there a tool similar in R to cut a layer using another layer ?
Tried to use sf::st_overlaps()
but the returned matrix was biggest than my feature table. sf::st_crops()
does not fit either as I want to cut in a specific shape.
r clip sf
|
show 1 more comment
I would like to get the greens polygons that intersects (or overlapsed) the red outlined polygon (see image below).
I tried sf::st_intersection()
but the polygon in yellow (yes that just one polygon) was not taken in account.
In QGIS, the clip (cut) tool did exactly what I wanted. Is there a tool similar in R to cut a layer using another layer ?
Tried to use sf::st_overlaps()
but the returned matrix was biggest than my feature table. sf::st_crops()
does not fit either as I want to cut in a specific shape.
r clip sf
2
The yellow polygon doesn't "fit into" the red outline. It intersects or overlaps it. "Fit into" to me means "is fully inside". These are very complex looking polygons and its possible some validity constraint isn't valid and we can't tell that without your data....
– Spacedman
Apr 4 at 19:41
Thanks for your comments. I'm well aware that the yellow polygon does not fit into I want either selected it (by an intersection) or get the part inside the red outlined polygon (by cutting it). Actuallysf::st_intersects()
miss the yellow polygon (and so does QGIS geoprocessing tool). I'm not a native english speaker so I might have misused the word "fit". Actually, I started by an intersection by habit, and because I didn't thought there will be big polygons like this one, but cutting is more what I need for this use case. So my question is still valid.
– Nicolas Roelandt
Apr 5 at 7:25
I edited my question to remove the misused word.
– Nicolas Roelandt
Apr 5 at 7:27
I'm surprised thatsf::st_intersection()
is not working: geocompr.robinlovelace.net/figures/venn-clip-1.png Do you need to clip the green subsection within the red outline, or both the yellow and the green together? Would performing ast_union()
before clipping work for you?
– spacedSparking
Apr 5 at 8:11
@spacedSparking, I'm surprised too. I checked the validity of the polygons and all are valids. Actually the green and the yellow are in the same layer, I just highlighted the problematic polygon.
– Nicolas Roelandt
Apr 5 at 8:53
|
show 1 more comment
I would like to get the greens polygons that intersects (or overlapsed) the red outlined polygon (see image below).
I tried sf::st_intersection()
but the polygon in yellow (yes that just one polygon) was not taken in account.
In QGIS, the clip (cut) tool did exactly what I wanted. Is there a tool similar in R to cut a layer using another layer ?
Tried to use sf::st_overlaps()
but the returned matrix was biggest than my feature table. sf::st_crops()
does not fit either as I want to cut in a specific shape.
r clip sf
I would like to get the greens polygons that intersects (or overlapsed) the red outlined polygon (see image below).
I tried sf::st_intersection()
but the polygon in yellow (yes that just one polygon) was not taken in account.
In QGIS, the clip (cut) tool did exactly what I wanted. Is there a tool similar in R to cut a layer using another layer ?
Tried to use sf::st_overlaps()
but the returned matrix was biggest than my feature table. sf::st_crops()
does not fit either as I want to cut in a specific shape.
r clip sf
r clip sf
edited Apr 5 at 7:47
Simbamangu
11.1k34680
11.1k34680
asked Apr 4 at 15:22
Nicolas RoelandtNicolas Roelandt
186
186
2
The yellow polygon doesn't "fit into" the red outline. It intersects or overlaps it. "Fit into" to me means "is fully inside". These are very complex looking polygons and its possible some validity constraint isn't valid and we can't tell that without your data....
– Spacedman
Apr 4 at 19:41
Thanks for your comments. I'm well aware that the yellow polygon does not fit into I want either selected it (by an intersection) or get the part inside the red outlined polygon (by cutting it). Actuallysf::st_intersects()
miss the yellow polygon (and so does QGIS geoprocessing tool). I'm not a native english speaker so I might have misused the word "fit". Actually, I started by an intersection by habit, and because I didn't thought there will be big polygons like this one, but cutting is more what I need for this use case. So my question is still valid.
– Nicolas Roelandt
Apr 5 at 7:25
I edited my question to remove the misused word.
– Nicolas Roelandt
Apr 5 at 7:27
I'm surprised thatsf::st_intersection()
is not working: geocompr.robinlovelace.net/figures/venn-clip-1.png Do you need to clip the green subsection within the red outline, or both the yellow and the green together? Would performing ast_union()
before clipping work for you?
– spacedSparking
Apr 5 at 8:11
@spacedSparking, I'm surprised too. I checked the validity of the polygons and all are valids. Actually the green and the yellow are in the same layer, I just highlighted the problematic polygon.
– Nicolas Roelandt
Apr 5 at 8:53
|
show 1 more comment
2
The yellow polygon doesn't "fit into" the red outline. It intersects or overlaps it. "Fit into" to me means "is fully inside". These are very complex looking polygons and its possible some validity constraint isn't valid and we can't tell that without your data....
– Spacedman
Apr 4 at 19:41
Thanks for your comments. I'm well aware that the yellow polygon does not fit into I want either selected it (by an intersection) or get the part inside the red outlined polygon (by cutting it). Actuallysf::st_intersects()
miss the yellow polygon (and so does QGIS geoprocessing tool). I'm not a native english speaker so I might have misused the word "fit". Actually, I started by an intersection by habit, and because I didn't thought there will be big polygons like this one, but cutting is more what I need for this use case. So my question is still valid.
– Nicolas Roelandt
Apr 5 at 7:25
I edited my question to remove the misused word.
– Nicolas Roelandt
Apr 5 at 7:27
I'm surprised thatsf::st_intersection()
is not working: geocompr.robinlovelace.net/figures/venn-clip-1.png Do you need to clip the green subsection within the red outline, or both the yellow and the green together? Would performing ast_union()
before clipping work for you?
– spacedSparking
Apr 5 at 8:11
@spacedSparking, I'm surprised too. I checked the validity of the polygons and all are valids. Actually the green and the yellow are in the same layer, I just highlighted the problematic polygon.
– Nicolas Roelandt
Apr 5 at 8:53
2
2
The yellow polygon doesn't "fit into" the red outline. It intersects or overlaps it. "Fit into" to me means "is fully inside". These are very complex looking polygons and its possible some validity constraint isn't valid and we can't tell that without your data....
– Spacedman
Apr 4 at 19:41
The yellow polygon doesn't "fit into" the red outline. It intersects or overlaps it. "Fit into" to me means "is fully inside". These are very complex looking polygons and its possible some validity constraint isn't valid and we can't tell that without your data....
– Spacedman
Apr 4 at 19:41
Thanks for your comments. I'm well aware that the yellow polygon does not fit into I want either selected it (by an intersection) or get the part inside the red outlined polygon (by cutting it). Actually
sf::st_intersects()
miss the yellow polygon (and so does QGIS geoprocessing tool). I'm not a native english speaker so I might have misused the word "fit". Actually, I started by an intersection by habit, and because I didn't thought there will be big polygons like this one, but cutting is more what I need for this use case. So my question is still valid.– Nicolas Roelandt
Apr 5 at 7:25
Thanks for your comments. I'm well aware that the yellow polygon does not fit into I want either selected it (by an intersection) or get the part inside the red outlined polygon (by cutting it). Actually
sf::st_intersects()
miss the yellow polygon (and so does QGIS geoprocessing tool). I'm not a native english speaker so I might have misused the word "fit". Actually, I started by an intersection by habit, and because I didn't thought there will be big polygons like this one, but cutting is more what I need for this use case. So my question is still valid.– Nicolas Roelandt
Apr 5 at 7:25
I edited my question to remove the misused word.
– Nicolas Roelandt
Apr 5 at 7:27
I edited my question to remove the misused word.
– Nicolas Roelandt
Apr 5 at 7:27
I'm surprised that
sf::st_intersection()
is not working: geocompr.robinlovelace.net/figures/venn-clip-1.png Do you need to clip the green subsection within the red outline, or both the yellow and the green together? Would performing a st_union()
before clipping work for you?– spacedSparking
Apr 5 at 8:11
I'm surprised that
sf::st_intersection()
is not working: geocompr.robinlovelace.net/figures/venn-clip-1.png Do you need to clip the green subsection within the red outline, or both the yellow and the green together? Would performing a st_union()
before clipping work for you?– spacedSparking
Apr 5 at 8:11
@spacedSparking, I'm surprised too. I checked the validity of the polygons and all are valids. Actually the green and the yellow are in the same layer, I just highlighted the problematic polygon.
– Nicolas Roelandt
Apr 5 at 8:53
@spacedSparking, I'm surprised too. I checked the validity of the polygons and all are valids. Actually the green and the yellow are in the same layer, I just highlighted the problematic polygon.
– Nicolas Roelandt
Apr 5 at 8:53
|
show 1 more comment
2 Answers
2
active
oldest
votes
sf::st_intersection()
will work with the last version of sf
(0.7-3). I don't know why it was not working in the previous version.
New contributor
I had sf 0.7.2; upgraded to sf 0.7.3 and the issue withsf::st_intersect()
was resolved. Not sign in the changelog that the algorithm was changed, maybe the new grob operator ? ¯_(ツ)_/¯ Thanks @rcarto
– Nicolas Roelandt
Apr 5 at 14:05
Final result is visible here. so No need for a clip function.
– Nicolas Roelandt
Apr 5 at 14:10
add a comment |
There is now a sf::st_crop
function available but, you may need the development github version of sf. You can download the development version using the devtools/remotes
package(s).
install.packages("devtools")
remotes::install_github("r-spatial/sf")
For specific irregular geometries, the raster::intersect
function can clip data, and retain attributes, using the rgeos
package. I believe that the package can handle sf class objects but, if not, you can coerce to sp using as(x, "Spatial")
.
Thanks for your comments. As I said,sf::st_crop()
does not respond to my need as it takes a bounding box (so 4 coordinates). I want to cut with another (irregular) shape from another layer. I'll look intoraster::intersect
– Nicolas Roelandt
Apr 5 at 7:32
add a comment |
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',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f317804%2fis-there-a-way-to-clip-a-layer-with-a-shape-from-another-layer-in-sf%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
sf::st_intersection()
will work with the last version of sf
(0.7-3). I don't know why it was not working in the previous version.
New contributor
I had sf 0.7.2; upgraded to sf 0.7.3 and the issue withsf::st_intersect()
was resolved. Not sign in the changelog that the algorithm was changed, maybe the new grob operator ? ¯_(ツ)_/¯ Thanks @rcarto
– Nicolas Roelandt
Apr 5 at 14:05
Final result is visible here. so No need for a clip function.
– Nicolas Roelandt
Apr 5 at 14:10
add a comment |
sf::st_intersection()
will work with the last version of sf
(0.7-3). I don't know why it was not working in the previous version.
New contributor
I had sf 0.7.2; upgraded to sf 0.7.3 and the issue withsf::st_intersect()
was resolved. Not sign in the changelog that the algorithm was changed, maybe the new grob operator ? ¯_(ツ)_/¯ Thanks @rcarto
– Nicolas Roelandt
Apr 5 at 14:05
Final result is visible here. so No need for a clip function.
– Nicolas Roelandt
Apr 5 at 14:10
add a comment |
sf::st_intersection()
will work with the last version of sf
(0.7-3). I don't know why it was not working in the previous version.
New contributor
sf::st_intersection()
will work with the last version of sf
(0.7-3). I don't know why it was not working in the previous version.
New contributor
New contributor
answered Apr 5 at 13:19
rcartorcarto
361
361
New contributor
New contributor
I had sf 0.7.2; upgraded to sf 0.7.3 and the issue withsf::st_intersect()
was resolved. Not sign in the changelog that the algorithm was changed, maybe the new grob operator ? ¯_(ツ)_/¯ Thanks @rcarto
– Nicolas Roelandt
Apr 5 at 14:05
Final result is visible here. so No need for a clip function.
– Nicolas Roelandt
Apr 5 at 14:10
add a comment |
I had sf 0.7.2; upgraded to sf 0.7.3 and the issue withsf::st_intersect()
was resolved. Not sign in the changelog that the algorithm was changed, maybe the new grob operator ? ¯_(ツ)_/¯ Thanks @rcarto
– Nicolas Roelandt
Apr 5 at 14:05
Final result is visible here. so No need for a clip function.
– Nicolas Roelandt
Apr 5 at 14:10
I had sf 0.7.2; upgraded to sf 0.7.3 and the issue with
sf::st_intersect()
was resolved. Not sign in the changelog that the algorithm was changed, maybe the new grob operator ? ¯_(ツ)_/¯ Thanks @rcarto– Nicolas Roelandt
Apr 5 at 14:05
I had sf 0.7.2; upgraded to sf 0.7.3 and the issue with
sf::st_intersect()
was resolved. Not sign in the changelog that the algorithm was changed, maybe the new grob operator ? ¯_(ツ)_/¯ Thanks @rcarto– Nicolas Roelandt
Apr 5 at 14:05
Final result is visible here. so No need for a clip function.
– Nicolas Roelandt
Apr 5 at 14:10
Final result is visible here. so No need for a clip function.
– Nicolas Roelandt
Apr 5 at 14:10
add a comment |
There is now a sf::st_crop
function available but, you may need the development github version of sf. You can download the development version using the devtools/remotes
package(s).
install.packages("devtools")
remotes::install_github("r-spatial/sf")
For specific irregular geometries, the raster::intersect
function can clip data, and retain attributes, using the rgeos
package. I believe that the package can handle sf class objects but, if not, you can coerce to sp using as(x, "Spatial")
.
Thanks for your comments. As I said,sf::st_crop()
does not respond to my need as it takes a bounding box (so 4 coordinates). I want to cut with another (irregular) shape from another layer. I'll look intoraster::intersect
– Nicolas Roelandt
Apr 5 at 7:32
add a comment |
There is now a sf::st_crop
function available but, you may need the development github version of sf. You can download the development version using the devtools/remotes
package(s).
install.packages("devtools")
remotes::install_github("r-spatial/sf")
For specific irregular geometries, the raster::intersect
function can clip data, and retain attributes, using the rgeos
package. I believe that the package can handle sf class objects but, if not, you can coerce to sp using as(x, "Spatial")
.
Thanks for your comments. As I said,sf::st_crop()
does not respond to my need as it takes a bounding box (so 4 coordinates). I want to cut with another (irregular) shape from another layer. I'll look intoraster::intersect
– Nicolas Roelandt
Apr 5 at 7:32
add a comment |
There is now a sf::st_crop
function available but, you may need the development github version of sf. You can download the development version using the devtools/remotes
package(s).
install.packages("devtools")
remotes::install_github("r-spatial/sf")
For specific irregular geometries, the raster::intersect
function can clip data, and retain attributes, using the rgeos
package. I believe that the package can handle sf class objects but, if not, you can coerce to sp using as(x, "Spatial")
.
There is now a sf::st_crop
function available but, you may need the development github version of sf. You can download the development version using the devtools/remotes
package(s).
install.packages("devtools")
remotes::install_github("r-spatial/sf")
For specific irregular geometries, the raster::intersect
function can clip data, and retain attributes, using the rgeos
package. I believe that the package can handle sf class objects but, if not, you can coerce to sp using as(x, "Spatial")
.
edited Apr 4 at 18:13
answered Apr 4 at 18:07
Jeffrey EvansJeffrey Evans
22.2k22869
22.2k22869
Thanks for your comments. As I said,sf::st_crop()
does not respond to my need as it takes a bounding box (so 4 coordinates). I want to cut with another (irregular) shape from another layer. I'll look intoraster::intersect
– Nicolas Roelandt
Apr 5 at 7:32
add a comment |
Thanks for your comments. As I said,sf::st_crop()
does not respond to my need as it takes a bounding box (so 4 coordinates). I want to cut with another (irregular) shape from another layer. I'll look intoraster::intersect
– Nicolas Roelandt
Apr 5 at 7:32
Thanks for your comments. As I said,
sf::st_crop()
does not respond to my need as it takes a bounding box (so 4 coordinates). I want to cut with another (irregular) shape from another layer. I'll look into raster::intersect
– Nicolas Roelandt
Apr 5 at 7:32
Thanks for your comments. As I said,
sf::st_crop()
does not respond to my need as it takes a bounding box (so 4 coordinates). I want to cut with another (irregular) shape from another layer. I'll look into raster::intersect
– Nicolas Roelandt
Apr 5 at 7:32
add a comment |
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f317804%2fis-there-a-way-to-clip-a-layer-with-a-shape-from-another-layer-in-sf%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
The yellow polygon doesn't "fit into" the red outline. It intersects or overlaps it. "Fit into" to me means "is fully inside". These are very complex looking polygons and its possible some validity constraint isn't valid and we can't tell that without your data....
– Spacedman
Apr 4 at 19:41
Thanks for your comments. I'm well aware that the yellow polygon does not fit into I want either selected it (by an intersection) or get the part inside the red outlined polygon (by cutting it). Actually
sf::st_intersects()
miss the yellow polygon (and so does QGIS geoprocessing tool). I'm not a native english speaker so I might have misused the word "fit". Actually, I started by an intersection by habit, and because I didn't thought there will be big polygons like this one, but cutting is more what I need for this use case. So my question is still valid.– Nicolas Roelandt
Apr 5 at 7:25
I edited my question to remove the misused word.
– Nicolas Roelandt
Apr 5 at 7:27
I'm surprised that
sf::st_intersection()
is not working: geocompr.robinlovelace.net/figures/venn-clip-1.png Do you need to clip the green subsection within the red outline, or both the yellow and the green together? Would performing ast_union()
before clipping work for you?– spacedSparking
Apr 5 at 8:11
@spacedSparking, I'm surprised too. I checked the validity of the polygons and all are valids. Actually the green and the yellow are in the same layer, I just highlighted the problematic polygon.
– Nicolas Roelandt
Apr 5 at 8:53