I have 1 dimension numpy array that has no geographical information. The numpy array was originally satellite image that I have manipulated in order to get this 1 dimension array.
I have the crs and transform of this array.
However, until now, in order to have geographic data on this array I had to write it as tiff and only then I could get back the geographical data and do things such as crop the raster and more.
I know there is option to reproject an array with no geographical data, as mentioned here . I have tried to do this with my data as following, based on the doc:
src_shape = (886, 1138)
rows, cols = (886, 1138)
d = 1.0/240 # decimal degrees per pixel
# The following is equivalent to
# A(d, 0, -cols*d/2, 0, -d, rows*d/2).
src_transform = A.translation(-cols*d/2, rows*d/2) * A.scale(d, -d)
src_crs = {'init': 'EPSG:4326'}
source = img_pred
dst_shape = (886, 1138)
dst_transform = rasterio.transform.from_bounds(*bbox, width= bbox_size[1], height= bbox_size[0])
# this gets the transform which is in this case : Affine(0.00011618510158013974, 0.0, -44.75374, 0.0, -7.050087873462236e-05, -6.80845)
dst_crs = rasterio.crs.CRS.from_dict(init='epsg:4326')
destination = np.zeros(dst_shape, np.uint8)
reproject(
img_pred,
destination,
src_transform=src_transform,
src_crs=src_crs,
dst_transform=dst_transform,
dst_crs=dst_crs,
resampling=Resampling.nearest)
Then I get new array with values 0:
So my question is : how do I get my array with the values reprojected correctly?
I assume that the problem might be in the definition of the original CRS, (src_crs
), as my numpy array has no crs at all, but not sure if this is the reason.
dst_crs = rasterio.crs.CRS.from_dict(init='epsg:4326')
to simply{'init': 'EPSG:4326'}
?