Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a proplem with arc hydro in arcpy,i want to create a simple script where automated some tools from archydro in arcpy.. I use arcmap 10.1 and python 1.7,my import is one dem and my export is a 6 raster file (fill,fdr,fac,cat,str,strlink) and run ok without proplem but if I add one more tool cachmented to polygon that converts a raster file to polygon feature class then show me error i import this python script on arcmap

import arcpy

arcpy.ImportToolbox("C:\Program Files (x86)\ArcGIS\Desktop10.1\ArcToolbox\Toolboxes\Arc Hydro Tools.tbx", "archydrotools")
#Set Ouput Names
fill=arcpy.GetParameterAsText(0) + '\\fill'
Fdr=arcpy.GetParameterAsText(0) + '\\fdr'
Fac=arcpy.GetParameterAsText(0) + '\\fac'
Str=arcpy.GetParameterAsText(0) + '\\Str'
StrLnk=arcpy.GetParameterAsText(0) + '\\StrLnk'
Cat=arcpy.GetParameterAsText(0) + '\\Cat'
Catchment=arcpy.GetParameterAsText(0) + '\\Catchment'

# Local variables:
arcpy.CheckOutExtension("spatial")
arcpy.env.overwriteOutput = True
arcpy.env.workspace = arcpy.GetParameterAsText(0)
dem = arcpy.GetParameterAsText(1)
# Process: Fill Sinks
arcpy.FillSinks_archydrotools(dem, fill, "", "", "ISSINK_YES")
# Process: Flow Direction
arcpy.FlowDirection_archydrotools(fill, Fdr, "")
# Process: Flow Accumulation
arcpy.FlowAccumulation_archydrotools(Fdr, Fac)
# Process: Stream Definition
arcpy.StreamDefinition_archydrotools(Fac, "", Str, "1")
# Process: Stream Segmentation
arcpy.StreamSegmentation_archydrotools(Str, Fdr, StrLnk, "", "")
# Process: Catchment Grid Delineation
arcpy.CatchmentGridDelineation_archydrotools(Fdr, StrLnk, Cat)
# Process: Catchment Polygon Processing
arcpy.CatchmentPolyProcessing_archydrotools(Cat, Catchment)

my error

but my export file in the folder they become export the all files regular

my proplem is the last command because is a feature class I think

any idea ?

share|improve this question
1  
Can you please use copy/paste to get sufficient lines of the error message captured and included so that there is a starting point for people to try and spot what is astray. "Failed to execute (Script)" tells you/us next to nothing - I suspect you want to know why it failed to execute. To see the whole tool output simply use the scroll bar on the dialog that you have screenshot. –  PolyGeo Mar 15 at 10:28
    
You have now included your script but what is the more complete error message? –  PolyGeo Mar 15 at 19:55
    
yes is a complete message from arcmap –  user27818 Mar 15 at 23:13
    
What happens when you run your script from an IDE like Python with a hardwired values for the workspace that you are setting from the parameter of your dialog? You should see a more informative error message then. –  PolyGeo Mar 16 at 2:16
    
if run from python ide showed me that error Traceback (most recent call last): File "C:\Users\LG\Desktop\peiramata\pythotwo.py", line 9, in <module> import arcpy ImportError: No module named arcpy –  user27818 Mar 16 at 5:42

2 Answers 2

You have now provided an error from IDLE in a Comment to your Question which is that it is:

Traceback (most recent call last): File "C:\Users\LG\Desktop\peiramata\pythotwo.py", line 9, in import arcpy ImportError: No module named arcpy

The error you are seeing has been reported several times on GIS SE (e.g. Error Importing Arcpy - Python). It seems to indicate a problem with your PATH and/or PYTHONPATH environment variables. A quick fix may be to uninstall/reinstall ArcGIS for Desktop which should set these straight.

Below this line is my earlier Answer, which I will leave here for now, and probably remove once this Question is resolved.

================================================================================

