Topics

reproject on numpy array

Sean Gillies
 

Hi,

The thing that is tripping Guy up is that reproject has an optional init_dest_nodata keyword argument that defaults to True: the output array is filled with the nodata value (0) before warped pixels are copied over. Guy, if you pass init_dest_nodata=False you will get the results you expect.


On Tue, Dec 18, 2018 at 10:06 AM Alan Snow <alansnow21@...> wrote:
Hi Guy,

The dest array will be overwritten by the reprojected data based on your source array. So, to get ones in the destination, you would need to modify the source array to have ones in it.

Hope that helps,
Alan



--
Sean Gillies

Alan Snow
 

Hi Guy,

The dest array will be overwritten by the reprojected data based on your source array. So, to get ones in the destination, you would need to modify the source array to have ones in it.

Hope that helps,
Alan

Guy Doulberg
 

Hi guys

I am trying to use a method `rasterio.warp.reproject`

I create a source numpy array full of zeros and dest numpy array full of ones, I reprojected using the nearset resmapling and src_nodata=0
The dest array became all zeros,

I expected it to be all ones, since the array didn't have any valid data

What am I missing?

I am running this code:


data =  np.zeros((1,1000, 1000))
dest = np.ones_like(data)
reproject(data, dest, src_transform=raster.affine,dst_transform=projected.affine, src_crs=raster.crs, dst_crs=projected.crs, resampling=Resampling.nearest, src_nodata=data[0][0][0])
print(src_transform,"\n",dst_transform,"\n", src_crs, "\n",dst_crs)
print(data)
print(dest)

and this is the output I am getting

| 10.00, 0.00, 640590.00|
| 0.00,-10.00, 5839580.00|
| 0.00, 0.00, 1.00| 
 | 0.00, 0.00,-73.41|
| 0.00,-0.00,-37.58|
| 0.00, 0.00, 1.00| 
 +init=epsg:32718 
 +init=epsg:4326
[[[0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]
  ...
  [0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]]]
[[[0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]
  ...
  [0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]]]


What am I missing?