ExtractByMask issue

578
6
Jump to solution
12-21-2020 09:15 AM
AndreaGiglio
New Contributor II

Hi everyone,

By running the code:

import arcpy

#Local variables

v19830101_tif = "C:\\Users\\me\\blablabla\\Dropbox\\Input\\Rainfall1\\19830101.tif"

# Process: Extract by Mask
arcpy.gp.ExtractByMask_sa(v19830101_tif, Fish2_shp__3_, clip)

I get the following error:

ERROR 000861: Input raster: C:\\Users\\me\\blablabla\\Dropbox\\Input\\Rainfall1\\19830101.tif is not valid

Does anyone know why? I tried to save the file in a local folder (instead of Dropbox) but I get the same error.

I am using ArcGis Pro 2.4.0

Andrea

1 Solution

Accepted Solutions
DavidPike
MVP Frequent Contributor

You have saved/copied the tif to that location, and the shapefile in the other location? Not just tried using those paths I hope?

Does the .tif file open and display in ArcGIS fine?  How do the paths show up in the properties of the datasets when you view them in arcgis?

Also, this script is very simplistic, is it part of a larger script , or to be added to an iterator?  I ask because you can easily run the tool instead in ArcGIS.  Another troubleshoot would be to initially run the tool in ArcGIS with those inputs.

View solution in original post

0 Kudos
6 Replies
DavidPike
MVP Frequent Contributor

Is there any reason behind using the gp tool rather than Extract by Mask (Spatial Analyst)—ArcGIS Pro | Documentation.

You've not shown all your parameters in the code, and it's unformatted, also consider renaming your variables to something readable.

I'm guessing it was copied from model builder?  

AndreaGiglio
New Contributor II

Exactly! It was copied from model builder (which was not created by me and it was from 2 years ago so I guess that also the software's version is older than the one I am using). Actually, I also tried this:

outExtractByMask = arcpy.sa.ExtractByMask(v19830101_tif , Fish2_shp__3_)

but still it is showing the same error. Regarding the other parameters, Fish2_shp__3_ is the area to extract while I guess clip are the clip features but I think the problem is with the .tif file. Can it be a problem of *.tif file extension?

Also, what do you mean by "renaming the variable to something readable"? (I am sorry for the very basic question but I am totally new to ArcGis)

Thanks a lot for your help,

Andrea

 

 

DavidPike
MVP Frequent Contributor

I would definitely stay away from your dropbox for both the input and output destinations until you get it working, then you can try to adjust those locations later.

 

You'll see below how giving logical variable names makes the code more readable, especially when looking at the tool inputs.

 

import arcpy

input_raster = r"C:\Users\me\19830101.tif"
clip_feature = r"C:\Users\me\fish2.shp"
out_path = r"C:\Users\me\extracted.tif"

outExtractByMask = arcpy.sa.ExtractByMask(input_raster, clip_feature)
outExtractByMask.save(out_path)

 

AndreaGiglio
New Contributor II
input_raster= r"C:\Users\me\Desktop\19830101.tif"
clip_feature=r"C:\Users\me\Desktop\Fish2.shp"
out_path = r"C:\Users\me\Desktop\extracted.tif"
outExtractByMask = arcpy.sa.ExtractByMask(input_raster, clip_feature)
outExtractByMask.save(out_path)

 

With the code above I got the following error (the part in red is the error I was getting with the very first code):


Traceback (most recent call last):
File "<string>", line 4, in <module>
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\sa\Functions.py", line 7337, in ExtractByMask
in_mask_data)
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\sa\Utils.py", line 53, in swapper
result = wrapper(*args, **kwargs)
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\sa\Functions.py", line 7333, in Wrapper
out_raster)
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\_base.py", line 506, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: ERROR 000861: Input raster: C:\Users\me\Desktop\19830101.tif is not valid.
Failed to execute (ExtractByMask).

0 Kudos
DavidPike
MVP Frequent Contributor

You have saved/copied the tif to that location, and the shapefile in the other location? Not just tried using those paths I hope?

Does the .tif file open and display in ArcGIS fine?  How do the paths show up in the properties of the datasets when you view them in arcgis?

Also, this script is very simplistic, is it part of a larger script , or to be added to an iterator?  I ask because you can easily run the tool instead in ArcGIS.  Another troubleshoot would be to initially run the tool in ArcGIS with those inputs.

0 Kudos
AndreaGiglio
New Contributor II

Yes, I did (the doubt was legitimate though, given my level)! I realized that the tiff file does not even open with Photo Viewer therefore I must have done something wrong when unzipping or renaming the original files

Thanks for the help and for the patience,

Andrea

0 Kudos