Directing output to a mirrored file tree. ArcGIS, Python

المشرف العام

Administrator
طاقم الإدارة
I am attempting to modify the Batch Project script to:

a) read from a text file of file names located on our server

b) build a mirror of the paths to those files on my local machine

c) output to my local machine at the end of those paths. The paths should also be appended to a user specified location

My code works to an extent, but stops after the first projection, as per:

Projected S:\FMM_Projects\Pyramid\Reports\Pyramid\Data_Transfer\Pyramid_FromJoey2010oct\GIS\Geochem\Geochem Merged\Pyramid_PanCon.shp to C:\Users\revresources\scratch\shapefiles\Test_Output\test3\FMM_Projects\Pyramid\Reports\Pyramid\Data_Transfer\Pyramid_FromJoey2010oct\GIS\Geology\SWAK 2008 mapping shapefiles\2008_Alteration.shp successfully.

.

Failed to project S:\FMM_Projects\Pyramid\Reports\Pyramid\Data_Transfer\Pyramid_FromJoey2010oct\GIS\Geochem\Geochem Merged\Pyramid_Rocks.shp. Failed to execute. Parameters are not valid. ERROR 000725: Output Dataset or Feature Class: Dataset C:\Users\revresources\scratch\shapefiles\Test_Output\test3\FMM_Projects\Pyramid\Reports\Pyramid\Data_Transfer\Pyramid_FromJoey2010oct\GIS\Geology\SWAK 2008 mapping shapefiles\2008_Alteration.shp already exists. Failed to execute (Project).

.

Failed to project S:\FMM_Projects\Pyramid\Reports\Pyramid\Data_Transfer\Pyramid_FromJoey2010oct\GIS\Geochem\Geochem Merged\Pyramid_Silts.shp. Failed to execute. Parameters are not valid. ERROR 000725: Output Dataset or Feature Class: Dataset C:\Users\revresources\scratch\shapefiles\Test_Output\test3\FMM_Projects\Pyramid\Reports\Pyramid\Data_Transfer\Pyramid_FromJoey2010oct\GIS\Geology\SWAK 2008 mapping shapefiles\2008_Alteration.shp already exists. Failed to execute (Project).

Here is my code:

#Import required modulesimport ConversionUtils, time, sys, os, arcpy#Define message constants so they may be translated easilymsgWorkspace = ConversionUtils.gp.GetIDMessage(86109) # Message "Output workspace does not exist: "msgCoordinateSystem = ConversionUtils.gp.GetIDMessage(86110) #Message "Must Enter a Spatial Reference or Template Feature Class."msgFail = ConversionUtils.gp.GetIDMessage(86111) # Message "Failed to project "#Set the input datasetsinputs = [item.replace('\n', '') for item in open(sys.argv[1]).readlines()] for line in inputs: line = line.replace("\\\\", "\\")#changing slashes to single slashes#print the stripped line (drive, path) = os.path.splitdrive(line) arcpy.AddMessage("path before the join is " + path) print "path before the join is " + path arcpy.AddMessage(" ConversionUtils.gp.GetParameterAsText(1) before the join is " + ConversionUtils.gp.GetParameterAsText(1)) outdata=os.path.normpath(ConversionUtils.gp.GetParameterAsText(1)+path) arcpy.AddMessage(" ConversionUtils.gp.GetParameterAsText(1) after the join is " + ConversionUtils.gp.GetParameterAsText(1)) arcpy.AddMessage("path after join is " + path)# print "outdata is " + outdata# print "path after join is " + path arcpy.AddMessage("outdata is " + outdata) try: (path2,fileName) = os.path.split(outdata) os.makedirs(path2) except OSError: print "Skipping creation of the following path because it exists already: " + path2 #if path exists, this will be printed arcpy.AddMessage("Skipping creation of the following path because it exists already: " + path2) #print line.strip()output_workspace = ConversionUtils.gp.GetParameterAsText(2) #Set the spatial referenceoutput_coordinate_system = ConversionUtils.gp.GetParameterAsText(3)#Set the template datasettemplate_dataset = ConversionUtils.gp.GetParameterAsText(4)#Set the transformationtransformation = ConversionUtils.gp.GetParameterAsText(5)#Message 86112 "Projecting multiple datasets ..."ConversionUtils.gp.SetProgressor("step", ConversionUtils.gp.GetIDMessage(86112), 0, len(inputs))if (output_coordinate_system == "" or output_coordinate_system == "#") and (template_dataset == "" or template_dataset == "#"): raise ConversionUtils.GPError(msgCoordinateSystem) elif (output_coordinate_system != "") and (output_coordinate_system != "#"): sr = output_coordinate_systemelif (template_dataset != "") and (template_dataset != "#"): dsc = ConversionUtils.gp.Describe(template_dataset) sr = dsc.SpatialReferencefor input in inputs: try: #outdata = ConversionUtils.GenerateOutputName(input, output_workspace) #Message 86113 "Projecting " ConversionUtils.gp.SetProgressorLabel(ConversionUtils.gp.GetIDMessage(86113) + input) ConversionUtils.gp.Project_management(input, outdata, sr, transformation) print outdata arcpy.AddMessage(outdata) #Message 86114 "Projected %s to %s successfully." ConversionUtils.gp.AddMessage(ConversionUtils.gp.GetIDMessage(86114) % (input, outdata)) except Exception, ErrorDesc: msgWarning = msgFail + "%s" % input msgStr = ConversionUtils.gp.GetMessages(2) ConversionUtils.gp.AddWarning(ConversionUtils.ExceptionMessages(msgWarning, msgStr, ErrorDesc)) ConversionUtils.gp.SetProgressorPosition()time.sleep(0.5)

أكثر...
 
أعلى