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
1answer
18 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
45 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
38 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 ...
0
votes
1answer
76 views

Plotting a polygon on a GeoTIFF [closed]

I am trying to use polygon coordinates to plot polygons on GeoTIFFs of satellite images using gdal or rasterio, yet somehow I keep failing. There is two things I want to do: create a mask with only ...
0
votes
0answers
27 views

NDVI array of values from -1 to 1 - how to get nice TIFF with green intensity depending on NDVI index? [closed]

I have a NDVI array of values from -1 to 1: nir=b8.read(1) red=b4.read(1) ndvi=numpy.where((nir+red)==0, 0, (nir.astype(float)-red.astype(float))/(nir+red)) When I write it to file using this: ...
1
vote
1answer
58 views

Convert GDAL command line commands to Python script or code

I'm looking to convert my GDAL commands to Python code using either GDAL or Rasterio, as I've heard this is better to use. I've been scratching my head at this and I could be missing some simple ...
0
votes
1answer
24 views

How do I keep the coordinates while calculating tiles from a raster with Rasterio?

I'm trying to split a georeferenced TIFF image into several tiles for further processing. I have managed to calculate a single tile and give it the right CRS, evething fine so far. Once I load the ...
1
vote
1answer
88 views

Extract all pixels values from GeoTIFF with Python [closed]

I would like to recover the values of the pixels of a GeoTIFF of a single band. First I get the x and y coordinates and I would like to use them to access the pixel value. Here is my code: raster =...
1
vote
2answers
53 views

Overlay two raster GeoTIFFs using rasterio mask

I'm trying to crop two different geotiffs/rasters using a polygon with rasterio's mask function in order to get two corresponding/overlapping cropped numpy arrays of the same size/shape. The problem ...
1
vote
2answers
46 views

Huge GeoTIFF file after reprojecting file

I have some geotiff file. Their CRS ise EPSG:32635. I want to change crs to EPSG:4326. I use below script from Rasteri doc (link). In addition I added 'compress': 'lzw' to compress new geotiff file. ...
1
vote
1answer
32 views

Creating custom proj4 string from components

I'm trying to work with NOAA's NDFD weather data, which are released as rasters in GRIB format. Specifically, I'm currently trying to get the pixels that intersect an arbitrary geometry. Information ...
1
vote
0answers
26 views

Rasterio 0-360 lon inputfile to -180:180lon WarpedVRT output

I have used rasterio to open netcdf files and by defining a WarpedVRT extract a subarea that can be read with the vrt.read() command. It works like a charm except when the longitude grid is 0:360 ...
1
vote
2answers
54 views

Reading raster values in points gives back a generator object instead of actual value

Given a raster TIF file and a point feature class in a geodatabase, I am trying to extract the values of the raster on the points and add them as a new column on the point feature class. I am using ...
1
vote
0answers
22 views

Offset after clipping an image using rasterio.mask (illustrated with figures) [closed]

I want to clip an image named img_A of dimensions 14000x10000 using a polygon shape in order to get the same dimensions than another image named img_B of dimensions 1925x1372 (see figure 1 below). The ...
1
vote
1answer
31 views

Loading a section of JPEG2000 raster

I have a raster band saved as a .jp2 which I downloaded from Sentinel2-L2A. I can load it using rasterIO: with rasterio.open(path_to_jp2) as src: img = src.read(1) This works fine, however, it ...
1
vote
0answers
15 views

Defining invalid regions of VRT file with rasterio in a way that allows windowing [closed]

I'm using a VRT file to represent a bunch of individual map tiles as one big image. I noticed that some of the data is invalid but not marked as such (via the invalid data value). I'd like to define ...
1
vote
1answer
47 views

Building Raster Attribute Table (RAT) from GeoPandas dataframe with rasterio or GDAL

I am trying to figure out how to generate a RAT for a 1-band raster with rasterio or GDAL given a GeoPandas dataframe. My GeoPandas dataframe has 4 columns (X, Y, PERC_VALUE, LANDUSE_LABEL) which I ...
0
votes
1answer
40 views

