Skip to content
Discussion options

You must be logged in to vote

Hi @LukaszKowalski2013,

xarray-spatial doesn't do file I/O, it's only the spatial analytics (slope, hillshade, etc.). For reading and writing GeoTIFFs you want rioxarray:

import rioxarray

da = rioxarray.open_rasterio("your_file.tif")
da_zeroed = da * 0
da_zeroed.rio.to_raster("your_file.tif")

To get the raster boundary as a polygon, use rasterio.features.shapes:

import numpy as np
from shapely.geometry import shape
import rasterio
from rasterio.features import shapes

with rasterio.open("your_file.tif") as src:
    mask = src.read(1)
    binary = (mask != src.nodata).astype(np.uint8) if src.nodata is not None else np.ones_like(mask, dtype=np.uint8)
    
    results = list(shapes(binary, t…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by brendancol
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants