Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
2 votes
0 answers
77 views

Replacing values in a raster using a mask in Python

I have a tiff-file with three color bands that I want to mask in Python using a shapefile, but when I use the normal masking method with rasterio, the data points under the mask are replaced with (0,0,...
Marcus K.'s user avatar
  • 141
0 votes
0 answers
48 views

Keep nan values when resampling using GEE and Python

I'm processing MODIS GPP data using GEE and python. The issue is the resolution of MODIS is very coarse so I need to upsample it using, for instance, bilinar resampling. The problem is MODIS contains ...
stray_dog's user avatar
1 vote
2 answers
484 views

How to mask bands of an image based on values of one of the bands using numpy and gdal

I have a raster with two bands, and I want to mask both bands to get data where band "yod" has a value of 2011 and export a new tif file with the same two bands masked. The following script ...
Isa's user avatar
  • 193
0 votes
1 answer
129 views

How to make multiclass color mask based on polygons (osgeo.gdal python)?

I know how to make binary 1-band mask in python with osgeo.gdal.Rasterize(src, shp_file_name, burnValues=[1]) But what if I have several classes and want to make 3-band mask with different colors for ...
Nikita Artemenko's user avatar
1 vote
1 answer
939 views

Mask NetCDF data in Python with shapefile

Precursor to this question: Masking NetCDF data with a shapefile in that has more than one variable Python. Note: Data files are in the previous question. I am trying to mask my polygon but I don't ...
Julius Bamah's user avatar
1 vote
1 answer
3k views

Clip a GeoTIFF based on a bounding box coordinates using rasterio

I would like to clip a geodaframe based on coordinates. Let's say that I have the following bounding box from a GeoPandas dataframe. The projection is mollweide. gdf.boundary.plot() gdf.total_bounds ...
emax's user avatar
  • 269
0 votes
1 answer
449 views

Output raster of rasterio.mask doesn't match CRS of input [closed]

I'm trying to mask a raster with population data with my area of interest. I reprojected the original population raster according to the AOI's crs, but after masking and writing the new file, the crs ...
Danny's user avatar
  • 35
1 vote
1 answer
1k views

Masking clouds on Landsat8 with Python before NDVI [closed]

I'm new to remote sensing and trying to mask clouds with Python. I'm using the same method in Earth Data Science website (https://www.earthdatascience.org/courses/use-data-open-source-python/...
Hilmi Emre's user avatar
1 vote
0 answers
303 views

Getting Rid of Black Boundaries from Tiff Image using Google Earth Engine

I'm getting a tiff image from earth engine using the code below, but the image I get is rectangular and surrounded by a black box. How can I get rid of the black boundaries on the corners and get a ...
Ege Akkaya's user avatar
0 votes
1 answer
535 views

Clip data while reading file into Python with GeoPandas

Geopandas is able to read in only part of a file using: roi= geopandas.GeoDataFrame(geometry) indexed_data = geopandas.read_file("path-to-file", mask=roi) or geopandas.read_file("path-...
sir_olf's user avatar
  • 71
4 votes
1 answer
984 views

Cloud mask algorithms for Sentinel-2 Level-2A data

I am trying to find the best Sentinel-2 cloud mask algorithm for Level-2A data that can be integrated in a Python script and that works well on oceanic areas. I am working with level-2 data because I ...
Just_4n0th3r_Pr0gr4mm3r's user avatar
2 votes
1 answer
208 views

Rasterio mask washing out result

Using the rio.mask.mask function to clip out a section of an ortho. The result .tif looks like it has been "washed" out. The pixel values from the ortho and the result are exactly the same, ...
Binx's user avatar
  • 1,390
2 votes
3 answers
11k views

Masking with rasterio in Python

Introduction I have a shapefile for my area of interest (which in this case is Tehran) and also a TIF file that contains the categorical information(cloud status). In this case, I want to mask the TIF ...
TheFaultInOurStars's user avatar
2 votes
1 answer
4k views

Rasterio mask doesn't work with shapely polygon

I have raster which I want to mask with shapely polygon.According the rasterio documentation, rasterio.mask can work with shapely geometry.However, in this case, it doesn't work. whenever I use my ...
ReutKeller's user avatar
  • 2,215
1 vote
1 answer
580 views

Masking satellite data using shapefile

I am using Landsat data to determine NDVI for a specific region of interest (roi). However, the roi has buildings and other artificial objects that I wish to mask. I have followed through the example ...
turner__rs's user avatar
1 vote
0 answers
753 views

Using a shapefile as mask with rasterio mask gives different affine transforms with rasters of the same projection and resolution

I have a list of n file paths to geotiffs of the same resolution and projection but with varying extents. In brief the goal is to use Rasterio's mask module to use a shapefile containing a single ...
jeremyg19's user avatar
  • 317
-1 votes
1 answer
2k views

GeoJSON to masks [closed]

I need to use the GeoJSON file and TIFF images to produce masks. Is there a Python program that takes GeoJSON file and TIFF image as input and produces masks?
Rohullah Najibi's user avatar
2 votes
1 answer
260 views

Issue while creating dataset mask for Landsat 7 ETM+ band data by using rasterio

I am trying to create dataset mask of a particular band of Landsat-7 (B2) & Landsat-8 (TIR) data and then plot the same using the following code: For Landsat-7 Band-1:- import rasterio import ...
RRSC NGP's user avatar
  • 678
1 vote
0 answers
1k views

Reading in GeoTIFF with different CRS and Transform with rasterio

I have multiple TIF files with different resolutions that I want to combine using rasterio. I am using a modification of the example given in the documentation here. However, on closer inspection ...
Ansh's user avatar
  • 11
1 vote
0 answers
840 views

Rasterio mask removes alpha band

I have a geotiff image that I am clipping to a geojson polygon using rasterio. When I load input the image in QGIS, it has an alpha band (4 bands total). rasterio says it only has 3 bands, which ...
Brian's user avatar
  • 4,229
0 votes
1 answer
245 views

Not plotting NA-Values in raster with python

I have a raster that I cropped beforehand based on a shapefile with gdalwarp -srcnodata '-1000 -255' -cutline {shape} {vrt_path} {tiff_path} The thing is, that there are many NAs that get simply ...
Robin Kohrs's user avatar
0 votes
0 answers
861 views

Crop `vrt` by vector-geometry with gdal

Is it possible to crop a .vrtmosaic to a vector-geometry? I have a .vrt-file which is a mosaic of various sentinel2-scenes. For me it seems to be more efficient to already crop and mask (set ...
Robin Kohrs's user avatar
1 vote
1 answer
3k views

Shapely Polygon to numpy boolean mask [closed]

How can I convert my Shapely polygon to a numpy pixel array representing a boolean mask, with True for where the polygon is?
Saffron Huang's user avatar
1 vote
1 answer
1k views

Creating a raster based on values of other rasters

I have three single band rasters, raster_a, raster_b and raster_c with pixel values 1 and 0. I am trying to burn the values of raster_a to raster_b and create a "new_raster_b" where if: raster_a == ...
FJ_Abbasi's user avatar
  • 611
1 vote
1 answer
6k views

Create a new raster TIFF file which is masked based on the GeoJSON file

I was trying to mask the building given its TIFF file and GeoJSON file creating a new raster TIFF file. I don't know what is the problem, the result is all black, here is the code below: from osgeo ...
user8005429's user avatar
2 votes
2 answers
922 views

Cropping raster using multiple shapefiles

I have a raster which I want to crop multiple times using different shapefiles. My code uses mask method which returns numpy array and its metadata: out_img, out_transform = mask(raster=data, shapes=...
ksnn's user avatar
  • 151
7 votes
1 answer
9k views

How to clip raster inside of circle (python gdal)

I have a source raster and an ERSI shape file, want to crop the raster into the circle. raster = gdal.Open("raster.tif", gdal.GA_ReadOnly) #read raster projection=raster.GetProjectionRef() ...
Cz Gong's user avatar
  • 81
1 vote
0 answers
408 views

Filtering anomalous pixels from masked raster in Python?

I am struggling to succesfully filter out anomalous pixels from a Sentinel-1 image band mask (Pixel based), produced in Python. I am new to Python. By anomalies, in this situation, I mean ...
Rhodri_22's user avatar
  • 360
2 votes
2 answers
6k views

Rasterio error: Input shapes do not overlap raster but reprojection not working

I'm trying to use rasterio (v1.0.13) and fiona to perform a raster clip on a geotiff using a geojson polygon. For reference, the clip works perfectly from the command line using GDAL: gdalwarp -...
metalaureate's user avatar
1 vote
0 answers
385 views

Summarising all the (NDVI) values pixelwise for a masked polygon

A .tif image has been created using the NDVI formula in QGIS. The resulting image shows a region, with varying grades of NDVI values over the image. A .shp file has then been created for an area of ...
pymat's user avatar
  • 111
1 vote
3 answers
1k views

Sequential cloud mask closest to date in Google Earth Engine

I'm interested in transitions that occur on a date, such as bushfires. I want to get the closest (in time) cloud-free landsat image possible using as many images as necessary in the collection up ...
Relu the Bengal's user avatar
1 vote
0 answers
458 views

Does anyone know why I'm getting a completely black geotiff as a result of this shapefile cut out of another geotiff in rasterio?

I am using rasterio to cut out the shape of a lake outlined in my shapefile from a geotiff. When using a shapefile of a singular lake with a geotiff, this works perfectly, but not when cutting out a ...
Kerry O'Neill's user avatar
2 votes
0 answers
1k views

Apply mask and compute statistics with GDAL

I've constructed a VRT that includes a band of data and a mask (0/1 representing water/land) with: ds = gdal.Translate(masked_vrt, combined_vrt, bandList=[1], maskBand=2, format='VRT') Where ...
bbuzz31's user avatar
  • 429
3 votes
0 answers
5k views

Using polygons to create mask on 2d grid with Python?

I have some polygons (Canadian provinces), read in with GeoPandas, and want to use these to create a mask to apply to gridded data on a 2-d latitude-longitude grid (read from a netcdf file using iris)....
Ian Ashpole's user avatar
2 votes
1 answer
2k views

Rasterio.mask returns error 'shapes are outside bounds of raster' - but they are definitely within raster bounds

I'm using rasterio.mask.mask to mask a raster with a shapefile. import rasterio import fiona image_object = rasterio.open('/home/cate/image_name.img') aoi_shapefile = fiona.open('/home/cate/AOI....
Cate's user avatar
  • 133
6 votes
1 answer
8k views

rasterio masking with GeoJSON from file issue

I'm trying to load GeoJSON from a file for use with rasterio mask on a GeoTIFF and I can't seem to get the GeoJSON to load properly. I get this error: File "/Users/user/example.py", line 18, in clip ...
beaorn's user avatar
  • 315
2 votes
1 answer
77 views

How to include pixels excluded by MASK in GRASS GIS?

I have a 150km x 150km raster layer of elevation. I'm running a cell-by-cell PyGRASS script, with one step that considers all neighboring cells within a fairly large circular radius (25km). To account ...
d.guidoo's user avatar
1 vote
1 answer
1k views

masking multiband with rasterio

I have 2 multiband rasters and I want to mask some areas of one of them with values of the other one, so I write this code (I can't figure out why is not working): import os, rasterio import numpy as ...
Digd's user avatar
  • 448
2 votes
0 answers
97 views

Rasterizing Shapefile, using other shapefile as Mask

I have a shapefile (ShapeY) of European extend and want to rasterize each time only a certain area of the shape (ShapeX) (i have the shapes indicating the prevailing extend) with python and QGis. ...
Philipp Dahlem's user avatar
3 votes
1 answer
551 views

Reclassify raster pixels underlying certain polygons using Python

I've got a shapefile with many polygons, each of which exactly overlays a contiguous region of raster cells; an example in yellow: For some of these, I want to use the polygon as a sort of analysis ...
Paulo Raposo's user avatar
  • 1,930
0 votes
2 answers
91 views

How many percentage of sea area is covered with points?

I have a large number of lat/long positions at sea for a geographical area (stored as CSV). This geographical area also contains lots of land area. I want to divide the sea area into a grid (f.ex down ...
bjornasm's user avatar
  • 196
3 votes
1 answer
273 views

Landsat Surface Reflectancce product Python packages

I have to work with numerous Landsat surface reflectance product that I downloaded from http://landsat.usgs.gov/CDR_LSR.php. The product comes with a QA data with information on clouds and shadows ...
user2324097's user avatar
4 votes
2 answers
2k views

Detecting cloud shadows

I am trying to detect cloud shadows in Landsat images. I came up with producing good shadows and cloud masks. Now I'd like to implement my cloud mask adding cloud shadows. Do You have a good idea to ...
umbe1987's user avatar
  • 3,785
4 votes
2 answers
10k views

Determine if point is within an irregular polygon using Python

I would like to create a mask of a grid where points are evaluated as either 1's or 0's depending on if they lay outside of an irregular (i.e. not rectangular) polygon. I have a set of high-latitude ...
ryanjdillon's user avatar
6 votes
1 answer
11k views

How to create mask bands in GDAL and Python?

I have small program in Python that uses gdal and numpy to perform a logarithmic scale of some data into the RGB 0-255 range. Now this input data has a nodata value set to mask the valid values, and ...
ljbade's user avatar
  • 443
6 votes
1 answer
6k views

Creating a mask with transparent pixels in Python

I have a GeoTIFF image with pixel intensities ranging between certain values. Let's say between -2 and 2 (the image is normalized). I have a certain threshold which interests me, let's sat 1. I would ...
JEquihua's user avatar
  • 1,087
9 votes
3 answers
13k views

Turning shapefile into mask and calculating mean

I have been using Python to process huge arrays stored as NetCDF files. I would like to calculate the mean of an area defined by a shapefile. I have just installed GDAL but if there are other tools I ...
questions's user avatar
  • 107