XY-Event-Layer (loop): Script runs slower and slower

975
1
10-09-2014 06:49 AM
LeonoreBehr
New Contributor

Hello,

I am running a script where in the first step I create a xy-Event-Layer out of txt-files. I am loading like 2000 files one after another out of one folder.

Now the process works fine, only it gets slower and slower. After 8 hours it needs like 4 minutes for one file, while in the beginning it finished 6 files in one minute.

My Question is:

Could it be that ArcGIS is saving something like an image of the XY-Eventlayers in temp-files somewhere so that my RAM can't work anymore in the end?

The thing is, if I kill the script, turn the PC off and on again and start again, it works as fast as in the beginning. If I only delete the files in the "delete"folder, (which I created for the output of line 31-38 which appears during the process) and in the "normal" temp-folder, it doesn't get better.

Thanks in advance for any help!

The script looks like this:

import os, arcpy

Pfad="C:/Users/Lolaley/Desktop/DAC_MD/"

Pfad1="C:/Users/Lolaley/Desktop/DAC_MD/Delete/"

PfadTxt="C:/Users/Lolaley/Desktop/DAC_MD/01_MD_HH/"

# Festlegen ob das Ergebnis Hydr. Höhen oder Salzgehalt ist

Sz="HH"

arcpy.CheckOutExtension("Spatial")

TextDateienListe = os.listdir(PfadTxt)

import re

def k(s):

    return [w.isdigit() and int(w) or w for w in re.split(r'(\d+)', s)]

TextDateienListe = sorted(TextDateienListe, key=k)

for Datei in TextDateienListe:

    #Datei=TextDateienListe[1]

    b = os.path.splitext(Datei)    

         # XY-Event Layer erstellen // Input: txt-Datei //Output: Layer mit Variable EventLayerName

    EventLayerName= b[0] + "_Layer"

    arcpy.MakeXYEventLayer_management(PfadTxt+Datei,"x","y",EventLayerName,"PROJCS['ETRS_1989_UTM_Zone_33N',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',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',15.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]];-5120900 -9998100 10000;-100000 10000;-100000 10000;0,001;0,001;0,001;IsHighPrecision",Sz)

        # Kriging // Output: Raster rXXX

    arcpy.gp.Kriging_sa(EventLayerName,Sz,Pfad1+"r" + b[0],"Spherical 15,717080","15,7170800000001","VARIABLE 12","#")  

        # Hydrotopdatei kopieren zum späteren Einlesen der gemittelten Werte

    arcpy.CopyFeatures_management(Pfad+"HydrotMD.shp",Pfad1+"Hydrotop" + b[0]+".shp","#","0","0","0")

        #Zonale Statistiken: Mittelwerte bilden für Hydrotop und Raster und in Tabelle ausspucken

    arcpy.gp.ZonalStatisticsAsTable_sa(Pfad1+"Hydrotop" + b[0]+".shp","ID_COMTESS",Pfad1+"r" + b[0],Pfad1+ "t"+b[0],"DATA","MEAN")

      

        # Tabellenfeld per ID_COMTESS-Feld in die hydrotop-Datei integrieren

    arcpy.JoinField_management(Pfad1+"Hydrotop" + b[0]+".shp","ID_COMTESS",Pfad1+ "t"+b[0],"ID_COMTESS","MEAN")

        #Exportieren der ID mit dem dazugehörigen Mittelwert in eine Textdatei

    arcpy.ExportXYv_stats(Pfad1+"Hydrotop" + b[0]+".shp","ID_COMTESS;MEAN","SPACE",Pfad + "Results/01_MD_"+Sz+"_"+b[0]+".txt","#")

arcpy.CheckInExtension("Spatial")

0 Kudos
1 Reply
JohannesBierer
Occasional Contributor III