New answers tagged

0 votes

Filling with values the area outside the cropped raster but still inside the masking polygon

I managed to solve the problem myself, so I am posting the code for others with the same problem. I masked the raster with a polygon. I then rasterised the masked polygon. I performed a mosaic ...
user avatar
0 votes

How do I open certain window from raster file

Just pass the raster dataset transform. with rio.open(data.tiff) as data: rst = data.read(1, window=from_bounds( bounds['left'], bounds['bot'], bounds['right'], bounds['top'], ...
user avatar
  • 52.8k
1 vote
Accepted

Xarray Dataset to raster - ValueError: failed to prevent overwriting existing key grid_mapping in attrs

See: https://corteva.github.io/rioxarray/stable/getting_started/getting_started.html ds = xr.open_dataset("TerraClimate_tmin_1958.nc", decode_coords="all") With decode_coords=&...
user avatar
  • 5,827
3 votes

Specifying target resolution when resampling with rasterio

You just need to figure out the scale factor from your chosen and current pixel size, e.g. I want to resample this 10m resolution "input.tif" to 12.5m: import rasterio from rasterio.enums ...
user avatar
  • 52.8k
2 votes
Accepted

'Affine' object does not support item assignment (rasterio)

If you want to modify the raster, you either need to open in r+ mode or w mode depending on if you wish you create new raster or modify inplace Using r+ ftdm = rasterio.open(dtm_path, 'r+') ftdm....
user avatar
1 vote
Accepted

Extract shapes and shape data from GeoTIFF using Rasterio and store as GeoJSON

shapes returns an iterable of tuples with geometry and value, you can use geopandas to parse the geometry into a valid geojson. import geopandas as gpd import rasterio from rasterio import features ...
user avatar
  • 52.8k
0 votes

How to solve rasterstats nodata warning

You may have set nodata on your raster, but you are not passing that raster to rasterstats.zonal_stats, you are passing a numpy array. And numpy arrays don't have a nodata property. Just like you ...
user avatar
  • 52.8k
0 votes

Finding latitude and longitude for pixel values

You could do something like the following which: only reads the data into memory once and as required as it uses dataset.sample() instead of dataset.read() and generators instead of list ...
user avatar
  • 52.8k
4 votes
Accepted

Changing band datatype to uint64 using rasterio

According to the rasterio source code for dtypes, valid dtypes does not include uint64. Instead use uint32
user avatar
1 vote

Parallelizing mask process using geopandas to cookie cut a rasterio object

As an alternative to rolling your own parallel processing implementation, here's an simple example of using dask and dask-geopandas to parallelize some polygon on raster statistics using the ...
user avatar
  • 52.8k
0 votes

Using rasterio to show RGB image with nodata

Note that show is a wrapper on imshow and you can pass imshow kwargs to it. I believe imshow itself would handle a 4th band as an "alpha" (i.e. transparency) layer, but you can also provide ...
user avatar
0 votes

Using Rasterio or GDAL to stack multiple bands without using subprocess commands

With gdal and numpy the following is possible assuming the images are the same size (rows and columns) and have the same CRS (e.g. 10m bands from a Sentinel 2 scene). import gdal import numpy as np ...
user avatar
  • 1,491

Top 50 recent answers are included