|
POST
|
Hi Simon I've been using the Spatial Analyst Supplemental Tools for quiet a while now for my hydrological model for determining average catchment slopes. When I determine watersheds for my rail or road alignments, they overlap of course. Graph Coloring is explained by William Huber: Exploding Overlapping Polygons into Non Overlapping Polygons. I suggest you look at repairing the geometry of your polygons or reload them into a new Feature Class. As I've not experienced any error message while using the following. I've attached portion of my python script below that I use daily for my hydrological modelling: '''
Created on Feb 1, 2016
@author: PeterW
'''
# import site-packages and modules
import arcpy
# import custom python toolboxes
arcpy.ImportToolbox("E:\Python\Downloaded\general\SpatialAnalystSupplementalTools\Spatial Analyst Supplemental Tools.pyt")
# set input and output arguments
raster_folder = arcpy.GetParameterAsText(1)
fgdb = arcpy.GetParameterAsText(2)
# set variables
drain = "{}\\{}".format(fgdb, "Watersheds")
slp = "{}\\{}".format(raster_folder, "slope")
avgslp = "{}\\{}".format(fgdb, "avgslp")
# determine the average slope for each watershed
arcpy.AddMessage("Processing Average Catchment Slope")
arcpy.ZonalStatisticsAsTable02_sas(drain, "HydroID", slp, avgslp, "MEAN", "DATA") #@UndefinedVariable
... View more
02-18-2016
01:28 PM
|
0
|
0
|
3674
|
|
POST
|
Hi Bill The following article might help you. Scheduling a Python script.
... View more
02-17-2016
02:34 PM
|
1
|
2
|
884
|
|
POST
|
I've been using Eclipse\PyDev for the last five years and have decided to up my game. I'm currently setting up Python Virtualenv and GitHub to manage my Python Code. I've attached a print screen of my Eclipse\PyDev structure. This allows me to run any of my Python or ArcPy scripts outside of ArcGIS as well as schedule my scripts to run at any given time.
... View more
02-17-2016
12:38 PM
|
0
|
5
|
3383
|
|
POST
|
Hi Jerry The reason that its writing the results out to "C:\GIS_DATA" is that the export path has been set to that directory manually. What you want to do is set the input_mxd and output_folder to become arguments that you can supply as the user of the script. You need to set your input_mxd and output_folder variables to arcpy.GetParameterAsText to change the input and output arguments for each time you run the script as a tool within ArcGIS. I've cleaned your code a bit and gave explanations why. '''
Created on Feb 17, 2016
Export Data Driven Pages
to jpegs
@author: PeterW
'''
# I've removed the unnecessary modules that you imported
# import modules and site-packages
import os
import arcpy
# set input and output arguments
input_mxd = arcpy.GetParameterAsText(0)
output_folder = arcpy.GetParameterAsText(1)
field_name = r"DIST_NAME"
# export each data driven page out as a jpeg
mxd = arcpy.mapping.MapDocument(input_mxd)
for i in range(1, mxd.dataDrivenPages.pageCount + 1):
mxd.dataDrivenPages.currentPageID = i
row = mxd.dataDrivenPages.pageRow
# I've created a variable page_name to store the current page name
page_name = row.getValue(field_name)
arcpy.AddMessage("Processing {}".format(page_name))
# I've used os.path.join to join the path and file name for the output jpegs
arcpy.mapping.ExportToJPEG(mxd, os.path.join(output_folder, page_name + ".jpg"))
del mxd
... View more
02-17-2016
12:18 PM
|
2
|
3
|
4565
|
|
POST
|
Hi Dan Thanks for the feedback, I found a solution on the USGS site that might help anyone else wishing the setup Eclipse\PyDev and Virtualenv. Calling arcpy from an external virtual Python environment Regards
... View more
02-17-2016
12:22 AM
|
1
|
2
|
2820
|
|
POST
|
I've been using Eclipse and PyDev as my IDE environment for Python over the last few years. I've not used a virtual environment or git repository up until now as my code has been simple scripts to automate daily tasks within ArcGIS. I have found that managing my scripts and more recently my python programs is becoming more cumbersome. I have Python 2.7.5 32 bit as well as 64 bit installed. I'm using more and more 3rd party site packages such as ArcHydro ; HEC-RAS ; HEC-GeoHMS ; HEC-GeoRAS ; TauDEM to mention just a few. Some of my code is 32 bit as there are no 64 bit packages available or some of ArcGIS tools won't run within 64 bit. My hydrological python programs are 64 bit to take advantage of the additional memory and threading. I'm looking for advice from the community on best practices (pythonic) for setting up a python development environment using Eclipse\PyDev with Virtualenv and a Git Repository. Based on my current online research its not that straight forward to get the Python versions installed by ArcGIS to work within a virtual environment using Python virtualenv.
... View more
02-15-2016
11:24 AM
|
0
|
4
|
6219
|
|
POST
|
Dear Meng Xu I recommend that you have a look at the following Toblers Hiking Function posted by Nico. The python module that I developed incorporates Toblers Hiking Function as a Vertical Factor Table. This with the DEM determines the speed that one can walk as the slope changes including upslope vs downslope as well as direction. I merely created an euclidean distance raster based on my road network feature class as an additional cost factor to add as an impedance of movement off the road network, thereby ensuring the best path was along the road network. I unfortunately don't think that you can merely adjust the vertical factor table to increase the speed at which one can travel as the variables for vehicles vs walking are not the same. you might need to do some more research through google on models that have been developed for cars using the Path Distance Tool and how they developed cost rasters and vertical factor table. Hope the following helps.
... View more
02-11-2016
08:52 AM
|
0
|
0
|
4894
|
|
POST
|
I've posted a discussion under Python Python: Geo-HMS "Centroidal Longest Flowpath" and wondering if the Arc Hydro community might be able to assist. Thanks in advance.
... View more
02-03-2016
09:57 AM
|
0
|
0
|
2951
|
|
POST
|
I've posted a discussion under Python Python: Geo-HMS "Centroidal Longest Flowpath" and wondering if the Arc Hydro community might be able to assist. Thanks in advance.
... View more
02-03-2016
09:56 AM
|
0
|
0
|
3097
|
|
POST
|
I'm trying to get Geo-HMS "Centroidal Longest Flowpath" to run from within Python. My current configuration is: ArcGIS 10.2.2 ArcHydro 10.2.0.191 HEC-GeoHMS 10.2.0.41 HEC-GeoRAS 10.2.0.12 HEC-RAS 4.1.0 I've generated a python module using the following code: import arcpy
import arcpy.toolbox_code
arcpy.toolbox_code.generate_toolbox_module(r'C:\Program Files (x86)\ArcGIS\Desktop10.2\ArcToolbox\Toolboxes\GeoHMS Tools.tbx', r'C:\Program Files (x86)\HEC\HEC-GeoHMS\bin\GeoHMSTools.py' False, False, True) I then generated a python path file that points to the GeoHMSTools.py module file under the following directory: C:\Python27\ArcGIS10.2\Lib\site-packages\GeoHMSTools.pth I'm able to import GeoHMSTools within my Python IDE (Eclipse) as well as within ArcMap Python Interpreter Window and all the tools are visisble. When I try to run Centroidal Longest Flowpath from within Python I receive the following error message after Python crashes: '''
Created on Feb 2, 2016
@author: PeterW
'''
import arcpy
import GeoHMSTools
subbasin = r"E:\Python\Temp\Model02\Model02.gdb\Layers\Subwatershed"
centroid = r"E:\Python\Temp\Model02\Model02.gdb\Layers\Centroid"
longestflowpath = r"E:\Python\Temp\Model02\Model02.gdb\Layers\LongestFlowPath_2D"
centroidallongestflowpath = r"E:\Python\Temp\Model02\Model02.gdb\Layers\CentroidalLongestFlowPath10"
GeoHMSTools.CentroidalLongestFlowpath(subbasin, centroid, longestflowpath, centroidallongestflowpath) Unhandled Exception: System.ArgumentException: The object's type must be __ComObject or derived from __ComObject.
Parameter name: o
at System.Runtime.InteropServices.Marshal.ReleaseComObject(Object o)
at ESRI.APWR.HECGeoHMS10.GPCentroidalLongestFlowPath.Finalize() Any help in being able to resolve the following will be appreciated.
... View more
02-02-2016
11:10 PM
|
1
|
3
|
5606
|
|
POST
|
Hi Luke and Dan I'm going to close the following as i feel the error messages that I'm receiving while trying to call Geo-HMS tools within Python are due to HEC-GeoHMS and not the Python Module that I've created. I've did a bit of research and found that ESRI has placed the ArcHydroTools.py module under the following directory: C:\Program Files\ESRI\WaterUtils\ArcHydro\Bin They generated a path file under the following directory that points to the module: C:\Python27\ArcGISx6410.2\Lib\site-packages So I've replicated the same for HEC-GeoHMS and I'm able to call GeoHMSTools within Python. The Centroidal Longest Flowpath tool still fails though and crashes Python. I'm going to open a new thread to see if anyone has gotten Centroidal Longest Flowpath to run from within Python. Thanks for all your assisstance.
... View more
02-02-2016
09:47 PM
|
0
|
0
|
5663
|
|
POST
|
Hi Luke I created the following directory and placed my GeoHMSTools.py module within the following directory. When I try to import GeoHMSTools module within Python it says it cant find the following module. >>> import arcpy
>>> import GeoHMSTools
Runtime error
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named GeoHMSTools
>>> I tried adding the path of the following directory to the environment settings, but it had no effect.
... View more
02-02-2016
09:02 PM
|
0
|
0
|
5663
|
|
POST
|
Hi Luke Thanks for getting back to me. I don't seem to have the following directory under C Drive: %AppData%\Python\Python27\site-packages. I've run the script tool within ArcMap and ArcCatalog with success. I tried Copy As Python Snippet and ran it within the ArcMap Python Interpreter: import arcpy
import GeoHMSTools
arcpy.CentroidalLongestFlowpath_geohms(in_subbasin_features="E:/Python/Temp/Model02/Model02.gdb/Layers/Subwatershed",in_centroid_features="E:/Python/Temp/Model02/Model02.gdb/Layers/Centroid",in_longestflowpath_features="E:/Python/Temp/Model02/Model02.gdb/Layers/LongestFlowPath_2D",out_centroidallongestflowpath_raster="E:/Python/Temp/Model02/Model02.gdb/Layers/CentroidalLongestFlowPath1")
Runtime error
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute 'CentroidalLongestFlowpath_geohms' As you can see the syntax is different for some reason or other, than when I call the tool from within the ArcMap Python Interpreter: import arcpy
import GeoHMSTools
GeoHMSTools.CentroidalLongestFlowpath(r'E:\Python\Temp\Model02\Model02.gdb\Layers\Subwatershed', r'E:\Python\Temp\Model02\Model02.gdb\Layers\Centroid', r'E:\Python\Temp\Model02\Model02.gdb\Layers\LongestFlowPath_2D', r'E:\Python\Temp\Model02\Model02.gdb\Layers\CentroidalLongestFlowPath2')
Runtime error Traceback (most recent call last): File "<string>", line 1, in <module> File "C:\Program Files (x86)\ArcGIS\Desktop10.2\ArcToolbox\Scripts\GeoHMSTools.py", line 125, in CentroidalLongestFlowpath raise e ExecuteError: System.Runtime.InteropServices.COMException (0x8002000A): Out of present range. (Exception from HRESULT: 0x8002000A (DISP_E_OVERFLOW)) at ESRI.ArcGIS.esriSystem.IStepProgressor.set_StepValue(Int32 Step) at ESRI.APWR.HECGeoHMS10.GPCentroidalLongestFlowPath.CentroidalLongestFlowpathWk(ApLayers apLayers, Int32 debug, ITrackCancel& trackcancel, IGPMessages& messages, String& exMessage) Failed to execute (CentroidalLongestFlowpath). I have found that although the GeoHMSTools.CentroidalLongestFlowpath() failed, if I open the results window and open the failed script and rerun it, it completes successfully.
... View more
02-02-2016
01:32 AM
|
0
|
3
|
5663
|
|
POST
|
Hi Luke Thanks for the following. I copied the GeoHMSTools.py under the following directory: C:\Program Files (x86)\ArcGIS\Desktop10.2\ArcToolbox\Scripts I was then able to import GeoHMSTools within Python, but when I try to run any of the tools Python crashes and I recieve the following error message: GeoHMSTools.CentroidalLongestFlowpath(r'E:\Python\Temp\Model02\Model02.gdb\Layers\Subwatershed',r'E:\Python\Temp\Model02\Model02.gdb\Layers\Centroid' , r'E:\Python\Temp\Model02\Model02.gdb\Layers\LongestFlowPath_2D', r'E:\Python\Temp\Model02\Model02.gdb\Layers\CentroidalLongestFlowPath6')
Runtime error Traceback (most recent call last): File "<string>", line 1, in <module> File "c:\program files (x86)\arcgis\desktop10.2\ArcToolbox\Toolboxes\GeoHMSTools.py", line 113, in CentroidalLongestFlowpath ExecuteError: System.Runtime.InteropServices.COMException (0x8002000A): Out of present range. (Exception from HRESULT: 0x8002000A (DISP_E_OVERFLOW)) at ESRI.ArcGIS.esriSystem.IStepProgressor.set_StepValue(Int32 Step) at ESRI.APWR.HECGeoHMS10.GPCentroidalLongestFlowPath.CentroidalLongestFlowpathWk(ApLayers apLayers, Int32 debug, ITrackCancel& trackcancel, IGPMessages& messages, String& exMessage) Failed to execute (CentroidalLongestFlowpath).
... View more
02-01-2016
10:48 PM
|
2
|
5
|
5663
|
| Title | Kudos | Posted |
|---|---|---|
| 3 | 01-16-2012 02:34 AM | |
| 1 | 05-07-2016 03:04 AM | |
| 1 | 04-10-2016 01:09 AM | |
| 1 | 03-13-2017 12:27 PM | |
| 1 | 02-17-2016 02:34 PM |
| Online Status |
Offline
|
| Date Last Visited |
03-04-2021
12:50 PM
|