Hello,
I am trying to replace the holes on the Aster DEM with the values from the Ferranti DEM, and I get the same error as described in the first post. Therefore, I've decided to proceed with tiles. Now I receive the following error:
File "C:\Python27\ArcGIS10.1\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 320, in RunScript
debugger.run(codeObject, __main__.__dict__, start_stepping=1)
File "C:\Python27\ArcGIS10.1\Lib\site-packages\Pythonwin\pywin\debugger\__init__.py", line 60, in run
_GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
File "C:\Python27\ArcGIS10.1\Lib\site-packages\Pythonwin\pywin\debugger\debugger.py", line 655, in run
exec cmd in globals, locals
File "D:\tests\aster_dem\aster_dem.py", line 53, in <module>
new_raster = arcpy.CreateRasterDataset_management(arcpy.env.workspace, "aster_fix", cellsize, pixel_type, spatialReference)
File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\management.py", line 11265, in CreateRasterDataset
raise e
ExecuteError: ERROR 999999: Error executing function.
Failed to execute (CreateRasterDataset).
I am quite new to the python and arcpy, so the probability that I have some stupid mistakes inside is quite high. Any kind of help would be really appreciated!
code:
import os, sys
import string, math
import numpy
import arcpy
from arcpy.sa import *
# os.chdir(r"D:\tests\aster_dem")
arcpy.env.workspace = r"D:\tests\aster_dem"
arcpy.env.overwriteOutput = True
# input data
ferranti = arcpy.Raster(arcpy.env.workspace + "\\dhm25_ferranti_wgs84.tif")
aster = arcpy.Raster(arcpy.env.workspace + "\\e84_aster_switzerland_clip.tif")
# spatial analyst extension check
arcpy.CheckOutExtension("Spatial")
# difference
difference = aster - ferranti
difference.save(arcpy.env.workspace + "\\difference.tif")
threshold = -300
# data description
spatialReference=arcpy.Describe(ferranti).spatialReference
inRasterDesc = arcpy.Describe(ferranti)
# coordinates of the lower left corner
xmin = inRasterDesc.Extent.XMin
xmax = inRasterDesc.Extent.XMax
ymin = inRasterDesc.Extent.YMin
ymax = inRasterDesc.Extent.YMax
# cell size, raster size
rasMeanCellHeight = inRasterDesc.MeanCellHeight
rasMeanCellWidth = inRasterDesc.MeanCellWidth
nrows = inRasterDesc.Height
ncols = inRasterDesc.Width
cellsize = rasMeanCellHeight
# tiles
tile_size=(128,128)
ntiles = 2
pixel_type = "16_BIT_UNSIGNED"
RasterType = 'TIF'
new_raster = arcpy.CreateRasterDataset_management(arcpy.env.workspace, "aster_fix", cellsize, pixel_type, spatialReference)
for row in range(0,nrows,tile_size[1]):
for col in range(0,ncols,tile_size[0]*ntiles):
colend = min([ncols,col+tile_size[0]*ntiles-1])
rowend = min([nrows,row+tile_size[1]-1])
xstart = xmin + (cellsize*col)
ystart = ymax - (cellsize*(rowend+1))
print 'Processing cols',col,':',colend
print 'Processing rows',row,':',rowend
print 'Extracting lower left corner:',xstart,ystart
ferranti_arr = arcpy.RasterToNumPyArray(ferranti, arcpy.Point(xmin,ystart), ncols, nrows)
aster_arr = arcpy.RasterToNumPyArray(aster, arcpy.Point(xmin,ystart), ncols, nrows)
difference_arr = arcpy.RasterToNumPyArray(difference, arcpy.Point(xmin,ystart), ncols, nrows)
if difference_arr[row,col] < threshold:
aster_arr[row,col] = ferranti_arr[row,col]
out_raster = NumPyArrayToRaster(aster_arr, arcpy.Point(xmin,ystart), cellsize, cellsize)
arcpy.Mosaic_management(out_raster,new_raster)
Thank you in advance!
Regards,
Olga