Questions tagged [rasterio]

open source Python library for reading and writing geospatial raster data

Filter by
Sorted by
Tagged with
0 votes
0 answers
9 views

rasterio import error in Python

When I am trying to import rasterio library I am getting the following error: ImportError Traceback (most recent call last) Input In [1], in <cell line: 1>() ----&...
  • 1
0 votes
0 answers
11 views

rasterio image.xy extremely slow [closed]

For anyone else who encounter this issue where running the following code is very slow for each call. it is a issue between rasterio versions i.e rasterio>1.2 where the use of gdal transformers is ...
0 votes
0 answers
15 views

Change values of pixels of a GeoTIFF in Python with conditions

I would like to change the values of pixels based on some conditions. I am using rasterio and python to modify the values. This is what I am doing import nunpy as np import raterio def changeLabel(arr)...
  • 177
1 vote
1 answer
25 views

Extent incorrect after using affine and rasterio to write image

I'm using rasterio to write data to a TIFF image. The original data was extracted from a TIFF image, that was projected in UTM 17 North, or EPSG 32617. I'm writing the data to EPSG 4326, and am also ...
0 votes
0 answers
17 views

Unable to read raster files written by rioxarray after an Xarray operation

I'm unable to read raster files written by Rioxarray after Xarray where operation. import rioxarray as rxr A_raster = rxr.open_rasterio(raster_path, masked=True).squeeze() depth_raster = xarray.where(...
  • 397
0 votes
1 answer
40 views

How to apply a function on two rasters in Python?

I would like to cell-wise function operation on two rasters. While I saw some examples of adding or subtracting two rasters, I'm yet to come across a complex example of how to manipulate rasters using ...
  • 397
1 vote
1 answer
32 views

Normalize images for Sentinel [closed]

I want to join different bands from Sentinel-2 to create index images (such NDVI, EVI...). I know how to open, mix and save the stack using rasterio. However, I have a technical question related with ...
0 votes
0 answers
12 views

Calculate area of raster overlap with polygon by raster value, geopandas

I have two inputs, a raster with values ranging between 0-2, and a polygon shapefile. import geopandas as gpd import xarray as xr import rasterio import rioxarray from rasterstats import zonal_stats ...
  • 283
2 votes
1 answer
85 views
+50

Raster Statistics of Fire Driven Forest Loss within shapefile

I have two inputs, a) shapefile, which I am reading in as a geodataframe, download here: https://we.tl/t-47oPvGR9wl b) raster data from - GFW Fire Driven Forest Loss dataset, download here: https://...
  • 283
0 votes
1 answer
34 views

Clip a GeoTIFF based on a bounding box coordinates using rasterio

I would like to clip a geodaframe based on coordinates. Let's say that I have the following bounding box from a GeoPandas dataframe. The projection is mollweide. gdf.boundary.plot() gdf.total_bounds ...
  • 177
0 votes
1 answer
15 views

Add raster pixel information to existing geodataframe, one column per band

I have a land cover dataset (a geopandas.GeoDataFrame) with a series of "buffers" over a territory. The dataset has roughly this format: unit_id , ..., geometry, 30 ...
  • 101
0 votes
1 answer
45 views

How to extract the elevation from GeoTIFF at an arbitrary point in latitude/longitude?

I want to extract the elevation at any point in longitude/latitude from GeoTIFF, similar to Global Mapper. Using GDAL and rasterio, I get an image with a size of (6000, 6000) points. And the distance ...
  • 3
0 votes
1 answer
58 views

Key error when trying to loop through geodataframe in python

I have a geodataframe 55 polygons for this example. Within this geodataframe is a column called “Colors” that simply has the string values either “Red”, “Blue”, or “Green”, and “Values” column that ...
1 vote
0 answers
24 views

rasterio.plot gives different shape using extent after transformation

