The extract by mask tool in ArcGIS has only two required arguments. The first is inRaster
and the second is inMaskData
. The filename and format of the output raster are determined automatically. The following command will achieve this:
extracted_raster = arcpy.gp.ExtractByMask_sa(input_raster, extraction_buffer)
The output raster automatically gets a name like so: Extract_{in_raster_name}
. It gets dumped into arcpy.env.workspace
as expected.
In my case, I want my output raster to get dumped into in_memory
, but I also want arcpy
to automatically name it and pick the format for me. I tried doing this using two methods. The first consists of changing the workspace to in_memory
before I run the above command:
arcpy.env.workspace = 'in_memory'
extracted_raster = arcpy.gp.ExtractByMask_sa(input_raster, extraction_buffer)
This throws an error, since it cannot find my input_raster, which is not located in_memory
:
ERROR 000865: Input raster: .\input\elsus.tif does not exist. Failed to execute (ExtractByMask).
The second method is to hardcode the output_raster
location to in_memory
. But using this method does not allow me to force arcpy
to name the file:
arcpy.gp.ExtractByMask_sa(input_raster, extraction_buffer, r'in_memory\test')
I really don't care about the file name for this intermediate data. I prefer to store the features/rasters as objects and use the variable names instead.How can I force arcpy
to handle the naming of the file, such that I only have to worry about the output object variable name?
arcpy.FeatureSet
andarcpy.Raster
objects. Then I switch my workspace toin_memory
and want to start doing my work there. However I want to still be able to invoke the input datasets at will, even if they belong to a different workspace.