Expanding a raster extent with nodata values using arcpy?

04-30-2020 03:16 PM
New Contributor III

Is there a simple way to expand the extent of an existing raster (using nodata values)?

I have explored the following:

Extending an existing raster extent. 

Increasing raster extent by filling extent with no data using ArcGIS Desktop without Spatial Analyst... 

And I came across another posting (sorry, the link is not readily coming up) in which someone (Dan Patterson I think) recommended combining the starting (small) raster, and overlaying with another larger raster.  Makes sense, and I have run the following:

# Expand the size of the data raster, using a NoData raster of the correct extent.
emptyraster = Raster("examplerasterofdesiredsize") # Make a copy of a raster that is of the correct size
emptyraster = SetNull("examplerasterofdesiredsize","examplerasterofdesiredsize","VALUE = 0") # The raster being used is already populated with the value 0, this is converted to NoData
emptyraster.save("emptyraster") # save the no data raster

So far so good.

outputraster = Con("smallraster","smallraster","emptyraster") # Where there is a value for the small raster, use it, otherwise use the value from the larger raster

Unfortunatly, the outputraster retains the same extent as the small raster.  There are ways to change this going through the GUI menus, but I would rather automate the process.

Should the Con function work?  Thanks.

0 Kudos
1 Reply
MVP Esteemed Contributor

geoprocessing extent can be set

Extent (Environment setting)—Geoprocessing | Documentation 

If you want to derive it from an existing raster, derive it from its properties (extent of a raster is read-only) but set it using the environment settings as in the code example in the above link

0 Kudos