I plot the following tiff I plot it using import matplotlib.pyplot as plt from rasterio import plot def plot(self) -> None: fig, ax = plt.subplots(1, figsize=(10, 7)) ax.ticklabel_format(...
  • 89
0 votes
0 answers
20 views

Calculate satellite raster products (NDVI, NDSI etc.) for dataset of polygons using Dask and Stac Catalog

I want to implement distributed raster calculations for dataset of polygons using Dask and Stac Catalog, for example: calculate NDVI for pixels in polygon, statistics(std, mean) etc. I know that there ...
  • 1
0 votes
2 answers
19 views

georeferencing results of `rio stack`

I'm taking some Sentinel-2 imagery and trying to merge the different .jp2 files into one multiband GeoTIFF file. When I do rio info T08VNL_20220702T200859_B02.jp2 I get some terminal output that ...
3 votes
2 answers
246 views

Georeferencing an image that I know four corner points, CRS and their coordinates with GDAL or Rasterio in Python

I have some scan files with spatial information.My Original Image In the example image, the rectangular area drawn with the blue line is my area containing spatial information. In the four corners of ...
2 votes
0 answers
27 views

Calculating upstream (contributing) area for >10,000 points using Python

I would like to create polygons of the contributing area for > 10,000 points. I have all information that I need for this, including a 30m DEM, a river network (LineString geodataframe file) and ...
  • 151
0 votes
0 answers
22 views

Get pixel size of raster in meters when unit of CRS is not in meters

I have a raster that I read with rasterio dataset = rasterio.open(f'{PATH}.tif') The CRS is epsg:4326 I want to know the pixel size of my raster. From the doc I know that res returns the (width, ...
  • 89
0 votes
0 answers
13 views

rasterio read string directly

Usually, I read ascii from files with something like: asc = rasterio.open(filepath) array = asc.read(1) But in some cases, all the lines of the ascii file have already been read into a variable like ...
  • 101
0 votes
0 answers
26 views

Change the origin point of the GeoTIFF files using Rasterio

I created a GeoTIFF file in Python (v3.8) using Rasterio (v1.2.10). The upper left corner is defined as the GeoTIFF file's origin point, which causes some difficulties in subsequent steps. Is there ...
0 votes
0 answers
19 views

Error while transforming in Python using rasterio

I have bunch of NDWI files in a folder and I want to covert them into EPSG 4326. But it is giving error. Also, when I am printing the CRS of the source file, it is showing none. Is this the issue with ...
0 votes
0 answers
39 views

Unable to install spatial-kde package in python due to subprocess error and GDAL version error

I am trying to install the python package spatial-kde for heatmap making, but encountered a subprocess installation error concerning my install version of GDAL. I have GDAL installed, and am able to ...
0 votes
0 answers
26 views

Generate latitude and longitude grid from GeoTIFF

I would like to create a grid (like a NumPy array) of the same size as a GeoTIFF and extract pixel-wise latitude and longitude values. However, I notice that most of the queries are around getting the ...
0 votes
0 answers
21 views

Datatype inconsistencies

I'm trying to merge two rasters that I stacked from Landsat 8 bands together. I'm using rasterio to do so. Earlier this worked for me but I cannot get the same result. After stacking the bands, ...
  • 1
4 votes
1 answer
36 views

Error in storing RGB image pixel-values at point locations using rasterio and geopandas

I have a shapefile showing the locations of some cities and I am trying to extract pixel values from a RGB image at the location of points and store it in new columns in the point shapefile. I can ...
  • 206
0 votes
1 answer
46 views

Converting Raster to Shapefile using filtered values of raster

I have multiple raster files (RGB, 255) and I want to convert those raster files to shapefiles but I want only that area as a polygon where there is data, which means I want to exclude the zero values ...
0 votes
1 answer
43 views

Output raster of rasterio.mask doesn't match CRS of input [closed]

I'm trying to mask a raster with population data with my area of interest. I reprojected the original population raster according to the AOI's crs, but after masking and writing the new file, the crs ...
  • 35
0 votes
0 answers
11 views

Preserve ERDAS .img attributes in rasterio output

I have written a filter using rasterio that reads a single band .img raster and writes a new .img with a modified band. The input .img has attributes in ERDAS that I would like to copy to my new file. ...
0 votes
0 answers
14 views

Reclassify raster pixels as a function of neighboring pixels

I have a raster that presents a combination of land use classification and slope. e.g. a pixel value might stand for "shrub land <10% slope" or "forest 10-20% slope". I'm having ...
0 votes
0 answers
29 views

Rotating satellite image to 90 degree in python using numpy

I have a Thirty two bit floating point satellite image. Due to the depth of the image it cannot be open with OpenCv therefore i am trying to rotate it with numpy. But when i try with numpy it gives me ...
  • 175
0 votes
0 answers
44 views

Count NoData cells inside Mask with Rasterio

I want to count the NoData cells of a GeoTIFF inside a given area of interest with Python/Rasterio. For this I started using the rasterio.mask feature to read in the GeoTiff and crop it to my area of ...
  • 101
1 vote
0 answers
82 views

Clip GeoTIFF into small patches using rasterio and patchify Python

I need to clip a large GeoTIFF into small equal patches to train a Convolutional Neural Network. My patches should have 512x512 pixels and overlap 128. To do this I'm using rasterio and patchify. ...
  • 479
0 votes
1 answer
89 views

Making Rasterio read CRS directly from PRJ file when CRS missing from metadata but present in PRJ file

I'm trying to read a Raster file (GeoTiff) using Rasterio/Python. The file has fully populated metadata, but no CRS projection. This is present in a separate PRJ file (other files included are .aux ...
  • 1
0 votes
0 answers
37 views

Convert geographic coordinates to positive pixel coordinates in a north up image

I have a box with the following coordinates in EPSG:32617 geom = [(542101.7620563037, 4136885.0), (542101.7620563037, 4136889.6473684204), (542107.5299877602, 4136889.6473684204), (542107.5299877602, ...
  • 329
0 votes
1 answer
36 views

Spatial Join does not return no point inside geometry Python

I have a geodataframe containing 200 000 entries with Points, and I want to check which coordinates are inside a geodataframe containing 20 000 polygons that I am creating. The polygons are created ...
  • 13
1 vote
1 answer
177 views

How to deal with Nan value when using rioxarray rio.reproject()?

I was trying to use rio.reproject_match() to match the resolution of two xarray datasets. However, when I used resample methods like Resampling.bilinear or Resampling.average, a large area would ...
  • 23
4 votes
1 answer
171 views

Finding the centroid of every pixel in a raster Python

I am trying to get the centroid of every pixel in a aviris hyperspectral image (a raster) but my results are not quite as expected. The centroids don't seem to line up with the center of every pixel, ...
0 votes
0 answers
33 views

Open manipulated ASC files in rasterio

Background: The German Meteorological Service offers some data in an .asc format that is somewhat off the standard. Which means that some lines with extra metadata in the header are added, which have ...
1 vote
0 answers
29 views

calculate_default_transform larger set than QGIS

I am projection a raster from EPSG:31467 (Gauss- Krüger 3) to EPSG:32832. I have done it once in QGIS and once with rasterio. for the correct affine transformation in rasterio I use: from rasterio....
1 vote
2 answers
205 views

Get elevation from TIFF using rasterio (Python)

I am trying to get the elevation from a TIFF file for each cell of the raster. Therefore I thought about looping through every cell of the raster and fetching the elevation value of the current cell. ...
  • 89
0 votes
0 answers
41 views

rasterio defaults to NAD83 EPSG over NAD83 2011

My ENVI type raster reads as CRS EPSG:26910 (NAD83 UTM 10n) with rasterio despite defining projection to be 6339 (NAD83 2011 UTM 10n) in ArcGIS, for example. My program does an initial CRS comparison ...
3 votes
0 answers
36 views

Merge rasters and clip by a shapefile

I was wondering how to merge multiple TIFF files together and clip the mosaic by the bounds of a intersecting shapefile. I've been able to merge them and output as a .tiff, but am not sure how to to ...
  • 31
0 votes
1 answer
65 views

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

I have a problem with masking a raster by a polygon. I would like to fill by values the area outside the clipped raster, but still inside the masking polygon (graphic example below). The black field ...
0 votes
1 answer
46 views

How do I open certain window from raster file

I have a geodataframe with some bounds and I'd like to open that specifc box from the raster file. Lets say my raster file is name data.tiff so my current code is like: import rasterio as rio from ...
  • 1
0 votes
1 answer
204 views

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

I have a netcdf file located here http://thredds.northwestknowledge.net:8080/thredds/catalog/TERRACLIMATE_ALL/data/catalog.html?dataset=TERRACLIMATE_ALL_SCAN/data/TerraClimate_tmin_1958.nc. I am ...
3 votes
1 answer
127 views

Specifying target resolution when resampling with rasterio

In GDAL warp you can simply set an xRes and yRes value. I'm trying to only use rasterio, but the process seems a lot less clear. According to the docs https://rasterio.readthedocs.io/en/latest/topics/...
  • 635
1 vote
1 answer
60 views

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

I would like to change the resolution of cells in the transform slot of a raster file, but it seems I cannot just do that with simple variable re-assignment. import rasterio ftdm = rasterio.open(...
  • 635
1 vote
1 answer
185 views

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

I have a GeoTIFF that has a black background and shapes using various colours and each point has a data value. I'm trying to use rasterIO to extract this GeoTIFF into a GeoJSON so it can be displayed ...
0 votes
0 answers
59 views

RasterIO how to extract multiple shapes from geotiff rather than background

Im trying to convert my geotiff to GeoJson using rasterio, when I run the following code with rasterio.open("../media/temp/temp.tif") as dataset: # Read the dataset's valid data mask as ...

1
2 3 4 5
14