Problem with running script outside of ArcMap (licensing, parameters)

1432
12
Jump to solution
10-02-2014 01:27 AM
LeonoreBehr
New Contributor

Hello,

I have written a script which runs fine inside of ArcMap in the Python-Window but does not outside of ArcMap in PythonWin.

My intention for the last step was to delete all the files I created except of the Result txt-file.

But if I run the script in PythonWin there seems to be some problems with the license of Spatial Statistic or/and with the fparameters within the arcpy functions.

The script looks like this (sorry, the explanation parts and the file names are partly in german):

import os, arcpy

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

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

PfadTxt="C:/Users/behr/Desktop/DAC_MD/01_MD_HH_klein/"

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

Sz="HH"

TextDateienListe = os.listdir(PfadTxt)

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","HH")

        # Kriging // Output: Raster rXXX

    arcpy.gp.Kriging_sa(EventLayerName,"HH",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],"ADD_FIELD_NAMES")

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 Textdat
arcpy.ExportXYv_stats(Pfad1+"Hydrotop" + b[0]+".shp","ID_COMTESS;MEAN","SPACE",Pfad + "Results/01_MD_"+Sz+"_"+b[0],"ADD_FIELD_NAMES")

The errors occuring are:

1.

ExecuteError: Errors during execution . Parameters are invalid .

ERROR 000824: The tool is not licensed .

Error executing ( kriging ) .

So my question is: is it not possible to run spatial statistic stuff outside of arcmap because of the license?

And could the first problem be, that I cant't use the parameters like "HH" as the row-definition in the attribute table outside of ArcMap?

Thanks in advance!

Leonore

0 Kudos
1 Solution

Accepted Solutions
JohannesBierer
Occasional Contributor III

Spatial Statistik müsste schon funktionieren. Wahrscheinlich mußt du im script die extension dazu auschecken? SA?

View solution in original post

12 Replies
LeonoreBehr
New Contributor

Sorry, it seems I couldn't load the file exactly: The lines 42 till 80 are indented, too, in the original script.

0 Kudos
JohannesBierer
Occasional Contributor III

Spatial Statistik müsste schon funktionieren. Wahrscheinlich mußt du im script die extension dazu auschecken? SA?

JohannesBierer
Occasional Contributor III
0 Kudos
LeonoreBehr
New Contributor

Hallo Johannes,

vielen Dank, das war die Lösung! Doch so einfach

eine Frage habe ich noch:

Ich wollte unten jetzt einfach noch folgendes einfügen:

    #Löschen der unnötigen Files
for filename in os.listdir(Pfad+ "Delete/"):
        os.remove(os.path.join(Pfad+ "Delete/", filename))

um damit die Daten aus dem Delete-Ordner, in dem ich alle Zwischenschritte abgespeichert habe, bequem zu löschen.

Da erscheint aber folgender Error:

WindowsError: [Error 5] Zugriff verweigert: 'C:/Users/behr/Desktop/DAC_MD/Delete/info'

Liegt das dann an den Windows-Rechten? Kann ich die vielleicht irgendwie umgehen?

Vielen Dank schonmal,

Leonore

0 Kudos
JohannesBierer
Occasional Contributor III

Die Fehlermeldung deutet schon auf ein Rechteproblem hin. Ich würde die Daten einfach woanders speichern?

Umgehen geht glaube ich nicht, zumindest ist mir da nichts bekannt.

0 Kudos
LeonoreBehr
New Contributor

OK, dann werde ich das halt einfach per Hand löschen müssen.

Danke für die Lösungshilfe!

0 Kudos
JohannesBierer
Occasional Contributor III

Da nich für

0 Kudos
JamesCrandall
MVP Frequent Contributor

I don't see where you are checking out/in your Spatial Analyst extension.

  ### see if spatial analyst extension is available for use

  availability = arcpy.CheckExtension("Spatial")

  if availability == "Available":

     arcpy.CheckOutExtension("Spatial")

     arcpy.AddMessage("SA Ext checked out")

  else:

     arcpy.AddError("%s extension is not available (%s)"%("Spatial Analyst Extension",availability))

     arcpy.AddError("Please ask someone who has it checked out but not using to turn off the extension")

     return

  #do your processing with SA

  # check the sa extension back in

  arcpy.CheckInExtension("Spatial")

0 Kudos
JohannesBierer
Occasional Contributor III

This was already proposed - in German so you haven't had the chance to read it - or do u speak german? 🙂

Actually she has got some problems with deleting files with os.remove according to access authority on "C:/Users/behr/Desktop". No idea why she has to saves the things there? But maybe you have a idea for a solution?

0 Kudos