first of all, thank you for your quick answer. In the last days I spend a lot of time researching my problem. I found a script and edited it further. The script takes my multiple point file, "splits" it up into single point features, buffers each of them to know the extend for the elevation raster (dem) for the viewshed analysis and creates so called multiple ring buffers. it works fine (and is very fast) exept for one misterous problem that kept me up for the last nights. I searched everywhere but couldn't find anything about it, but then I am not a programmer and my python knowlegde is very restricted.SO here comes the mysterious problem: even though my multiple point file is valid and has no broken geometry or anything not every single point file is being bufferd. for some crazy reason the buffer analysis as well as the multiple ring buffer analysis skip certain points. If I manually delete these points the error passes to the next point. I also tried to buffer and multibuffer the whole multiple point file and it works fine. the error has to be somewhere in the script...so here is my newest version. I tried to comment it out as best as I could# -*- coding: cp1252 -*-
# Imports...
import arcpy
from arcpy.sa import *
from arcpy import env
import multiprocessing, ntpath, os, shutil, time, math
from re import split
#overwrite is now possible
arcpy.gp.overwriteOutput = True
#create folders
arcpy.CreateFolder_management("C:/studium", "project")
arcpy.CreateFolder_management("C:/studium/project", "script0")
arcpy.CreateFolder_management("C:/studium/project", "script1")
arcpy.CreateFolder_management("C:/studium/project", "bufferRings")
arcpy.CreateFolder_management("C:/studium/project", "tmp")
def calcVS(argsCSV):
import arcpy
'''Worker function'''
#takes the list (of 4 items) and splits them so every item can be accessed
argsList = split(",", argsCSV)
vsFC = argsList[0] #item 1 (path of the singlepoint-shape)
elevRas = argsList[1] #item2 (path of the dem)
outWS = argsList[2] #item3 (output path)
NABE = float(argsList[3]) #item4 (height)
head, tail = ntpath.split(vsFC) # split into head and tail
#creates a path for scratch workspace
MbrPath =os.path.join("c:/studium/project/tmp", "MRB_"+ tail[:-4])
#makes the directory
os.mkdir(MbrPath)
#sets the scratch workspace
arcpy.env.scratchWorkspace = MbrPath
#bufferzones will later be calculated, but I spared you the calculation
Zone1= 500
Zone2= 1000
Zone3= 2000
Zone4= 5000
Zone5= 9000
Zone6=15000
#create multiple buffer rings for every pointfile with specific zones
arcpy.MultipleRingBuffer_analysis(vsFC , "c:/studium/project/bufferRings/Rings_%s" % (tail), str(Zone1)+";"+str(Zone2)+";"+str(Zone3)+";"+str(Zone4)+";"+str(Zone5)+";"+str(Zone6) , "meters" , "", "ALL")
#delete the scratch directory for the multiple buffer rings
shutil.rmtree(MbrPath)
#the buffering for the extent. Viewsheds have a maximus of 15 kilometers, so
#the dem extent can be scaled to that extent also
buffVS = os.path.join(outWS, "bu%s" % (tail))
arcpy.Buffer_analysis(vsFC, buffVS, "RADIUS2")
arcpy.env.extent = buffVS
arcpy.Delete_management(buffVS)
#the scratch workspace for the viewshed analysis
scratchWS = os.path.join(outWS, tail[:-4])
os.mkdir(scratchWS)
arcpy.env.scratchWorkspace = scratchWS
#check out the license
arcpy.CheckOutExtension("Spatial")
#create viewsheds
outViewshed = Viewshed(elevRas, vsFC,1,"CURVED_EARTH",0.15)
outViewshed.save(os.path.join(outWS, "%s.tif" % (tail[:-4])))
#delete second scratch workspace
shutil.rmtree(scratchWS)
#delete the single point file
arcpy.Delete_management(vsFC)
if __name__ == "__main__":
obsShp = "C:/studium/00_Master/clean/drei.shp" #my multiple point-file
uidField = "FID" # unique identifier of pointfile table
Hoehe= "NABENHOEHE" #field of heights of pointfile table
elevationRas = "C:/studium/00_Master/clean/demtora_okay1" #digital elevation model
outputWS = "C:/studium/project/script1"
arcpy.env.workspace = outputWS #sets the workspace
start = time.clock() #remembers the time fot duration calculation at the end
obsList=[] #create empty list for FIDs
HoehenList =[] #create empty list for heights
arcpy.MakeFeatureLayer_management (obsShp, "pts")
# make temporairy layer that can be searched, then search it and save
# FID and GESAMTHOEH from everey row in a list
with arcpy.da.SearchCursor('pts',['FID','GESAMTHOEH']) as cursor:
for row in cursor:
HoehenList.append(row[1])
obsList.append(row[0])
vsList = []#create empty list for every value that shall be passed to calcVS
for obs in obsList:
obsFileName = "Vshed%s.shp" % (str(obs).zfill(4))
HIES = HoehenList[obs] #save inherent height in a variable
#make featureclasses for each point
arcpy.Select_analysis(obsShp, obsFileName, uidField+" = "+str(obs))
#fill list of lists for every value that shall be passed to calcVS
vsList.append("%s,%s,%s,%s" % (os.path.join(outputWS, obsFileName), elevationRas, outputWS, HIES))
print vsList
pool = multiprocessing.Pool()# starts multiprocessing
pool.map(calcVS, vsList)
# chops the iterable into a number of chunks and submits them to calcVS
pool.close()# stops sending more data
pool.join()# waits for processes to finish and terminates them
#calculate duration
end = time.clock()
duration = end - start
hours, remainder = divmod(duration, 3600)
minutes, seconds = divmod(remainder, 60)
print "Completed in %dh:%dm:%fs" % (hours, minutes, seconds)
#shows a counter before calling the next script (so the user can interfere)
countdown = 5
for j in range(1, countdown):
print str(countdown - j) + " Sekunden bis nächstes Skript gestartet wird"
time.sleep(1)
#here the next file would be called, but I disabled it
#execfile("c:/studium/00_Master/clean/10_2.py")
@ stacy rendall:I tried to implement apply_async but I couldn't get it to work. All the examples I found about it on the internet suggested using the map-function. But I'm starting to think my error might have something tot do with it.p.s.:I like your blog and have been there even before the initial post but it is definetly to complicated for me to undertsand it completely