Hot answers tagged

5

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 ...


2

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 ...


1

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 ...


1

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 gdalinfo 5band.vrt Driver: VRT/Virtual Raster Files: 5band.vrt test.tif Size is 12000, 12000 Coordinate System is: ... Band 1 Block=256x256 Type=Byte, ...


1

Start and end indexes should be integer and color should be (c1, c2, c3, c4). Docs Link colors.CreateColorRamp(1, (82, 44, 15, 255), 2, (255, 128, 44, 255))


Only top voted, non community-wiki answers of a minimum length are eligible