import arcpy #Define message constants so they may be translated easily unknown_projection = "Unknown" # Get the feature class to describe # featureClass = arcpy.GetParameterAsText(0) desc = arcpy.Describe(featureClass) #Loop through each dataset and describe projection. for dataset in inDatasets: try: #Describe input dataset to check if a projection is already defined. dsc_Dataset = ConversionUtils.gp.Describe(dataset) cs_Dataset = dsc_Dataset.SpatialReference #Check if a projection is already define for the input dataset. if cs_Dataset.Name != unknown_projection: ConversionUtils.gp.AddWarning(msgPrjAlreadyDefine) # Print SpatialReference object properties SR = desc.spatialReference print SR.name # shows results in commandline of IDLE print SR.exportToString() # Show results in geoprocessing tool dialog arcpy.AddMessage(SR.name) arcpy.AddMessage(SR.exportToString())
import ConversionUtils, arcpy#Set the input datasetsinputs = ConversionUtils.gp.GetParameterAsText(0)inFeatureClasses = ConversionUtils.SplitMultiInputs(inputs)for featureClass in inFeatureClasses: # Describe each fc desc = arcpy.Describe(featureClass) # Print SpatialReference object properties SR = desc.spatialReference print SR.name # shows results in commandline of IDLE print SR.exportToString() # Show results in geoprocessing tool dialog arcpy.AddMessage(SR.name)
import arcpy arcpy.env.workspace = "T:/WORK FOLDER" #Loop through each dataset and describe projection. inDatasets = arcpy.ListFeatureClasses() for dataset in inDatasets: # Describe each fc desc = arcpy.Describe(dataset) #Describe input dataset to check if a projection is already defined. dsc_Dataset = arcpy.Describe(dataset) cs_Dataset = dsc_Dataset.SpatialReference #Check if a projection is already define for the input dataset. if cs_Dataset.Name != "Unknown": arcpy.AddWarning("msgPrjAlreadyDefine") # Print SpatialReference object properties SR = desc.spatialReference print SR.name # shows results in commandline of IDLE print SR.exportToString() # Show results in geoprocessing tool dialog arcpy.AddMessage(SR.name) arcpy.AddMessage(SR.exportToString()) print "\nDone.\n"
In general, yes.There are exceptions depending "how" you are running your script, and what tools your using (at least in 9.x.) Not positive about 10.x.You can run script tools from anywhere on your network but you'll have to change the path (workspace) in your script to where your data is.
arcpy.env.workspace = arcpy.GetParameterAsText(0)
arcpy.env.workspace = "T:\\WORK FOLDER"
Executing: BatchDescribeProjection 'T:\WORK FOLDER\DEN_MP_DIA.shp';'T:\WORK FOLDER\dirt_spcs.shp'Start Time: Fri Feb 25 14:38:27 2011Running script BatchDescribeProjection...ERROR!ERROR!ERROR!ERROR!ERROR!ERROR!ERROR!ERROR!ERROR!ERROR!ERROR!ERROR!ERROR!ERROR!ERROR!Completed script BatchDescribeProjection...Succeeded at Fri Feb 25 14:38:29 2011 (Elapsed Time: 2.00 seconds)
import arcpy #Loop through each dataset and describe projection. fcs = arcpy.GetParameterAsText(0) for fc in fcs: try: desc = arcpy.Describe(fc) # Print some SpatialReference object properties SR = desc.spatialReference print SR.name # shows results in commandline of IDLE print SR.exportToString() # Show results in geoprocessing tool dialog arcpy.AddMessage(SR.name) arcpy.AddMessage(SR.exportToString()) except: arcpy.AddMessage("ERROR!")
Do you always have to set a workspace?
or can script tools run data from anywhere on your network?
import arcpy arcpy.env.workspace = "T:\WORK FOLDER" #Define message constants so they may be translated easily unknown_projection = "Unknown" #Loop through each dataset and describe projection. inDatasets = arcpy.ListFeatureClasses() for dataset in inDatasets: try: # Describe each fc desc = arcpy.Describe(dataset) #Describe input dataset to check if a projection is already defined. dsc_Dataset = ConversionUtils.gp.Describe(dataset) cs_Dataset = dsc_Dataset.SpatialReference #Check if a projection is already define for the input dataset. if cs_Dataset.Name != unknown_projection: ConversionUtils.gp.AddWarning(msgPrjAlreadyDefine) # Print SpatialReference object properties SR = desc.spatialReference print SR.name # shows results in commandline of IDLE print SR.exportToString() # Show results in geoprocessing tool dialog arcpy.AddMessage(SR.name) arcpy.AddMessage(SR.exportToString()) except: arcpy.AddMessage("ERROR!")
Executing: BatchDescribeProjection 'T:\WORK FOLDER\DEN_MP_DIA.shp'Start Time: Fri Feb 25 08:15:38 2011Running script BatchDescribeProjection...ERROR!ERROR!ERROR!ERROR!ERROR!ERROR!ERROR!ERROR!ERROR!ERROR!ERROR!ERROR!ERROR!ERROR!ERROR!Completed script BatchDescribeProjection...Succeeded at Fri Feb 25 08:15:39 2011 (Elapsed Time: 1.00 seconds)
<type 'exceptions.RuntimeError'>: ERROR 000638: Workspace not set for GeoProcessor.Failed to execute (BatchDescribeProjection).
import arcpy #Define message constants so they may be translated easily unknown_projection = "Unknown" #Loop through each dataset and describe projection. inDatasets = arcpy.ListFeatureClasses() for dataset in inDatasets: try: # Describe each fc desc = arcpy.Describe(dataset) #Describe input dataset to check if a projection is already defined. dsc_Dataset = ConversionUtils.gp.Describe(dataset) cs_Dataset = dsc_Dataset.SpatialReference #Check if a projection is already define for the input dataset. if cs_Dataset.Name != unknown_projection: ConversionUtils.gp.AddWarning(msgPrjAlreadyDefine) # Print SpatialReference object properties SR = desc.spatialReference print SR.name # shows results in commandline of IDLE print SR.exportToString() # Show results in geoprocessing tool dialog arcpy.AddMessage(SR.name) arcpy.AddMessage(SR.exportToString()) except: arcpy.AddMessage("ERROR!")
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.