Clip a Raster with a Polygon in QGIS (Extract by Mask)
Вставка
- Опубліковано 8 вер 2024
- This tutorial demonstrates how to use QGIS to clip a raster layer to the shape of a polygon. This operation is also referred to as clip by mask, or extract by mask. QGIS makes clipping a layer to polygon very simple. If you're having trouble with no data values being displayed as zero or in black, this tutorial will show you how to fix it.
Website: opensourceopti...
Sign up for email notifications (opensourceopti...) and get $5 off any course at opensourceopti...
thanks a lot! made a dozen steps in order to achieve the result needed, but then discovered this feature with no data value - exceptionally thanks to your example! all the best
Glad it helped!
Thanks for the tutorial, but my clipped layer appears with a black rectangle around it, how can I get rid of it? I think you have explained it at the last part of your tutorial, but if you can explain it in a bit detail, it will be helpful for me.
3 years later and its still helping out people like me! Thank you for taking your time to make this video
interesting shape!
Thank you for the nice explanation. I had difficulty with that black area around my clipped raster.
Thanks, much needed. I tried this in Q 3.10.4 and it showed the exact output as Extract by Mask in ArcMap. Also, when I exported it to ASCII using the Translate tool, there was no need to set the NoData values and kept it as default, and it worked.
Nice work!
Omg thank you. I didnt know that I need to assign a no data value. I've been so frustrated with that black border.
You're welcome!
Thank you so much, this thing about "specified nodata" save my life, was kinda frustrating the images with the black parts
Glad it helped!
Thanks very much for showing me how to do this!
No problem!
Thanks for clearly explanation! it is so helpful to me
THANK YOU!!!
Why you did not include how you put the polygon and what is the purpose
My qgis is not showing extractions option in raster. What to do for that
Thank you very much. very helpful
Glad it was helpful!
Nice tutorial! What if I want to reverse the clip, that is, only keep that part of the raster that is outside of the polygon?
You ever find a solution?
me too im looking for this kind solution
Same, is there a way to do that?
Bump...I'm keen to know if this is possible too.
@@RobertThomson So I found a way in the end, however it's not exactly what I hoped it'd be.
You have to create another shape layer, which covers the whole original raster. And then you have to subtract the mask from that huge shape layer, making a third one. This was the only option I found.
Exactly what I was looking for. Thanks!
Glad I could help!
i get "ERROR 1: Cannot compute bounding box of cutline. Cannot find source SRS" and don't knwo what to do, nothing works!
I had the same error message. I entered the "Source CRS" value... even though it displays the CRS for the input layer, I copied that into the Source CRS field, and the clipping extraction worked. In my case this meant entering EPSG:4326, becuase that was the CRS of the input raster.
really great, works nicely. Thanks!
You're welcome!
very nice explanation. thanks
You are welcome
Indredible ! I'm now find a solution! Thanks ! I have another question. After doing a clip action , I have a very bad resolution for my output. I try everything , but I still have it
You should be able to adjust the resolution when running the tool.
@@geospatialschool Thanks for your response but how to do it ?
that is great ! many thanks
You are welcome!
thanks, very helpful
You're welcome!
How do I save the masked portion so as to use it as a DEM for other new projects??
PLEASE HELP!!!!!!!
Select the option to save to a file then enter the file name to save it.
Hello, I am trying to the exact opposite of this. Basically I would want to cut that shape out the raster and keep the rectangular raster and leave the polygone blank. What is the best way to do this?
You'll do it the exactly the same. You just need to make a polygon for the area you want to keep. To do that you might need to create a larger polygon, then difference it from the area you want to remove.
Hello, What is the difference between a "normal" view and a materialized view? Why can a materialized view make more sense with raster data?
Thank you very much!
You're welcome!
HELP
The Following Layers Were Not Correctly Generated always pops up!
Following this, I get the correct clipped raster, but the resolution has drastically dropped. I tried checking "Keep resolution of input raster", but nothing changed. Resolution still dropped.
Checking the pixel size on both layers, the original states: 9.25,-9.25, but the clipped raster also has the same pixel #, but what is on screen is a lot different...
hey, so my main raster has unique value symbology, and a bunch of named classes and colors i chose by hand. Is it possible to clip the main raster and keep the information like symbology and so on? Because i clipped and it changed the colors and the values to default.
Nevermind, figured it out. I notice we can save a color map file and that did the job. Thanks anyway
On some clips, the colouration alters, I have one with thick red lines on the raster. when I do a clip the result is with very thin, dashed lines. Is there a setting I need?
It sounds like after the clip your raster may be overlapping a vector layer? Rasters are not going to be displayed as lines.
@@geospatialschool the original image has clear thick red bourndary in the image but the clip is "washed out" I was hoping to paste an image of both, but cant see an option
Cutline polygon is invalid why???
Why does the clipped raster doesn't match with the polygon when zoom in to pixel level?
Did u got any solution for this problem sir? I am facing the same issue...
@@rashmiyadav987 it might just be a rendering issue, have you tried setting the color gradient values as the original layer?
Can I use this method to clip an area from the Google Satelite base map?
Nope. You can't clip basemaps
@@geospatialschool Thanks.
Why is it ok to clip using input layers with different CRS?
QGIS will reproject layers so they match. Sometimes this can cause problems. If results aren't turning out correctly it is often because of different CRS
@@geospatialschool Ok. I'm working on a project where I use rasters with different CRS. Before I clip them with a country-vector, I use the Warp tool to have them all in WGS 84.
Can't you name the file with polygon name?
Thankyou!! This stuff isnt intuitive
You're welcome!