POST
|
The following works in extreem cases where you don't want to recreate anything that is already on disk. If you check for the existance of something then you can choose to not create it as is done below.
#---------------------------------------------------------------------------
# delimita.py
# Created on: Thu Dec 05 2013 07:18:26 AM
#
# Description:
# Es importante que e Modelo de Elevacion tenga Proyeccion UTM, caso contrario, cambie al Sistema de Proyeccion Sugerido
# ---------------------------------------------------------------------------
# Import system modules
import sys, string, os, arcpy#arcgisscripting
# Create the Geoprocessor object
#not used in 10.1
#gp = arcgisscripting.create()
# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")
# Load required toolboxes...
arcpy.AddToolbox(r"C:\Program Files\ArcGIS\Desktop10.1\ArcToolbox\Toolboxes\Spatial Analyst Tools.tbx")
# Set the Geoprocessing environment...
#not used in working example
#arcpy.extent = "DEFAULT"
#The only input variable to this script:
dem = r"C:\Users\Me\Desktop\M130_B90\M130_B90\M130_38076DSQ_BIG.dem"
# downloaded from:
# http://estuarinebathymetry.noaa.gov/bathy_htmls/M130.html
# Local variables...
lleno = r"C:\Users\Me\Desktop\M130_B90\lleno"
direccion = r"C:\Users\Me\Desktop\M130_B90\direccion"
Output_drop_raster = ""
acumula = r"C:\Users\Me\Desktop\M130_B90\acumula"
condicional = r"C:\Users\Me\Desktop\M130_B90\condicional"
Input_true_raster_or_constant_value = "1"
Expression = "Value > 4000"
drenaje = r"C:\Users\Me\Desktop\M130_B90\drenaje.shp"
# Process: Fill...
if not os.path.exists(lleno):
arcpy.Fill_sa(dem, lleno, "")
# Process: Flow Direction...
if not os.path.exists(direccion):
arcpy.FlowDirection_sa(lleno, direccion, "NORMAL", Output_drop_raster)
# Process: Flow Accumulation...
if not os.path.exists(acumula):
arcpy.FlowAccumulation_sa(direccion, acumula, "", "FLOAT")
# Process: Con...
if not os.path.exists(condicional):
arcpy.Con_sa(acumula, Input_true_raster_or_constant_value, condicional, "", Expression)
# Process: Stream to Feature...
if not os.path.exists(drenaje):
arcpy.StreamToFeature_sa(condicional, direccion, drenaje, "SIMPLIFY") This same method will work for this example, but if you are looking to see if a property exists or if a file geodatabase feature class exists, you will need to use the arcpy.Exists boolean function. I would consider using the script as a toolbox script tool by providing input parameters. for example, arcpy, or in your case: dem = gp.GetParameterAsText(0)
output = gp.SetParemeter)(1) and then configure the parameter values using the parameters tab of the script tool properties page in arccatalog. I realize you are using arcgis 9.x and it may not work exaclty like this but this should get you going in the right direction.
... View more
12-06-2013
10:18 AM
|
0
|
0
|
617
|
POST
|
Hello. I think I understand your question, but it would be helpful if you could provide your code so that we know more precisely what you mean. import arcpy
if arcpy.Exists(output1):
arcpy.SolveNetwork(output1, output2)
however, you may mean something more along the lines of a tool validator. These are not so easy to explain but I would go to an existing script tool (denoted by the scroll -like icon within a toolbox) and right click the tool. in the context menu that pops up, select the Validation tab. In here you will see the validator class that can run prerequisite components of your script tool. You can start from scratch or you can try to use the validation classes that esri has created as a starting point. For example, the data management toolbox contains python script tool for converting points to a line. You can view the source code for this tool but to address the issue you are having you may be interested in the validator tab which shows: import locale
class ToolValidator:
"""Class for validating a tool's parameter values and controlling
the behavior of the tool's dialog."""
def __init__(self):
"""Setup the Geoprocessor and the list of tool parameters."""
import arcgisscripting as ARC
self.GP = ARC.create(9.3)
self.params = self.GP.getparameterinfo()
def initializeParameters(self):
"""Refine the properties of a tool's parameters. This method is
called when the tool is opened."""
self.params[1].Schema.GeometryType = "Polyline"
self.params[1].Schema.FieldsRule = "AllFIDsOnly"
return
def updateParameters(self):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parmater
has been changed."""
if self.params[2].altered:
if self.params[0].value and self.params[2].value:
field = self.GP.CreateObject("Field")
field.name = self.params[2].value.value
self.params[1].Schema.AdditionalFields = [field]
return
def updateMessages(self):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
You can see from this example that if the self.params[2] parameter is modified, a function is called to add a field to the point feature. This is where your first model could be initialized/checked for the existence of. Good luck!
... View more
12-05-2013
06:28 PM
|
0
|
0
|
617
|
POST
|
One useful thing to try is running the tools that your are interested in scripting from arccatalog. Make sure the results tab is enabled. After running the tool you can right click the result object for the tool and select "copy as python snippet." This copies the exact command that was passed to the arcpy interpreter. you can paste it into your python editor and inspect it further. One thing you should also look into is using the traceback, and os libraries (import os, traceback, etc.) to help you debug your script. simple error handling helps a lot when working with arcpy. something as easy as try:
arcpy.mapping.ListLayers(mxd)
except:
print "there was an exception"
# from arcgis python editor or toolbox execution:
arcpy.GetMessages()
# from idle or the like:
print arcpy.GetMessages()
can prevent you from banging your head against the wall for too long. You should also define the input parameters (separated by commas after the method call (i.e. arcpy.CopyFeatures_management (in_features, out_feature_class, {config_keyword}, {spatial_grid_1}, {spatial_grid_2}, {spatial_grid_3})) so you can attach each of your processes to one another dynamically. http://resources.arcgis.com/en/help/main/10.1/index.html#//001700000035000000 ESRI also has some great examples of how to set up your python script as a tool box script using the input parameters, output parameters, and data types. http://resources.arcgis.com/en/help/main/10.1/index.html#/A_quick_tour_of_creating_tools_with_Python/00150000002q000000/ It's fun.
... View more
12-05-2013
06:05 PM
|
0
|
0
|
775
|
POST
|
I think it has to do with the string value of your formula for calculating the name of the feature. Note the double quotes holding the name in single quotes by substituting string values in the third part of the arcpy.CalculateField_management() method. solution:
import os
import arcpy
fieldNameToAdd = "NAME"
try:
shpDir = r"C:\ShapeFileDir"
arcpy.env.workspace = shpDir
fcList = arcpy.ListFeatureClasses()
for fc in fcList:
print "processing: %s" % (fc)
fcName = fc.split(".")[0]
fcPath = shpDir + os.sep + fc
# blah geoprocessing ...
#
#
#...
fLength = len(fcName)
# check if field "Name" already exists
existingFields = arcpy.ListFields(fcPath)
for field in existingFields:
print field.name
if field.name.lower() == fieldNameToAdd.lower():
print "the field named %s already exists. Try again or follow the commented instructions below." % (fieldNameToAdd)
#raise # exception
#OR
arcpy.DeleteField_management(fcPath, fieldNameToAdd)
# blah continue working
arcpy.AddField_management(fcPath,fieldNameToAdd, "TEXT", None, None, fLength)
arcpy.CalculateField_management(fcPath,fieldNameToAdd, "'%s'" % (fcName), "PYTHON")
# blah more geoprocessing...
except:
print "there was an error"
print arcpy.GetMessages()
#import traceback
#raise
#etc
... View more
12-03-2013
02:01 PM
|
0
|
0
|
868
|
POST
|
I am unable to Import Cache to another existing cached map service. does anyone have suggestions? I would suggest ensuring that you have matching tiling schema (including source map data frame properties) between the two caches that you wish to merge. I would then check that the two servers from which you are attempting to move cache between have the necessary permission/user path combinations. If those steps fail I would consider looking at using a windows/robocopy cache management solution where you could set switches for files that are newer, older, larger, or empty (based on the block size of your hard disk and file size of empty tiles). Hope that helps.
... View more
11-19-2013
05:36 AM
|
0
|
0
|
1765
|
POST
|
Hello! Did the posted solution work for you? I'm just wondering because I have layer package with an ArcSDE datasource and it points to WGS84 vector data, but the data is loaded as SQL spatial and registered with the SDE. Similar to what you described, it works in ArcMap, but not in Explorer. Hmm. If you have any suggestions, I'd love to hear them. Thanks! Max
... View more
10-09-2012
03:10 PM
|
0
|
0
|
331
|
POST
|
Hi Frederic, If you are interested in getting into the Flex coding... I am definately interested. I sent you a message with more details. Thanks.
... View more
05-16-2012
06:32 AM
|
0
|
0
|
490
|
POST
|
If I am successful, I'll be sure to make the results available for interested folks. I'm interested. How can I learn more?
... View more
05-14-2012
03:16 PM
|
0
|
0
|
490
|