Questions tagged [rasterio]

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

Filter by
Sorted by
Tagged with
11
votes
2answers
10k views

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

Does anyone have a eloquent way of stacking multiple .tif files into a multiple band stack using Rasterio and/or GDAL? I am looking for a way to avoid using a subprocess command like gdal_merge.py ...
6
votes
2answers
5k views

Cannot install a version of GDAL via Anaconda that permits reading BigTIFFs

I have some BigTiff files that I need to read into Python using gdal to do some analyses. According to GDAL's documentation: When built with internal libtiff or with libtiff >= 4.0, GDAL also ...
14
votes
1answer
5k views

Getting pixel values at single point using rasterio

To get a single pixel value at a point in a raster using rasterio, there is an example here: https://github.com/mapbox/rasterio/pull/275 However, is there a direct API within rasterio (and not the ...
4
votes
1answer
1k views

Creating an in memory rasterio Dataset from numpy array

I am reading in a raster using rasterio, and then upsampling the raster as per the example in the documentation: def upsample_raster(raster): return raster.read( out_shape=(raster.height *...
7
votes
1answer
5k views

Plot shapefile on top of raster using plot and imshow from matplotlib

I need to plot a shapefile on top of a raster. I would like to use the python package rasterio and some combination of fiona or geopandas to load the shapefile. I found an example in the rasterio ...
6
votes
1answer
3k views

Reading raster files by block with rasterio?

I find rasterio much easier to use that plain ogr/gdal, so I'd prefer using it. However, I need to process large rasters, so reading rasters by block as explained in the Python GDAL course is ...
5
votes
1answer
4k views

How can I superimpose a geopandas dataframe on a raster plot?

I have a geopandas dataframe countries with country polygons, and a raster dataset raster (read with rasterio). I've already aligned the two as follows: countries = countries.to_crs(raster.crs.data) ...
5
votes
1answer
4k 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 ...
3
votes
0answers
2k views

ImportError dll load failed the specified module could not be found (rasterio)

I want to use the rasterio package to make some test with the Planet Explorer Api (https://www.planet.com/docs/guides/quickstart-ndvi/). I've seen on many forums that I needed to use a wheel file to ...
3
votes
1answer
801 views

Rasterio + QGIS - rasterio.drivers() -> TypeError: 'module' object is not callable

I have been trying to get rasterio working with my QGIS setup so that I can take advantage of the fast raster manipulations. After a day of installing / uninstalling and then piece by piece searching ...
0
votes
1answer
1k views

Add bands' name and description to the Metadata when stacking using rasterio

I'm using this code, of @Loïc Dutrieux, to stack 8 Landsat bands. with rasterio.open(final_list[0]) as src0: meta = src0.meta with rasterio.open('stack.tif', 'w', **meta) as dst: for id, layer ...
0
votes
1answer
85 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 ...
9
votes
1answer
589 views

Read from TIF overviews using rasterio

I'm reading a window of a tif using rasterio. How do I utilize the available overviews to get a down-sampled version of the data instead of reading at the true resolution? Right now I am reading a ...
3
votes
2answers
2k views

How can I extract contours from a raster with Python?

I currently run gdal_contour as a Python subprocess to extract contours from a raster file, but would like to achieve the same function with a combination of Rasterio, Shapely and Fiona. However, ...
3
votes
1answer
2k views

How to split multiband image into image tiles using Rasterio?

I have been using this answer on GIS SE to split 3-band (RGB) imagery into 256x256 3-band image tiles: import os, gdal in_path = '/path/to/indata/' input_filename = 'dtm_5.tif' out_path = '/path/to/...
7
votes
2answers
3k views

What is the simplest way to get the average of multiple raster images while ignore nodata?

I am looking for the simplest approach to take the average across multiple raster images, which contain a lot of nan values. The mean value should ignore any nan. The gdal_calc does not work, because ...
5
votes
1answer
2k views

Why do GDAL and rasterio give different projected bounding coordinates for a given input geotiff?

I have a geotiff, and I want to find its extents and reproject them. I can use rasterio: # Destination CRS dest_crs = some CRS # Get projected boundaries with rasterio clipbox = rasterio.open('...
5
votes
2answers
2k views

Rasterio: tool for creating mosaic?

Is there in Rasterio any way to create a mosaic? I tried to google it, but I couldn't find anything, maybe someone else already used it. I want to use some open source possibilities, I already know ...
2
votes
1answer
229 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 ...
1
vote
2answers
1k views

Error reprojecting Landsat with rasterio

I am trying to reproject on python 2.7 a Landsat8 image from UTM 19N to UTM 18S using rasterio, reading the docs I found and example on the documentation and just change the input, output file and ...
1
vote
2answers
2k 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 -...
0
votes
1answer
234 views

Installing rasterio and Fiona together?

I work on Windows; I use Christoph Gohlke wheels; Python 3.7 After installing GDAL-3.0.1 and Fiona-1.8.6 an error occurs on import of fiona from fiona.ogrext import Iterator, ItemsIterator, ...
7
votes
1answer
7k views

how to take cell size from raster using python or GDAL or RASTERIO

How to take cell size per X,Y using simple python or GDAL or RASTERIO? and hot to count how many pixels have my raster with some packages.. I have find some code but is pyqgis and I don't need this ...
5
votes
0answers
314 views

Stacking and masking Landsat at the same time with rasterio

Based on answers from previous questions 1,2 and the Masking a raster using a shapefile guide from rasterio cookbook, I wrote the code below. The code runs correctly. I would like to improve it. 1- ...
5
votes
3answers
3k views

Converting NetCDF dataset array to GeoTiff using rasterio Python

I have read a NetCDF file using the netCDF4 library and then read one of its datasets ("Evapotranspiration") into a variable (variable contains array) using the following code. Subsequently now I am ...
3
votes
1answer
2k views

import rasterio gives DLL load failed: The specified module could not be found error

I tried pip install rasterio but it failed building a wheel. So i downloaded the wheel file and tried installing it again as suggested in this post: https://github.com/mapbox/rasterio/issues/603 It ...
3
votes
1answer
262 views

Get a window from a raster in rasterio using coordinates instead of row/column offsets, width and height

I am trying to open a windowed dataset in rasterio, but I have a bounding box to work with. I thought it would be easy to do this but it seems that it involves some complicated process with a "Mixin", ...
2
votes
0answers
189 views

Plotting GoeDataFrame on a raster

I have a bunch of polygons which I loaded from a shapefile into a fields GeoDataFrame: geometry raster_val 0 POLYGON ((8.56799 47.80800, 8.56799 47.77200,...
2
votes
1answer
774 views

Masking GeoTIFF file after GeoJSON through rasterio - “Input shapes do not overlap raster”

So my intention is quite simple: I have a 4-Band TIFF file I want to crop after a polygon shape. However, I'm getting the following two exceptions WindowError: windows do not intersect ValueError: ...
1
vote
1answer
874 views

Creating subset of TIFF image and generating its NDVI in Python?

I have two Raster images, one from band4 with a B4 at the end and another with from band5 with B5 at the end. I want to subset the B5 raster to 800x600, then display it and save it as a GeoTiff. Then ...
1
vote
3answers
84 views

Extracting data from a raster

Im working on a project where i must use the map: Corine land cover. https://land.copernicus.eu/pan-european/corine-land-cover/clc2018 (You can download the map in the .tif format) Im not fammiliar ...
1
vote
1answer
802 views

Segmentation fault while writing an output raster by blocks with rasterio

With the answer on my previous question, I was able to set up reading a raster by blocks. I did some computation and now I try to write the result into another raster. However, the program fails with ...
1
vote
0answers
251 views

Rasterizing shapefile with rasterio and gdal gives all cells 0 values [closed]

I am trying to rasterize my shapefile (20 polygons) with rasterio and fiona and turn the new raster into a mask for clipping. I need to rasterize my all polygons in my shapefile and turn on mask ...
1
vote
1answer
95 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 ...
1
vote
0answers
995 views

How to resolve “'NoneType' object is not callable” TypeError when calling rasterstats.zonal_stats from ArcPy script?

I'm attempting to workaround the apparent zonal statistics bug in ArcGIS 10.4 by using rasterstats.zonal_stats. stats = zonal_stats(shapefile_full_path, rast_full_path,0,1,None,None,{'mean','min','...
0
votes
1answer
303 views

Mask rasterio raster with geopandas shapefile

I am loading a shapefile using geopandas as follows: import geopandas as gpd StudyA = gpd.read_file('.../Study_Area_Polygon.shp') Next, I am using folium to plot it interactively: m = folium.Map([...
0
votes
1answer
332 views

Transforming a image to a shape defined by image corners in earth coordinates - Python

I have a source satellite image. It is a rectangular shape x by y. I also have the stored lon/lat coordinates of the corners and the center point in the xml meta file. Is there a way with the gdal or ...