I'm running a fairly small script to get height differences. The scripts gets the height in a point based on a DTM. Running the script in the ArcMap python window uses 1 min 30 seconds for 1000 points, while running it in the python window outside Arcmap (C:\Python27\ArcGIS10.5\python.exe) uses 2 min 40 seconds for the same 1000 points. What causes this big difference? There can be many points for each dataset, so I want it to be able to run outside ArcMap so it doesn't run out if memory.
import arcpy
import datetime
arcpy.env.workspace = r'\\path\Laserdata.gdb'
arcpy.env.scratchWorkspace = r'\\path\Temp_data.gdb'
# laserline
laser = 'L0380_2m_Vertice_selection'
# 1 x 1 m raster
raster_1m = r'\\path\Connection to sde.sde\DTM1'
def main():
i = 1
print "Starttime: " + str(datetime.datetime.now())
start = datetime.datetime.now()
fields = arcpy.ListFields(laser)
if len(arcpy.ListFields(laser,"DTMZ"))>0:
print "Field exist"
else:
print "Does not exist"
arcpy.AddField_management(laser, "DTMZ", "FLOAT")
with arcpy.da.UpdateCursor(laser, ['SHAPE@X','SHAPE@Y' ,'DTMZ']) as curs:
for row in curs:
X = str(row[0]).replace(".",",")
Y = str(row[1]).replace(".",",")
XY = str(X + " " + Y)
hoydeDTM = arcpy.GetCellValue_management(raster_1m, XY)
if str(hoydeDTM) == 'NoData':
hoydeDTM = -9999
else:
hoydeDTM = hoydeDTM
row[2] = str(hoydeDTM)
i = i + 1
if i % 1000 == 0:
print i
print datetime.datetime.now() - start
curs.updateRow(row)
print "Endtime: " + str(datetime.datetime.now())
print datetime.datetime.now() - start
if __name__ == '__main__':
main()
GetCellValue
operates faster on the raster layer in your map rather than connecting to the ArcSDE and reading the raster each time you run yourGetCellValue
. Depending on the size of your raster, you may boost the performance drastically by copying the raster into the specialin_memory
workspace once before going intofor
loopIn_memory
desktop.arcgis.com/en/arcmap/10.3/analyze/modelbuilder/…. Check whether your raster can fit into the RAM you have on your machine