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

Sean Gillies
 

Hi,

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 rasterio.open("population") as population, rasterio.open("lights") as lights:

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

    reprojected, transform = rasterio.warp.reproject(rasterio.band(lights, 1), reprojected, dst_crs=population.crs, dst_transform=population.transform)

The reprojected array will be aligned with and have the same shape as lights.read(1).

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 = rio.open(population)
    lights = rio.open(lights)
    res = rio.warp.reproject(rio.band(lights,1), rio.band(population,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 main@rasterio.groups.io to automatically receive all group messages.