Re: reproject from a tiff to another tiff gives "destination band 1 appears to be read only"

Sean Gillies


It's a good thing that you opened the destination (population) file in "r" mode. Otherwise, it could have been overwritten.

You must create an output array for the reprojected data and pass it as the second argument, along with dst_crs and dst_transform keyword arguments.

with"population") as population,"lights") as lights:

    reprojected = numpy.zeros(population.shape, dtype=lights.dtypes[0])

    reprojected, transform = rasterio.warp.reproject(, 1), reprojected,, dst_transform=population.transform)

The reprojected array will be aligned with and have the same shape as

On Mon, Nov 11, 2019 at 6:28 AM <simonm3@...> wrote:
Please can someone explain how I align a tiff file of lights with another of population to create two numpy arrays the same size and aligned. I tried:

    population =
    lights =
    res = rio.warp.reproject(,1),,1))

This gives "CPLE_IllegalArgError: Destination band 1 appears to be read-only."

I was expecting it to read the meta data (crs, height, width and affine transform) from source and destination then return something with the data of source but the shape of destination.

Sean Gillies

Join to automatically receive all group messages.