AnsweredAssumed Answered

Iterating feature classes and writting in a text file

Question asked by kostas_ptr88 on May 30, 2015
Latest reply on Jun 5, 2015 by sephefox

Hi i am trying to export some values from a number of shapefiles to a text file so as to use it to creat a point shapefile. The process is succeded ONLY when i put my files in the table of context. Why is that? **I have only folders no GDBase or .mxd**

 

In addition there is A problem with my code cause i can't get the right calculation of AVGDISTANCES i put it outside if and for, but nothing changed. FOR EXAMPLE for DISTANCE = 170, 170, 160, 150 i should get AVGDISTANCES= 162.5 not 150.  This is my code:

 

 import arcpy
    import os
    from arcpy import env
    Routesworkspace = arcpy.GetParameterAsText(2)
    env.workspace = Routesworkspace
    cases = ['RCs4s3s2c10_S', 'RCs4s3s2c20_S', 'RCs4s3s2c30_S', 'RCs4s3s2c40_S']
    for fc in arcpy.ListFeatureClasses():
        for case in cases:
            if fc.startswith(case):
                fields = ['DISTANCE', 'DURATION']
                SUMDISTANCE = 0
                C = 0
                with arcpy.da.SearchCursor(fc, fields, "FID = 0") as cursor:
                    for row in cursor:
                        DISTANCE = row[0]
                        DURATION = row[1]
                        SUMDISTANCE = SUMDISTANCE + DISTANCE
                        C = C + 1 
                        AVGDISTANCE = SUMDISTANCE / C
    outFile.write('' + str(AVGDISTANCE) + '\n')

 

Is this the right format for a point txt?

Point
0 34.5 23.2 12
1 65.7 56.5 67
2 34.9 97.9 43
3 67.2 34.3 20

Outcomes