AnsweredAssumed Answered

Read folder paths out of text file and project the shapefiles

Question asked by JB1234510 on Jul 31, 2017
Latest reply on Aug 1, 2017 by JB1234510

The following python code should read out of a text file folder paths and project the shapefiles in this folder. Unfortunately this works only with the last (folder) line? Any suggestions why this doesn't work?

# Import arcpy module
import arcpy, os

fname = r"H:\python_scripte\ProjizierenMulti\test.txt"

with open(fname) as f:
    for line in f:
       
        print line
       
        arcpy.env.workspace = line
        workspace = arcpy.env.workspace
        arcpy.env.overwriteOutput = True

        # Use the ListFeatureClasses function to return a list of
        #  shapefiles.
        featureclasses = arcpy.ListFeatureClasses()

        # Copy shapefiles to a file geodatabase
        for fc in featureclasses:
            print "Projiziere " + fc

            outfile = os.path.splitext(fc)[0] + "_E.shp"
               
            spatialRef = arcpy.Describe(fc).spatialReference

            print spatialRef.name

            Ftype = arcpy.Describe(fc).datatype

            print Ftype
               
            if Ftype == "ShapeFile":
               
                if spatialRef.name == "DHDN_3_Degree_Gauss_Zone_3":
                                       
                    arcpy.Project_management(fc, outfile, "PROJCS['ETRS_1989_UTM_Zone_32N_8stellen',GEOGCS['GCS_ETRS_1989',DATUM['D_ETRS_1989',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',32500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',9.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]", "DHDN_To_ETRS_1989_3", "PROJCS['DHDN_3_Degree_Gauss_Zone_3',GEOGCS['GCS_Deutsches_Hauptdreiecksnetz',DATUM['D_Deutsches_Hauptdreiecksnetz',SPHEROID['Bessel_1841',6377397.155,299.1528128]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Gauss_Kruger'],PARAMETER['False_Easting',3500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',9.0],PARAMETER['Scale_Factor',1.0],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]")
                   
f.close()

Outcomes