Questions tagged [rasterio]

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

Filter by
Sorted by
Tagged with
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 ...
12
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 ...
12
votes
1answer
2k views

Reading S3 Sentinel-2 image files with rasterio

I am currently experiencing an 'Access Denied' error after using rasterio to open the Sentinel-2 AWS .jp2 image files (currently hosted by Sinergise and can be found here). My code looks like this: ...
10
votes
1answer
4k views

numpy array to GTiff using rasterio without source raster

I have a numpy array that represents rasterized data from a LiDAR point cloud. For example: import numpy as np import rasterio arr = np.random.randint(5, size = (100, 100)) I know information about ...
9
votes
1answer
591 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 ...
8
votes
1answer
5k views

Crop a raster using rasterio and geopandas

I am cropping a set of historic aerial photographs. These photographs have large black areas in the edges (0 value). However there is also valid data with a 0 value. The workflow I am using is: Load ...
8
votes
2answers
2k views

Rasterio does not execute the rasterize function

Rasterio's features.rasterize() function is not working as expected. I have two files: OpenStreetMap shapefile with land usages Raster (.tif) with satellite imagery Goal: Create a raster file from ...
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 ...
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 ...
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 ...
7
votes
2answers
1k views

Sentinel-1 Data opened with rasterio has no Affine/Transform/CRS

I'm trying to process Sentinel-1 data downloaded from SCIHub using Rasterio. When I open a Sentinel-2 raster taken from the Amazon Web Services Sentinel 2 dataset the Affine, Transform and CRS are ...
7
votes
1answer
838 views

Should i use jp2 or cloud optimized geotiffs to efficiently access small windows from Rasters on S3

I am building a system where we have a lot of large rasters (Sentinel-2 bands) stored in S3. A lot of this data is stored in our own buckets so we can store whatever format we find most usable. I ...
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 ...
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 ...
6
votes
1answer
1k views

Rasterio: Use case for src.meta vs. src.profile when reading and writing rasters?