Open a GDAL dataset with rasterio.open()

I am processing geotiff files with GDAL and rasterio. Every process of my processing chain generates a file in output. What I want is saving every file in memory instead of creating files in the disk. ...
2
votes
0answers
47 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,...
1
vote
2answers
65 views

module 'rasterio' has no attribute 'open'

I am new to rasterio. I'm trying to open a tif file using this code: import rasterio dataset= rasterio.open('/home/zaianir/Documents/DB/serie_temporelle_s2/serie_temporelle_s2/Sentinel2_T31TCJ_MASKS....
1
vote
0answers
97 views

Installing Rasterio and GDAL API in a virtuallenv in Windows 10

Following rasterio installation guidelines (rasterio.readthedocs.io) I downloaded the relevant wheel files from Cristoph's list (link) and installed them successfully on my Windows 10 system. Yet I ...
2
votes
1answer
87 views

Convert GeoJSON to GeoPandas GeoDataframe

I created the following GeoJSON object with this code: from rasterio.features import shapes polys = [] for shape, value in shapes(segments, transform=affine): polys.append(shape) [{'type': '...
1
vote
0answers
40 views

Converting GeoJSON to a raster image using rasterio [closed]

My geospatial data knowledge is limited. I am hoping for advice as to how I can convert the full GeoJSON geometry into a tif image using rasterio. I have tried using gdal_rasterize to no avail. Not ...
2
votes
1answer
47 views

Using rasterio to show RGB image with nodata

This question is same as https://stackoverflow.com/questions/59132459/use-rasterio-show-rgb-image-with-nodata I have a multiband image with nodata value (which is Landsat and been set nodata to 0). ...
3
votes
1answer
87 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....
1
vote
1answer
23 views

rasterio merge giving incorrect result

I have 4 separate ASCII grids which all contain the same data: 1 2 3 4 3 4 5 6 4 5 6 8 7 9 5 4 The metadata, however, is different: ncols 4 nrows 4 xllcorner x yllcorner y cellsize 1 nodata_value -...
2
votes
2answers
72 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=...
2
votes
1answer
31 views

Change dtype in Sentinel-2 .jp2 images

I'm trying to change dtype of a .jp2 Sentinel 2 image, with this code: with rasterio.open(tmp_file) as src: meta = src.meta meta.update(dtype=rasterio.uint16) array = src.read() with ...
2
votes
1answer
56 views

Using Rasterio for calculating Volume in a raster file

I am calculating the volume in a raster .tif file. My current approach is area * height where I calculate the area in the .tif file and multiply it by elevation value of .tif file. I have used ...
1
vote
0answers
35 views

Alternative to Rasterio Mask module for clipping a raster using masked geojson

I am clipping a raster (.tif file) using a mask vector (.geojson) file. with rasterio.open(url) as src: out_image, out_transform = rasterio.mask.mask(src, shapes, crop=True) But, this ...
2
votes
1answer
47 views

Modify bounding box of GeoDataFrame

I have a GeoDataFrame which is a multipolygon and represents boundaries of a country: 0 MULTIPOLYGON (((10.10112 46.23346, 10.10099 46... Its bounding box/extent is: minx miny maxx ...
2
votes
0answers
104 views

Rasterize GeoJSON or Shapely Geometry?

I am trying to rasterize a GeoJSON or shapely geometry but it does not rasterize all the geometry (some of it is not in the TIFF-file). I tried gdal_rasterize -burn 255 -burn 0 -burn 0 -ts 4950 4900 ...
1
vote
1answer
28 views

s3 for GeoTIFF - mask band ignored in GeoServer

Goal: Cloud Optimised Geot4iffs (COG) that display without edge artefacts in Geoserver. Problem: It doesn't display nicely: GeoServer appears to be ignoring the internal mask on the input GeoTIFF ...
0
votes
0answers
28 views

Update raster value at point with Python

I am looking for a fast way to update one value in a raster. Similar to this solution but the other way round. Normally I would go with generating a raster and run a conditional grid operator like it ...
2
votes
1answer
55 views

Extract images from GeoTIFF file using shapefile

I would like to know if there is any way that I can extract images from a GeoTIFF file using a shapefile which contains shapely polygon data for specific locations in the image in Python. I would like ...
1
vote
1answer
42 views

How to select one band in image using rasterio

I have two different images and I want to select one specifi band from each one of them and calculate regression between them. Each one of those bands is a result of calculation I did (in the first ...
0
votes
0answers
18 views

Rasterio: setting the size of `block_shapes` for Windowed reads

I am trying to use Rasterio Windowed reads to iterate over an image. Seems like the block_windows api will break the image into pieces and iterate over them. However from the examples given, it does ...
1
vote
0answers
42 views

Merging Sentinel 2 RGB bands with rasterio

I'm trying to merge Sentinel 2 bands RGB bands with rasterio like this: import rasterio import numpy as np from rasterio import plot from rasterio.plot import show band2=rasterio.open("B02.jp2") ...
1
vote
0answers
26 views

Reprojection problem with Rasterio

I have already processed so far NDSI map by using Rrasterio, NumPy, os and matplotlib.pyplot for plotting the data. Now, I would like to eliminate permanent ice from NDSI map. I am facing one major ...
2
votes
1answer
67 views

Maximum and mean value is different in Python than QGIS 3.6

I read a Landsat-8 TIFF file using Python Rasterio to compute the max and mean using the following code: path = "LC08_L1TP_115036_20181025_20181031_01_T1_B7.TIF" test = rasterio.open(path).read() ...
0
votes
1answer
38 views

Reading raster cell values on specific PostgreSQL points with rasterio and updating PostgreSQL table with those values?

I have 9 UK wide raster files (TIFF) and about 3 millions points on a PostgreSQL table. I need to add, for each point on the pg table, the values of the 9 raster cells where the point falls in. I am ...
1
vote
0answers
20 views

Getting subset with same cordinates for different rasters using gdal.translate?

I am a new into Python. I have processed 1000 NDVI rasters covering larger area. I need to burn those NDVI raster with Water mask. The water mask came for whole world I need to subset AOI and also ...
2
votes
1answer
30 views

Cut hole in raster with shapefile and sample at closest edges

I have a raster in which I'd like to cut a "hole" with a shapefile. I have points close to the boundary, but inside the hole, and I would like to find the closest point on the edge. To give a concrete ...
2
votes
1answer
109 views

Using xarray to resample and merge two datasets

I have one dataset of satellite based solar induced fluorescence (SIF) and one of modeled precipitation. I want to compare precipitation to SIF on a per pixel basis in my study area. My two datasets ...
1
vote
2answers
69 views

How to convert PNG files to GeoTIFF using Python

I have a big set of PNG files and EPSG:3006 coordinates of the edges of each file. (actually the coordinates of the edges are given in the file name, like this: 'image_666751_7023263_667007_7023519....
0
votes
0answers
25 views

GDAL Warp windows do not intersect error

I have been trying to use sentinelsat API for retrieving and processing satellite image data. I use GDAL to warp the image and the rasterio to clip my Area of interest and use it for analysis. However,...
0
votes
0answers
23 views

How to export a rasterio window to an image without geo-reference information?

I would like to export a rasterio window to an image. import rasterio def export_window(w, path): number_of_bands, height, width = w.shape profile = { "driver": "JPEG", "...
0
votes
0answers
17 views

Masked array fill value getting changed

I am using the following code to mask the clouds from Landsat image using QA band. I am facing the strange issue as you can see I have 2 print statements in my code which prints the fill_value of ...
0
votes
0answers
37 views

Calculating the mean value of a raster stack using numpy

I am calculating the mean value of a stack of images. I created a virtual raster which is the stack of 68 sentinel-1 images. I want to calculate the mean value for every pixel. Here is my code: ...
2
votes
2answers
228 views

rasterio “invalid dtype: 'bool'”

I want to write a binary raster to disk. I have the numpy array whose dtype is: dtype('bool') I try to open a GTiff for writing: img_output = rasterio.open( "../../binary_output.tif", ...