How to match the extent of one raster to another?

06-05-2020 04:51 AM
New Contributor


I have got an georeferenced original image, coming from ArcGIS. On a copy of this raster I perform various calculations using Numpy. I save this copy with Skimage as a tif file - the georeferencing is logically lost.

print('Orig: ({} {}) ({} {})'.format(orig.extent.XMin, orig.extent.YMin, orig.extent.XMax, orig.extent.YMax))
print('Copy: ({} {}) ({} {})'.format(copy.extent.XMin, copy.extent.YMin, copy.extent.XMax, copy.extent.YMax)

>> Orig: (345750.0 5645250.0) (346000.0 5645500.0)
>> Copy: (-0.5 -511.5) (511.5 0.5)

I want to try to get the georeferencing of the original raster into the copy for quite a while now. However, the extent attribute of an object is not editable.

I tried to set the environement's extent to the orignal image's extent - nothing changend.

arcpy.env.extent = orig.extent
arcpy.CopyRaster_management(copy, path)

Running the following snippet applies the changes to the extent.

copy = copy*1
print('Copy: ({} {}) ({} {})'.format(copy.extent.XMin, copy.extent.YMin, copy.extent.XMax, copy.extent.YMax))

>> Copy: (345750.0 5645250.0) (346000.0 5645500.0)

arcpy.CopyRaster_management(copy, path)

After saving my copy with CopyRaster-function i got a "blank" raster without any data.

I think i have to adjust the env's cellsize, crs, etc., too?

0 Replies