Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
edited tags
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
Added code that deletes objects, in order to free RAM
Source Link
Delonix R.
  • 795
  • 6
  • 15
  for rows in range (0,4):
      for columns in range (0,5):
          arcpy.AddMessage('> Attempt to extract raster [row]-[col]: [' + str(rows)+ ']-['+str(columns)+']...')
          try:
              small_raster_lower_left  = arcpy.Point(large_raster_extent.XMin + (columns * window_size * large_raster_cellsize_X),
                                                     large_raster_extent.YMin + (rows    * window_size * large_raster_cellsize_Y)
                                                     )


              arcpy.AddMessage('> Raster to Numpy...')
              numpy_array  = arcpy.RasterToNumPyArray(large_raster,
                                            small_raster_lower_left,
                                            window_size,
                                            window_size,
                                            nodata_to_value=-99999
                                            )

              arcpy.AddMessage('> small raster coordinates. X: {0}, Y: {1}'.format(small_raster_lower_left.X,small_raster_lower_left.Y))

              arcpy.AddMessage('> Numpy to raster...')
              small_raster = arcpy.NumPyArrayToRaster(numpy_array,            
                                      small_raster_lower_left,
                                      large_raster_cellsize_X,
                                      large_raster_cellsize_Y,
                                      value_to_nodata = -99999
                                      )

              arcpy.DefineProjection_management(small_raster, large_raster_spatial_ref)
              small_raster_name = "small_dem_" + str(columns+rows*10)
              arcpy.AddMessage('> Success! Saving raster: ' + small_raster_name + '...')  
              small_raster.save(small_raster_name)
              del numpy_array
              del small_raster
            

         except:
              arcpy.AddMessage('> Fault! Trying next window...')
              del numpy_array
              del small_raster
  for rows in range (0,4):
      for columns in range (0,5):
          arcpy.AddMessage('> Attempt to extract raster [row]-[col]: [' + str(rows)+ ']-['+str(columns)+']...')
          try:
              small_raster_lower_left  = arcpy.Point(large_raster_extent.XMin + (columns * window_size * large_raster_cellsize_X),
                                                     large_raster_extent.YMin + (rows    * window_size * large_raster_cellsize_Y)
                                                     )


              arcpy.AddMessage('> Raster to Numpy...')
              numpy_array  = arcpy.RasterToNumPyArray(large_raster,
                                            small_raster_lower_left,
                                            window_size,
                                            window_size,
                                            nodata_to_value=-99999
                                            )

              arcpy.AddMessage('> small raster coordinates. X: {0}, Y: {1}'.format(small_raster_lower_left.X,small_raster_lower_left.Y))

              arcpy.AddMessage('> Numpy to raster...')
              small_raster = arcpy.NumPyArrayToRaster(numpy_array,            
                                      small_raster_lower_left,
                                      large_raster_cellsize_X,
                                      large_raster_cellsize_Y,
                                      value_to_nodata = -99999
                                      )

              arcpy.DefineProjection_management(small_raster, large_raster_spatial_ref)
              small_raster_name = "small_dem_" + str(columns+rows*10)
              arcpy.AddMessage('> Success! Saving raster: ' + small_raster_name + '...')  
              small_raster.save(small_raster_name)

         except:
              arcpy.AddMessage('> Fault! Trying next window...')
  for rows in range (0,4):
      for columns in range (0,5):
          arcpy.AddMessage('> Attempt to extract raster [row]-[col]: [' + str(rows)+ ']-['+str(columns)+']...')
          try:
              small_raster_lower_left  = arcpy.Point(large_raster_extent.XMin + (columns * window_size * large_raster_cellsize_X),
                                                     large_raster_extent.YMin + (rows    * window_size * large_raster_cellsize_Y)
                                                     )


              arcpy.AddMessage('> Raster to Numpy...')
              numpy_array  = arcpy.RasterToNumPyArray(large_raster,
                                            small_raster_lower_left,
                                            window_size,
                                            window_size,
                                            nodata_to_value=-99999
                                            )

              arcpy.AddMessage('> small raster coordinates. X: {0}, Y: {1}'.format(small_raster_lower_left.X,small_raster_lower_left.Y))

              arcpy.AddMessage('> Numpy to raster...')
              small_raster = arcpy.NumPyArrayToRaster(numpy_array,            
                                      small_raster_lower_left,
                                      large_raster_cellsize_X,
                                      large_raster_cellsize_Y,
                                      value_to_nodata = -99999
                                      )

              arcpy.DefineProjection_management(small_raster, large_raster_spatial_ref)
              small_raster_name = "small_dem_" + str(columns+rows*10)
              arcpy.AddMessage('> Success! Saving raster: ' + small_raster_name + '...')  
              small_raster.save(small_raster_name)
              del numpy_array
              del small_raster
            

         except:
              arcpy.AddMessage('> Fault! Trying next window...')
              del numpy_array
              del small_raster
edited body
Source Link
Hornbydd
  • 44.6k
  • 5
  • 42
  • 84

pdps: When using DefineProjection in an empty raster (or more precisely: in a raster with all its cells null), throws an error. That's why I used try/except within the nested loops.

pd: When using DefineProjection in an empty raster (or more precisely: in a raster with all its cells null), throws an error. That's why I used try/except within the nested loops.

ps: When using DefineProjection in an empty raster (or more precisely: in a raster with all its cells null), throws an error. That's why I used try/except within the nested loops.

edited tags
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
Loading
added 4 characters in body
Source Link
Delonix R.
  • 795
  • 6
  • 15
Loading
Edit to add OS, RAM and ArcGIS specs.
Source Link
Delonix R.
  • 795
  • 6
  • 15
Loading
Source Link
Delonix R.
  • 795
  • 6
  • 15
Loading