Things have changed a lot at 10.x for Spatial Analyst. Before you look for fancy alternatives, just refactor it for the new Python Grid Algebra. The key improvement that stands out here is that the grid is held in memory, so you could iterate over the same grid without reloading it each time, and the output is also held in memory until you want to save it.But if that is still to slow, could numpy be programmed to run the same processes?Cup of Coffee RuleIf any process takes longer than a cup of coffee, interrupt it and fix it or find a better way.I would never accept a model that takes 40 hours. What if you have to re-run it?
def snapExtentToRaster(inputExtent, snapRaster): "Returns a xMin, yMin, xMax, yMax extent snapped to the cell allignment of a raster" xMinInput = float(inputExtent.split(" ")[0]) yMinInput = float(inputExtent.split(" ")[1]) xMaxInput = float(inputExtent.split(" ")[2]) yMaxInput = float(inputExtent.split(" ")[3]) dscSnapRaster = gp.describe(snapRaster) cellSize = float(dscSnapRaster.meancellheight) xMinSnap = float(dscSnapRaster.extent.xmin) yMinSnap = float(dscSnapRaster.extent.ymin) xMaxSnap = float(dscSnapRaster.extent.xmax) yMaxSnap = float(dscSnapRaster.extent.ymax) #Calculates a modified xMinInput if xMinSnap < xMinInput: if divmod(abs(xMinInput - xMinSnap), cellSize)[1] / cellSize < .5: xMinOutput = xMinSnap + divmod(abs(xMinInput - xMinSnap), cellSize)[0] * cellSize else: xMinOutput = xMinSnap + cellSize + divmod(abs(xMinInput - xMinSnap), cellSize)[0] * cellSize else: if divmod(abs(xMinInput - xMinSnap), cellSize)[1] / cellSize < .5: xMinOutput = xMinSnap - divmod(abs(xMinInput - xMinSnap), cellSize)[0] * cellSize else: xMinOutput = xMinSnap - cellSize - divmod(abs(xMinInput - xMinSnap), cellSize)[0] * cellSize #Calculates a modified yMinInput if yMinSnap < yMinInput: if divmod(abs(yMinInput - yMinSnap), cellSize)[1] / cellSize < .5: yMinOutput = yMinSnap + divmod(abs(yMinInput - yMinSnap), cellSize)[0] * cellSize else: yMinOutput = yMinSnap + cellSize + divmod(abs(yMinInput - yMinSnap), cellSize)[0] * cellSize else: if divmod(abs(yMinInput - yMinSnap), cellSize)[1] / cellSize < .5: yMinOutput = yMinSnap - divmod(abs(yMinInput - yMinSnap), cellSize)[0] * cellSize else: yMinOutput = yMinSnap - cellSize - divmod(abs(yMinInput - yMinSnap), cellSize)[0] * cellSize #Calculates a modified xMaxInput if xMaxSnap < xMaxInput: if divmod(abs(xMaxInput - xMaxSnap), cellSize)[1] / cellSize < .5: xMaxOutput = xMaxSnap + divmod(abs(xMaxInput - xMaxSnap), cellSize)[0] * cellSize else: xMaxOutput = xMaxSnap + cellSize + divmod(abs(xMaxInput - xMaxSnap), cellSize)[0] * cellSize else: if divmod(abs(xMaxInput - xMaxSnap), cellSize)[1] / cellSize < .5: xMaxOutput = xMaxSnap - divmod(abs(xMaxInput - xMaxSnap), cellSize)[0] * cellSize else: xMaxOutput = xMaxSnap - cellSize - divmod(abs(xMaxInput - xMaxSnap), cellSize)[0] * cellSize #Calculates a modified yMaxInput if yMaxSnap < yMaxInput: if divmod(abs(yMaxInput - yMaxSnap), cellSize)[1] / cellSize < .5: yMaxOutput = yMaxSnap + divmod(abs(yMaxInput - yMaxSnap), cellSize)[0] * cellSize else: yMaxOutput = yMaxSnap + cellSize + divmod(abs(yMaxInput - yMaxSnap), cellSize)[0] * cellSize else: if divmod(abs(yMaxInput - yMaxSnap), cellSize)[1] / cellSize < .5: yMaxOutput = yMaxSnap - divmod(abs(yMaxInput - yMaxSnap), cellSize)[0] * cellSize else: yMaxOutput = yMaxSnap - cellSize - divmod(abs(yMaxInput - yMaxSnap), cellSize)[0] * cellSize #Returns the entire modified extent return str(xMinOutput) + " " + str(yMinOutput) + " " + str(xMaxOutput) + " " + str(yMaxOutput) #Set the gp.extent to that of the nestIdsBufferFC = nestId and use snapExtentToRaster() function to set the snapraster instead of gp.snapraster (which slows things down) gp.extent = "" tempExtentML = "in_memory\\temp_extent" gp.Select_analysis(nestIdsBufferFC, tempExtentML, "NEST_ID = " + str(nestId)) gp.extent = tempExtentML gp.extent = snapExtentToRaster(gp.extent, habGrd)
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.