ERROR 000732: Input Features: Dataset _ does not exist or is not supported

4706
6
Jump to solution
03-02-2017 12:19 PM
CharlotteMays1
New Contributor

I have seen a few questions with this error, but none of the fixes worked for me.  

I am trying to use the clipping data management tool to clip raster files to a shapefile of polygons.  I have also tried to do the same thing with the Extract by Mask tool and I got the same error.

This is the error: ERROR 000732: Output Extent: Dataset PerRanktop10percentTPA2001.shp does not exist or is not supported
Failed to execute (Clip).

The error says that the shapefile PerRanktop10percentTPA2001.shp does not exist, but when I use the print statement in line 39 it prints out this file, so it definitely exists and the script can find it. 

Hope someone can help!

Here's my code:

#import necessary packages
import arcpy
import os
from arcpy import env


#sets workspace to ADS folder
env.workspace = "Z:/Fall2016_GlacierNationalParkClimate/Term2/Charlotte/ADS/ADS_PerRanktop10percentTPA2001"
#turns overwrite on
env.overwriteOuput = True
#lists shapefiles
shapefiles = arcpy.ListFeatureClasses("*")
print (shapefiles)
#changes year to match ADS year
shapefile = shapefiles[0]
year = shapefile [22:26]
print (year)

#sets workspace to rasters folder
env.workspace = "Z:/Fall2016_GlacierNationalParkClimate/Term2/Charlotte/RGI/RGI_2000_2003"
env.overwriteOuput = True

#Lists folders in workspace
folders = arcpy.ListWorkspaces()
for folder in folders:
     env.workspace = folder
     env.overwriteOuput = True
     #lists rasters in all folers
     rasters = arcpy.ListRasters("*", "tif")
     print (rasters)

     for raster in rasters:
          #Names inputs and outputs for each raster in each folder
          in_raster = rasters[0]
          in_template_dataset = shapefiles[0]
          out_raster = ("clip_ads_" + year + raster.split(".")[0] + ".tif")
          output_path = "Z:/Fall2016_GlacierNationalParkClimate/Term2/Charlotte/RGI_ADS_clip_output"
          
          print(in_template_dataset)

          #runs clip data management 
          clip = arcpy.Clip_management(in_raster, "#", output_path + out_raster, in_template_dataset, "#", "ClippingGeometry","NO_MAINTAIN_EXTENT")‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
1 Solution

Accepted Solutions
DarrenWiens2
MVP Honored Contributor

You collect the name (not full path) of the shapefiles in FolderA (i.e. 'FolderA\FileA'). Then, collect a list of FolderB's. Then, try to refer back to the first file (in_template_dataset), after setting the workspace to FolderB, so it is looking for FileA in FolderB, when it should be looking for FileA in FolderA, unless it just so happens that there is also a file with name FileA in FolderB.

View solution in original post

0 Kudos
6 Replies
DanPatterson_Retired
MVP Emeritus

three things...

("clip_ads_" + year ... year should probably be str(year) unless it is text already

try putting the source and destination files in much shorter paths.

secondly, you switch the environment workspace twice, you might want to ensure in your script that the print statements you use to confirm locations are still respected/reflected at the various stages of the script just prior to using them subsequently.

These issues are usually path name associated.

0 Kudos
CharlotteMays1
New Contributor

I tried making the source and destination paths a lot shorter and I checked with my print statements that the locations are still confirmed right before running Clip... still didn't work and I'm still getting the same error.

0 Kudos
DarrenWiens2
MVP Honored Contributor

You collect the name (not full path) of the shapefiles in FolderA (i.e. 'FolderA\FileA'). Then, collect a list of FolderB's. Then, try to refer back to the first file (in_template_dataset), after setting the workspace to FolderB, so it is looking for FileA in FolderB, when it should be looking for FileA in FolderA, unless it just so happens that there is also a file with name FileA in FolderB.

0 Kudos
CharlotteMays1
New Contributor

So how could I set it up so that the inputs to the Clip function are coming from two different folders? I thought if I defined a workspace once I wouldn't have to do it again.

Or how could I collect the full path of the shapefiles in FolderA?

0 Kudos
CharlotteMays1
New Contributor

It worked!

I changed the in_template_dataset to be equal to the absolute path of the shapefile I was calling.

in_template_dataset = "Z:/Fall2016_GlacierNationalParkClimate/Term2/Charlotte/ADS/ADS_PerRanktop10percentTPA2001/PerRanktop10percentTPA2001.shp"

Thank you so much!

0 Kudos
DarrenWiens2
MVP Honored Contributor

Glad it worked out in the end. You can collect the full path into a list like this:

import os
workspace = arcpy.env.workspace = r'C:\junk'
shps = [os.path.join(workspace,file) for file in arcpy.ListFeatureClasses('*')]

Basically, as it builds the list, it joins the workspace to the file name.

0 Kudos