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 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 modules
import ConversionUtils, time, sys, os, arcpy

#Define message constants so they may be translated easily
msgWorkspace = 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 datasets
inputs = [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 reference
output_coordinate_system = ConversionUtils.gp.GetParameterAsText(3)

#Set the template dataset
template_dataset = ConversionUtils.gp.GetParameterAsText(4)

#Set the transformation
transformation = 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_system
elif (template_dataset != "") and (template_dataset != "#"):
    dsc = ConversionUtils.gp.Describe(template_dataset)
    sr = dsc.SpatialReference

for 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)
share|improve this question
    
Isn't the ConversionUtils module more for internal use? I guess you can use it yourself, but... why? –  blah238 Jun 1 '12 at 20:26

1 Answer 1

up vote 5 down vote accepted

Your script is trying to save each input to the same output shapefile. Since it is not set to overwrite existing data, it works the first time but not any time after that.

The relevant line is: outdata=os.path.normpath(ConversionUtils.gp.GetParameterAsText(1)+path)

To fix it, you will need to incorporate the outdata= line into your for input in inputs: loop and make sure that the shapefile is a new one each time, before calling ConversionUtils.gp.Project_management(input, outdata, sr, transformation).

share|improve this answer
    
Thank you nmpeterson. I will try this out. –  Visceral Jun 4 '12 at 15:40

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.