When I read a raster in with rasterio (version 0.36.0) in Python, I can call up the metadata in two ways: src = rasterio.open(my_raster) src.profile {'affine': Affine(1.0, 0.0, 401900.0, 0.0, -1.0, ...
6
votes
2answers
3k views

Is it possible to read in specific bands from a multi-band raster with gdal or rasterio?

I wasn't able to find an answer to this after searching the help files and the forums. I have a (virtual) raster with 60 bands, where each band represents a realization in time (think of frames of a ...
6
votes
1answer
206 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 ...
6
votes
1answer
1k views

Open a raster file with read and write permissions in rasterio

I am trying to write a function which will help me construct a rasterio memory file and return the dataset reader object so I can then play around with it as needed. I am trying to avoid with ...
6
votes
1answer
635 views

Extracting data within geometry (shape)

I have a NetCDF dataset which I normally call using the xarray function. I have recently been doing some transect analysis on the dataset, which looks something like this (the area between the ...
5
votes
4answers
427 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 ...
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 ...
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 ...
5
votes
1answer
5k views

Calculating NDVI with Rasterio

I'm using Rasterio to read GeoTIFF files from Landsat 8 and calculate NDVI into a new GeoTIFF file. My code looks like this: import numpy import rasterio import subprocess with rasterio.drivers(...
5
votes
3answers
4k 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 ...
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
1k views

Fast raster combine using rasterio

I'm trying to duplicate the functionality of ArcGIS's Combine function within rasterio. Given a list of (presumably categorical) rasters read with rasterio, I want to output a combined raster and a ...
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
1answer
3k views

Excluding nodata value in band calculation with Rasterio?

How do I exclude no data values when doing a raster calculation with rasterio. I realise that the files are read into an array, and that "0" is a nodata value. However, when I do a simple sum like "...
5
votes
1answer
94 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] ...
5
votes
3answers
5k views

python rasterio error

When I am importing RASTERIO then i am getting an error as: Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> import rasterio File "C:\Python27\lib\site-...
5
votes
2answers
45 views

Create pandas df from raster image- each pixel is a row

I have raster image with 3 bands. I would like to convert this image to csv file wso each row will be pixels and each column will be one band, so I can see easily the three values each pixel got. ...
5
votes
1answer
1k views

Geopandas and Zonal Statistic error

I'm trying to use Geopandas and zonal statistic from rasterstats together. I run this code import geopandas as gpd from rasterstats import zonal_stats geodf = gpd.read_file("SHP/shape.shp") ...
5
votes
1answer
334 views

Error using rasterio's sample method

I'm using rasterio's sample function to get values from a (single-layer) raster based on a list of x,y locations: for val in myraster.sample(locations): print(val) This works fine for the first ...
5
votes
0answers
614 views

Georeference an unreferenced image using rasterio in Python

I have unregistered/unreferenced 6 band TIFF images that I have been trying to export as georeferenced GeoTIFFs. The GPS coordinates of the corners of each image is known and each image is 1024 height ...
5
votes
0answers
315 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- ...
4
votes
3answers
4k views

Finding pixel location in raster using coordinates?

I'm not a GIS person. I haven't found or at least identified a solution to my problem, so decided to ask. I have a big rasters and a list of thousands of coordinates. I need to find the pixel ...
4
votes
1answer
1k views

bad results NDVI in rasterio with jp2 sentinel-2 bands

I am using 2 Sentinel-2A bands to compute the NDVI. Here is my code: import os, rasterio outfile = r'some\path\ndvi.tif' #url to the bands b4 = 'http://sentinel-s2-l1c.s3.amazonaws.com/tiles/30/T/TK/...
4
votes
1answer
597 views

Suppressing rasterio verbosity

I have the following script using rasterio: if not os.path.isfile(out_dir + os.sep + name_adm1 + '.tif'): with rasterio.drivers(): with rasterio.open(constants.ras_cmask) as src: ...
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 *...
4
votes
1answer
272 views

How to run rio-color from rasterio?

I am completely new to GitHub, I've never had a need to use it, but now I would like to use rio-color plugin from rasterio, mapbox. I am on Ubuntu. I've already managed to start using rasterio, load ...
4
votes
1answer
223 views

Which affine format to use in Rasterstats zonal_stats?

I am working with the Rasterstats package to run zonal statistics on two raster datasets. The documentation calls for the following: import rasterio from rasterstats import zonal_stats with rasterio....
4
votes
1answer
543 views

Split GeoTIFF into multiple cells with Rasterio

I'd like to create training data for a machine learning pipeline. To do this I want to take a large raster and split it into multiple equal sized cells. I have a very basic loop for generating the ...
4
votes
1answer
298 views

How to use rasterio transform on all bands

I've imported a 10 band raster tif using rasterio as ds. I'm attempting to pad the image but keep getting errors with the transform. print(ds.transform) pilpadimg = rasterio.pad(ds.read(), transform=...
4
votes
1answer
462 views

Error reading large virtual raster with rasterio: “Cannot invert degenerate transform”

I've created a virtual raster using gdalbuildvrt, which covers a large extent (England) at a high resolution. The data is fairly sparse, focused around the coastlines with no files covering inland ...
4
votes
1answer
481 views

How to pull crs information from a world file when reading an image using python GDAL or Rasterio?

How to pull crs information from a world file when reading an image using python GDAL or Rasterio? The images I am reading to not have in built metadata, it is stored in the projection file (.prj) and ...
4
votes
2answers
2k views

How to let rasterio use a colormap file when showing a TIFF

I'm new to rasterio. I have tried this example. My raster file is a GeoTIFF file and I have a colormap file available in ESRI *.clr format, with 58 lines. The values in the GeoTIFF file range from ...
4
votes
1answer
1k views

gdal missing jp2 driver files how to install them

Am operating on OSX(latest) have gdal installed and rasterio (both from conda versions 2.1.3 and 1.0xxx. I can read tiff perfectly but jp2 files (aka from Sentinel-2 sat). When I search for ...
4
votes
1answer
910 views

NDVI image processing

I am trying to get a NDVI image from an RGB + NIR image captured by a modified Cannon S110 camera bought from Event38 along with a 3DR Iris+ drone link The image captured with the camera looks like ...
4
votes
1answer
1k views

Rasterizing polygon grid in Python (geopandas & rasterio)

I am trying to rasterize a custom polygon grid with one or more columns. Preferably I'd like to create multi-band rasters from multiple GeoDataFrame columns (in polygon grid), but I have got stuck ...
4
votes
1answer
680 views

Cannot upscale raster with rasterio

I am trying to upscale a raster using rasterio but I don't know why my process gets killed. It can print "i am arrived here" but on the reproject() I have as terminal output: killed This is the ...

1
2 3 4 5
7