Skip to main content
20 votes

R raster: masking a raster by polygon also remove cells partially covered?

The documentation is indeed a little confusing. It states that: [...] all cells that are not covered by the Spatial object are set to updatevalue But actually, here covered means only if the ...
Matifou's user avatar
  • 2,021
18 votes
Accepted

Remove NA from Raster Layer

A raster is an array and is always square (rectangular), regardless of where the data occurs. Unless you have a perfectly square extent of data you will have NA values, this is part of the point of ...
Jeffrey Evans's user avatar
12 votes
Accepted

Styling specific layer by using polygon mask in QGIS?

Not a perfect solution but you could make use of the Geometry Generator which adds a visualised line to represent the intersection. You could then set this to overlap the original line feature. Add a ...
Joseph's user avatar
  • 75.9k
12 votes

Counting number of unmasked pixels per image in collection using Google Earth Engine

To get to your end goal of filtering your clipped image collection by 10% or less cloud cover, I would write a function that: counts the number of unmasked pixels in the image counts the number of ...
korndog's user avatar
  • 1,058
10 votes
Accepted

How to clip raster inside of circle (python gdal)

If you create a clipping layer with only the circular feature to use, your code can be simplified in this way (I use my own paths): from osgeo import gdal, ogr OutTile = gdal.Warp("/home/zeito/...
xunilk's user avatar
  • 30k
10 votes

Creating polygon mask in QGIS

In QGIS version 3.24, it is now possible to mask layers using other layers. It is necessary to create a group of layers, where the mask layer and the masked layer will be located. In the layers panel,...
Vsevolod Tsukanov's user avatar
9 votes
Accepted

rasterio masking with GeoJSON from file issue

If your GeoJSON geometry is unique (not a "type": "FeatureCollection") as in geoms = {'type': 'Polygon', 'coordinates': [[(250542.40328375285, 141691.07089614146), (250641.30366207045, 141400....
gene's user avatar
  • 55.1k
9 votes

Sentinel Cloud-free Collection Google Earth Engine Code Editor

Here is an example of cloud masking for Sentinel-2: var s2 = ee.ImageCollection("COPERNICUS/S2"); var pt = ee.Geometry.Point([-122.41653442382812, 37.77180027337861]); var cloudyImage = ee.Image('...
Nicholas Clinton's user avatar
9 votes

Creating Cloud free images out of a MOD09A1 MODIS image in GEE?

I haven't actually worked with MODIS, but it looks like most other image collections in EE. The images contains a QA band, StateQA, with data about clouds/shadow/etc. The catalog contains a ...
Daniel Wiell's user avatar
  • 14.3k
9 votes
Accepted

Masking with rasterio in Python

Your code works fine. If you look at SVDNB_npp_d20120301.vcld.tif (src.meta) you'll see nodata = 255 and you specified filled=True which means fill out_image with nodata values. So when you print ...
user2856's user avatar
  • 66.8k
8 votes

Increasing speed of crop, mask, & extract raster by many polygons in R?

This question is very old so my answer is just for posterities. Since 2020-11-20 there is the new exactextractr package which implement the exact_extract() function, which is the new benchmark for ...
Elia's user avatar
  • 298
8 votes
Accepted

Masking layers by a vector polygon layer in QGIS

You can put the colored polygons on top, with a layer blending mode set to darken Below, have the building layer with the polygon fill in white. At the bottom, add a new layer containing one large ...
JGH's user avatar
  • 42.2k
8 votes
Accepted

Setting masked pixel value in Google Earth Engine image export?

Wasn't able to get this to work with an NA output, but based on this answer I settled on this solution, which can be used to set "masked" pixel values to whatever value is set in the unmask() function:...
JepsonNomad's user avatar
  • 2,166
8 votes
Accepted

Masking pixels inside the polygons using Google Earth Engine?

There may be many ways to do that, but when I had to do it I did: var maskInside = function(image, geometry) { var mask = ee.Image.constant(1).clip(geometry).mask().not() return image.updateMask(...
Rodrigo E. Principe's user avatar
8 votes
Accepted

Adding simple Geomasking (Donut masking) feature using PyQGIS

Preamble: Unfortunatelly I did not read your articles, but I hope I understood your issue correctly. Let's assume there is an input point layer called 'points2', see the image below. The task is the ...
Taras's user avatar
  • 33.1k
7 votes
Accepted

Apply cloud mask to sentinel 2 image in SNAP

You can use Raster > Mask > Land/Sea Mask and choose Use vector as mask and the corresponding cloud band in the dropdown menu.
AndyB's user avatar
  • 812
7 votes

How to create a semi-transparent map collar in QGIS composer?

You can create a collar using data frame or map frame within the layout view, as follows Set the data map position for both X and Y to 0 (Zero) Increase the thickness of the frame to desired value (...
ahmadhanb's user avatar
  • 41k
7 votes

Calculating water occurrence of Sentinel-1 images in Google Earth Engine

After some research and help, I finally have the solution to the described problem, which I also want to share with the community. https://code.earthengine.google.com/8b39abcdf63cd569ee09a6ac2eb68c93?...
Stephan Büttig's user avatar
7 votes
Accepted

How to mask everything but a polygon in QGIS?

There is a plugin that does what you need: Mask Or since 3.22 (no sure the version), there is also a new type of symbology called « inverted polygon render », with which you can do a mask outside your ...
katagena's user avatar
  • 1,668
6 votes

Remove NA from Raster Layer

If you mask any raster you probably will obtain NA values, even more using SpatialPolygonDataFrame as mask. You have two posible options, if SpatialPolygonDataFrame is a rectangle, use crop() before ...
aldo_tapia's user avatar
  • 13.7k
6 votes
Accepted

Lapply function on raster iterating through SPDF polygons in R

You can try crop and mask instead of only masking over the Raster Layers. Try the reproducible and commented code below. In this example, using crop reduced ~ 92% the size of the objects in the R ...
Guz's user avatar
  • 3,176
6 votes

Increasing speed of crop, mask, & extract raster by many polygons in R?

Speed up extracting raster (raster stack) from point, XY or Polygon Great answer Luke. You must be a R wizard! Here is a very minor tweak to simplify your code (may improve performance slightly in ...
mmann1123's user avatar
  • 591
6 votes
Accepted

Replace specific raster class by surrounding classes

You can convert your clouds and shadows to null / no data (e.g. by using r.null) and then interpolate those "null areas" based on the surrounding values using the Fill nodata tool, see the ...
GISHuman's user avatar
  • 3,691
6 votes
Accepted

How to add to the map all the images on a image collection with cloud pixels masked on Google Earth Engine?

The solution you have tried uses the image 'id' so you end up displaying the 'original' image in the collection. As an alternative, following what you said in the comment, you can use the .get() ...
jfoguet's user avatar
  • 545
6 votes
Accepted

Conditional calculation using QGIS

Since it is a raster layer you should use the Raster Calculator. It is a bit different then the Field Calculator described by the other answer and comments. The expression should be something like ...
eurojam's user avatar
  • 11.1k
6 votes
Accepted

Deleting or hiding features in QGIS in one layer based on the value of the feature in another layer

you can use the raster calculator and make a formula like the following: if (identification_number@1 = 1, 0, elevation_raster@1) this computes a new Raster with the original values from your height ...
eurojam's user avatar
  • 11.1k
5 votes

Turning shapefile into mask and calculating mean

Now in 2017, I use rasterio.mask.mask and fiona to rasterize the shape file and then apply that to the netCDF dataset using xarray. Now in 2019, there is https://github.com/corteva/rioxarray to ease ...
j08lue's user avatar
  • 289
5 votes

Resampling raster based on mask raster?

Following comment by @RJJoling, this is QGIS Align Rasters tool workflow: Click on a green + icon. Input raster layer is the raster you want to change (in your case: originally 2m resolution). Give ...
Kazuhito's user avatar
  • 30.9k
5 votes
Accepted

Creating water and vegetation mask via image collection?

The error occurs cause you did not rename the band to 'NDVI' and you did not use the actual variable containing the NDVI band (you are now using the original collection using 'S2collection.map(...
Kuik's user avatar
  • 10.1k
5 votes
Accepted

Masking an ImageCollection using another Image in Google Earth Engine

ImageCollection.map takes a function to apply to each image in the collection. Give it a function which applies the mask: MOD44B = MOD44B.map(function (image) { return image.updateMask(Globcover); })...
Kevin Reid's user avatar
  • 10.4k

Only top scored, non community-wiki answers of a minimum length are eligible