You're writing a floating point array as an unsigned 8 bit integer. Try
src = rasterio.open('raster2.tif')
profile = src.profile
with rio.open('test.tif', 'w', **profile) as dst:
dst.write(new_raster, 1) # No need to cast to int, as profile is already float32
or if that doesn't work, enforce the casting using .astype(rio.float32) instead of your ...
You probably have a null geometry, try filtering them out.
import geopandas as gpd
gdf = gpd.read_file("roads.shp")
gdf = gdf[~(gdf['geometry'].is_empty | gdf['geometry'].isna())]
stats = zonal_stats(gdf['geometry'], "raster.tif", stats="count min mean max median")
Note this code example is completely untested and may not ...
It's often easier to use the GDAL python wrappers. See my attempt below. If you still get errors, check that both raster and shapefile have geographic information (i.e. you can overlap them in QGIS or something like that).
from osgeo import gdal
from osgeo import ogr
def dump_poly(raster_fname, vector_fname, ifeat):
# New filename. Assumes input raster ...
I do not know "program A" but certainly you can create more bands with VRT. File "test.tif" is a 3-band image.
gdal_translate -of VRT -b 1 -b 1 -b 1 -b 1 -b 1 test.tif 5band.vrt
Driver: VRT/Virtual Raster
Size is 12000, 12000
Coordinate System is:
Band 1 Block=256x256 Type=Byte, ...