Questions tagged [rasterio]

Clean and fast and geospatial raster I/O for Python programmers who use Numpy

Filter by
Sorted by
Tagged with
1
vote
2answers
24 views

Mask xarray dataset using a shapefile

I have an xarray dataset of some satellite data and I'd like to mask it using a shapefile. I have previously been doing this using a combination of PIL, numpy and gdal but it would be cleaner to do ...
0
votes
1answer
25 views

Stack multiband raster with Rasterio

I am trying to stack four bands into one TIFF, this is the code I'm using: red_raster = rasterio.open(r"red.tif") red = red_raster.read(1, masked=True) nir_raster ...
2
votes
1answer
32 views

Can satellite data have different locations of nodata values in different channels

I have some Sentinel satellite imagery. And I have noticed that it looks like there are different locations of nodata values in each channel's mask. (I read in the tif file with 3 channels in via the ...
0
votes
0answers
22 views

Rasterio IO Error: Read Failed and Gdal VRT_SHARED_SOURCE

I trying to follow some code on git which uses sentinel hub images code I'm stuck with one part of the code which opens and reads a grayscale tif image which for some reason returns a rasterio ...
0
votes
0answers
24 views

Exporting raster to GeoTIFF

I wish to export a raster to GeoTIFF and I'm unsure of how to go about it. At the moment, the raster is an array and I can view in PyCharm using Rasterio. import rasterio as rio from shapely.geometry ...
1
vote
1answer
20 views

Export single band from a multiband stacked raster with rasterio

I have been trying to break down my multi-band raster into individual bands with rasterio and I am getting this error: ValueError: Source shape (11356, 9488) is inconsistent with given indexes 1 ...
-1
votes
1answer
20 views

Raster overlay and analysis

I have two raster files, of the same spatial area, but different granularity of spatial resolution. Specifically, one (say, A) has cells measuring 375x375m, and the other (say, B) has cells measuring ...
0
votes
0answers
21 views

How to clip a raster using rasterio without lose resolution

I'm using rasterio to clip a large Tiff image using a shapefile, generating one raster for each feature. However, the output resolution is low(96 dpi) and I would like to obtain a better resolution. ...
1
vote
1answer
41 views

Extracting pixel values and their n neighbours from a raster given a set of coordinates

I recently saw Get surrounding pixel value from point shapefile in R or Python on GIS SE. Although it was a rather broad question and got closed, I found it quite useful and interesting. Thus, I ...
0
votes
0answers
25 views

zonal_stats results misaligned

I am trying to clip a raster file with a shapefile using zonal_stats. The obtained clipped raster however does not follow the polygon in the shapefile and the clipped raster covers more area than the ...
0
votes
1answer
31 views

Using Rasterio to index by traditional longitude and latitude with Molleweide Projection GeoTIFF

I'm currently trying to read carbon footprint information from a GeoTIFF, I've never worked with geographic data before. The link is http://worldmrio.com/citiesmaps/GGMCF_v1.0.tif I was wondering ...
1
vote
1answer
26 views

Rasterio histogram save as image

I have create some histogram using DEM as dataset and rasterio using show_hist to take histogram but I can't find some way to save this histogram as image.any idea? import rasterio from rasterio.plot ...
2
votes
0answers
18 views

Raster shapes are not exactly equal after cropping

I clipped multiple rasters to the shape of a polygon shapefile. But, the output rasters do not have exactly the same shapes. I am doing correlation analyses per pixel so I need the array shapes to ...
0
votes
1answer
36 views

Raster info in rasterio module

