Select to view content in your preferred language

viewshed calculation using arcpy

815
4
04-01-2011 05:56 AM
RiccardoKlinger1
Deactivated User
dear members of this great forum:

I am trying to use the following code in python to calculate the viewshed for every point of my point-shapefile separately:
import arcpy
rows = arcpy.SearchCursor("dem_points")
row = rows.next()
while row:
     arcpy.Viewshed_3d("dem_py.tif",row, str(row.POINTID)+"_view.tif","", "CURVED_EARTH","")
     row=rows.next()


what is wrong? cannot come to the problem!

hope to get some help or suggestions,

thanks!!
0 Kudos
4 Replies
AndrewChapkowski
Esri Regular Contributor
Try checking out your 3D extension. 

class LicenseError(Exception):
    pass

import arcview
import arcpy
from arcpy import env

try:
    if arcpy.CheckExtension("3D") == "Available":
        arcpy.CheckOutExtension("3D")
    else:
        # raise a custom exception
        #
        raise LicenseError

    #<Enter your code here>#

    arcpy.CheckInExtension("3D")

except LicenseError:
    print "3D Analyst license is unavailable"
except:
    print arcpy.GetMessages(2)

0 Kudos
RiccardoKlinger1
Deactivated User
Everything was fine with my license. Yet my path for storing the calculated view sheds was unavailable for ArcGIS...

Everything is fine now,!

Shall I post the correct code-snippet?
0 Kudos
RiccardoKlinger1
Deactivated User
for everyone else, who`s interested:

import arcpy
rows = arcpy.SearchCursor("observer_points")
row = rows.next()

while row:
    arcpy.MakeFeatureLayer_management("path_to_file", "one-point-dataset", "ID = " + str(row.ID))
    arcpy.Viewshed_3d("path_to_file", "one-point-dataset","path_to_view-raster"+str(row.ID)+"_v.tif", "", "CURVED_EARTH", "")
    row = rows.next()


yet this is about 3secs per point on a thinkpad Core2Duo 2.53Ghz 8GB Ram, Intel SSD
and about 12secs per point on a pentium quad core 2.4Ghz, 4Gb Ram, 7200RPM Harddrive.

Nevertheless it is taking to much time... 😞
0 Kudos
RiccardoKlinger1
Deactivated User
Now I know, why it takes so long:

the part:
arcpy.Viewshed_3d takes 3 times longer if the number of points increase by the factor 3 going from 10.000 to 700.000 points per points.

which means:
700.000 points will take approx. 90 days (given 12sec. per point)
10.000 points will take approx. 5.5hrs (given 3sec. per point) multiplied by 70 will lead to approx. 16 days for 700.000 points...

so what is the problem?

any suggestions?
0 Kudos