My suspicion is that the parts which work do so because you are writing the output raster files to a folder which you set using arcpy.GetParameterAsText(0).

However, when you try to run arcpy.CatchmentPolyProcessing_archydrotools I suspect that the tool is stuck between:

  • trying to write a feature class to a geodatabase when you have provided a folder workspace; and
  • trying to write a shapefile when you have not provided the *.shp extension.

Try setting this:

Catchment=arcpy.GetParameterAsText(0) + '\\Catchment.shp'

and I think it will work.

share|improve this answer
    
yes I tried export to a geodatabase,i tried and import new workspace only for cachment(shp) and i tried to *.shp extension and nothing no change for my proplem –  user27818 Mar 16 at 5:40
    
can be to *feature class extension ? –  user27818 Mar 24 at 12:53

Unfortunately, this is not a complete answer. But consider converting your script to run as a script tool or standalone in a format like this. You might need to move the SA checkout to the top, since I am not sure what dependencies come into play when importing ArcHydro and how those time. This format will make debugging easier, as you can run standalone first for debugging, then switch to a script tool when you have the script running smoothly.

#Imports at the top
import arcpy
arcpy.ImportToolbox("C:\Program Files (x86)\ArcGIS\Desktop10.1\ArcToolbox\Toolboxes\Arc Hydro Tools.tbx", "archydrotools")


def main(root, dem):
    """Takes root as the root workspace and dem as the provided dem."""
    arcpy.CheckOutExtension("spatial")
    arcpy.env.overwriteOutput = True
    arcpy.env.workspace = root
    #Set Ouput Names
    fill = root + '\\fill'
    Fdr = root + '\\fdr'
    Fac = root + '\\fac'
    Str = root + '\\Str'
    StrLnk = root + '\\StrLnk'
    Cat = root + '\\Cat'
    Catchment = root + '\\Catchment'
    # Process: Fill Sinks
    arcpy.FillSinks_archydrotools(dem, fill, "", "", "ISSINK_YES")
    # Process: Flow Direction
    arcpy.FlowDirection_archydrotools(fill, Fdr, "")
    # Process: Flow Accumulation
    arcpy.FlowAccumulation_archydrotools(Fdr, Fac)
    # Process: Stream Definition
    arcpy.StreamDefinition_archydrotools(Fac, "", Str, "1")
    # Process: Stream Segmentation
    arcpy.StreamSegmentation_archydrotools(Str, Fdr, StrLnk, "", "")
    # Process: Catchment Grid Delineation
    arcpy.CatchmentGridDelineation_archydrotools(Fdr, StrLnk, Cat)
    # Process: Catchment Polygon Processing
    arcpy.CatchmentPolyProcessing_archydrotools(Cat, Catchment)
    return

if __name__ == "__main__":
    # Expects two arguments, root folder and dem
    # This should work when called stand alone with script arguments, in idle with arguments provided, or in a script tool
    argv = tuple(arcpy.GetParameterAsText(i) for i in range(arcpy.GetArgumentCount()))
    main(*argv)
share|improve this answer
    
sorry for the stupid questions but I am very new to programming and thank you all for the answers.. root and dem is variables right ? –  user27818 Mar 17 at 20:56
    
Yeah, so what is happening there is I am making a tuple, assigned to argv, out of the supplied arguments. The tuple is unzipped (the asterisk) into arguments that are supplied to the function main(). main() expects two arguments, which will then be assigned to the variables root and dem inside the function main(). –  blord-castillo Mar 18 at 2:40
    
yea ok I'm trying to understand that,but the variables is are different categories,the root is a workspace and dem is a raster dataset, how will the import declarations in arcmap ?normaly 2 variables where one is a workspace and two is a raster dataset ? –  user27818 Mar 18 at 14:45
    
nothing i use your code and same error :( I'm desperate –  user27818 Mar 18 at 18:31
    
Execute the code in IDLE first. After it fails, import sys in the interactive window, then type and provide back here the result: sys.modules['idlelib'] –  blord-castillo Mar 18 at 18:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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