I have a folder of NDVI raster and I want to see his stats as follows: with rasterio.open('C:\\path_to_NDVI.tif', 'r+') as ds: array=ds.read() stats = [] for band in array: stats.append({ ...
0
votes
0answers
45 views

How to reproject a set of data in Python to 4326?

I need to reproject a set of data in a numpy array with a shape of (121, 160) with crs='+proj=merc +units=meters +a=6370000.0 +b=6370000.0 +lon_0=-76.0100021362 +lat_ts=20.3180007935 +nadgrids=@null' ...
1
vote
2answers
26 views

Rasterio applies a random error to all pixels when saving a raster

When I read a raster and then save it with rasterio the pixels are sligthly modified. Code example: import rasterio inputFile = './band3.jp2' with rasterio.open(inputFile) as b3: v3 = b3.read(1) ...
1
vote
1answer
15 views

Write in missing CRS without copying a file

The coordinate system is not specified in a GeoTiff, but I know what it is. How do I edit the file using rasterio to write in the CRS? Copying it is one way (something like the following), but it's ...
2
votes
1answer
35 views

Is having rectangular cell sizes in a raster bad (after resampling)?

I used rasterio to scale a raster I have to a new resolution. It was at (5.0, 5.0) resolution, and I wanted to make it (15.0, 15.0). However, the resulting resolution is not square anymore. Here's ...
0
votes
0answers
15 views

How can I get .aux.xml written for the GeoTIFF when writing from memory

I have an AWS lambda function that is converting NetCDF files to GeoTIFF files and writing them to an S3 bucket. Due to disk space considerations I have had to write to do the transformation and ...
0
votes
1answer
35 views

Decimated and windowed read in rasterio

In my workflow using rasterio, I'd like to read an overview from a raster and get only a portion of it through a window at the same time. Is this possible? I have a pretty complex script so far and ...
0
votes
0answers
55 views

Problem Combining R, G, B Bands from JP2 Sentinel Imagery Into RGB Imagery

I have JP2 files from Sentinel-2 satellites that I need to combine into a single RGB image. I have tried a few different methods, which I will describe below; however, I keep running into issues. My ...
1
vote
2answers
42 views

How to clip an xarray to a smaller extent given the lat/lon coordinates?

I have a netcdf file showing elevation over Europe derived from GTopo30. Turns out that the extent of this raster file is too big to combine it with other layers, so I would like to crop it to a given ...
4
votes
1answer
76 views

Read pixel values of a raster image for given coordinates stored in a CSV file

I was trying to find the pixel values of several pixels whose coordinates are known. I did that in this way: import rasterio lons = [66.979, 69.2979, 67.2979 ] lats = [36.5854, 40.9854, 37.9854] ...
1
vote
0answers
35 views

Rasterio RGB band combo results in black TIFF

I am trying to to compose a RGB .TIFF image using rasterio with bands that I've downloaded from sentinel-2 (via sentinelsat). The resulting image is black. import rasterio # Open Bands 4, 3 and 2 ...
0
votes
0answers
23 views

Handling nodata values in raster in Python

I would like to set value of raster -999.0 as NaN in crop_image function, while reading/cropping file: for band_path in range_bands: # open raster as numpy array by rater.io in content manager(...
-2
votes
1answer
52 views

Using Python gdalwarp/rasterio to read gif file and world file, re-project to another picture [closed]

I want to re-project a radar image (https://radar.weather.gov/Conus/RadarImg/latest_radaronly.gif) which is in NAD83/EPSG4326 to WGS84/Pseudo-Mercator/EPSG3857. There is a world file associated with ...
0
votes
1answer
51 views

Rasterio: error when resampling a raster [closed]

I'm trying to resample a Sentinel 2 band using an upscale factor. I'm using the code exactly as in Rasterio documentation but I keep getting an error. Here is my code: import os import rasterio from ...
5
votes
4answers
253 views

Make shapefile from raster-bounds in Python

I have a raster that I opened with rasterio. When I do raster.bounds I get BoundingBox(left=399960.0, bottom=-3309780.0, right=609780.0, top=-3099960.0). My question is now, if there is any simple ...
6
votes
1answer
182 views

Multi-threaded compression in rasterio?

For writing large raster files (e.g. satellite image GeoTIFFs) to disk, the throughput rate tends to be limited by the compression algorithm rather than by the raw disk IO. (Benchmarks: 1, 2.) This is ...
0
votes
1answer
22 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 ...
1
vote
1answer
63 views

Converting gray band from dataset to RGB with rasterio for population density

I am seeking a solution that provides me a range of values rather than the provided 0 and 255 from rasterio. That most likely meant that I had to set the photometric and bands and ColorInterp to ...
0
votes
2answers
56 views

Combining two rasters based on a Condition using Open Source Python

I'm new to Python. My only experience is with Arcpy. I need to combine two rasters with the same extent into one output raster based on a condition. Using Arcpy, I would do something like this: ...
3
votes
1answer
69 views

What is the correct way to assign GeoPandas a CRS from Rasterio?

I'd like to be able to create a new GeoPandas object and inherit the CRS from Rasterio, and save a shapefile. The current projection format is seen as invalid when writing an ESRI driver. From here, ...
1
vote
0answers
24 views

Handling Nodata values in sklearn (working w pyimpute)

I'm using sklearn for a classification project. Because I'm relatively new to doing geospatial tasks outside of a GUI, I'm using Matt Perry's pyimpute (link has all the code for that module) to handle ...
2
votes
1answer
142 views

Using Rioxarray / QGIS Projection

For the past couple weeks I have been trying to view GOES17 data from netCDF files (converted to geotif) in QGIS 3.10 but cannot get the projection to work correctly. I have attempted numerous ...
2
votes
0answers
40 views

Polygonize every single pixel of a raster

How can I get every pixel separated? When I calc unique values, if two pixels have the same value, it converts in one row in the final shape. I need every single pixel converted into one unique ...
3
votes
1answer
52 views

Customized Web-based for data cube visualization [closed]

I am stepping into web mapping for the first time. I wanted to develop software for animating multi-spectral, multi-temporal data (in the form of an orthorectified data cube). User should be able to ...
3
votes
1answer
71 views

Unexpected result using rasterio windowed writing - Access window out of range in RasterIO()

I am trying to write (copy and paste) a raster into another raster using raserio's blocks and windows. I have two rasters (A and B): A has a greater extent than B and it completely contains B. The ...
0
votes
1answer
60 views

How can I overlay two raster without turning them in vector format in Python to get zone wise statistics?

I have two raster re-sampled and same extent one is elevation class raster from DEM reclassification classified in 10 zone with 500m interval and another is snow cover fraction raster has snow ...
3
votes
1answer
144 views

Merging rasters with rasterio in blocks to avoid MemoryError?

I am trying to merge two rasters with rasterio. However, when I run dest_array, out_transform = merge(sources), I receive the following error: MemoryError: Unable to allocate array with shape (1, ...
3
votes
1answer
67 views

Working with HDF4 file in GDAL

I'm definitely not the most experienced GDAL user, but I already struggle for quite a while now getting my head around the hdf4 file format in GDAL. The thing is that I have a directory with many hdf4 ...
0
votes
1answer
99 views

Extract population count from GeoTIFF based on mask layer

I downloaded Population Count data from Gridded Population of the World (GPW), v4 as a *.GeoTIFF file. In a next step, I would like to extract the population count of a given area based on a mask ...
0
votes
0answers
17 views

Change in Altitude Value of .tif file [duplicate]

I have a tif file of 7378 X 6923(widthXheight) resolution. I resized it to 1200 X 1200 pixels using Image class in python. img = Image.open('path to tif file') img = img.resize((1200,1200)) But ...
0
votes
1answer
63 views

Change in altitude value after resizing .tif file

I have a TIFF file of 7378x6923 (widthXheight) resolution. I resized it to 1200x1200 pixels using Image module in Python. img = Image.open('path to tif file') img = img.resize((1200,1200)) But after ...
2
votes
1answer
87 views

Rasterising multiple shapefiles into a single raster

I'm not even sure you can do this, but I want to convert multiple shapefiles into a single single-band raster. I'm pretty sure its going to be easier to first create a multi-band raster and then use ...
0
votes
1answer
79 views

Create VRT from multiple hdf files with Rasterio/GDAL

I have several Landsat 8 Scenes, each consisting of 11 bands. I want to mosaic them by creating a VRT and afterwards exporting the mosaic as TIFF again. I tried using GDAL via Python. But maybe it ...
0
votes
0answers
18 views

Convert list of .hdf-files to .vrt in python with Gdal

I'm a little lost. I have a directory with some Landsat-8-scenes. There are files that end on .hdf and they are always accompanied by a .hdr file. What I wanted to do is to convert these scenes to a ...
1
vote
1answer
74 views

How to write BIGTIFF raster files with rasterio

A few months ago I had a hard time in finding a way to read BIGTIFF files. In the end I only managed to do so by creating a new conda environment with the following options: conda create -n env_name ...
3
votes
1answer
66 views

Summing four rasters to one suitability raster using Rasterio & GeoPandas in Python

I am trying to create a basic suitability raster from three vector sources and one raster source using Rasterio & GeoPandas in Python. I have already clipped and rasterized the vector sources to ...
1
vote
1answer
82 views

Calculating NDVI using Rasterio, Python

Below is my code for calculating NDVI using Landsat 8. I have used band 4 and 5, but I am not getting any output. How should I get the output image? import numpy as np import rasterio import ...

1
2 3 4 5
7