4

I am using ArcGIS 10.3 Desktop to write a script tool to, among other things, extract raster data using a mask.

I keep getting these errors:

ExecuteError: ERROR 000875: Output raster: C:\Users02183940\Documents\Thesis_Data\soil_data\Calculated_Rasters\IL_rasters.gdb\Extract_ph_s1's workspace is an invalid output workspace. ERROR 000581: Invalid parameters. Failed to execute (ExtractByMask).

My code:

import arcpy
from arcpy import env
from arcpy.sa import *
arcpy.env.overwriteOutput = True

ebm_in_raster = r'C:\Users\a02183940\Documents\Thesis_Data\soil_data\Calculated_Rasters\ph_statsgo'
ebm_mask_data = r'C:\Users\a02183940\Documents\Thesis_Data\Cropland_Data_Layer\noda_1_10-15'

arcpy.CheckOutExtension("Spatial")
env.workspace ='C:\Users\a02183940\Documents\Thesis_Data\soil_data\Calculated_Rasters\IL_rasters.gdb'

outExtractByMask = ExtractByMask(ebm_in_raster, ebm_mask_data)
outExtractByMask.save('C:\Users\a02183940\Documents\Thesis_Data\soil_data\Calculated_Rasters\ph_in_crl')

What are the requirements for a valid output workspace for this tool? I don't think it is an issue of raster name length or use of unsupported characters as I've tried a few different things and none of them have worked.

3
  • What format are your input data (i.e. ebm_in_raster and ebm_mask_data)? – Aaron Jun 27 '16 at 23:40
  • Can you try changing the dash to underscore at the mask filename? – Delonix R. Jun 27 '16 at 23:50
  • The input raster and mask raster are both in grid format. It looks like you recommend using .img instead? I'll try that. – Neil Jun 28 '16 at 17:08
3

There is no need to define the workspace if you are explicitly defining the variable paths. Additionally, you are formatting the paths incorrectly--try using r'C:\path\to\your\data'.

I would recommend writing the output raster to .tif or .img format. As your script is currently configured, it is trying to output a grid format raster.

This is how I would write the script:

import arcpy
from arcpy import env
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")

arcpy.env.overwriteOutput = True

ebm_in_raster = r'C:\path\to\in_raster.img'  # Assuming a .img source raster
ebm_mask_data = r'C:\path\to\mask_data.img'  # Assuming a .img mask

outExtractByMask = ExtractByMask(ebm_in_raster, ebm_mask_data)
outExtractByMask.save(r'C:\path\to\output_raster.img')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.