0

I'm working in extracting smaller rasters from a bigger one (yellow). I'm using only python, some numpy maybe. I succesfully extracted a patch from a big raster, secuentially, by moving windows. So I ended up with several small rasters, 'quilted'/patching the bigger one. The code works for the first column of patches(red colored) (See graph, sample point 'A'), where the extracted raster and the source raster has the same value at any given cell (extracted raster in red means they match perfectly the source raster). However, all the patches in gray are off by one cell! See the values at sample points 'B' and 'C'. The right value in the patched raster is in the cell besides. And this displacement is kept to all the patches, except the first column. Odd that some rasters are ok and some not. What is wrong with my code?

for rows in range (0,8):
   for columns in range (0,10):
     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)
                                              )


       numpy_array = arcpy.RasterToNumPyArray(large_raster,
                                              small_raster_lower_left,
                                              window_size,
                                              window_size,
                                              nodata_to_value = -99999
                                              )

       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)
       raster_counter += 1
       small_raster_name = "small_dem_" + str(raster_counter) +"_c" + str(columns) + "_r" + str(rows)
       small_raster.save(small_raster_name)
       del numpy_array
       del small_raster

  except:
       del numpy_array
       del small_raster

enter image description here

  • Something wrong with computing coordinates of origin point. Hard to tell because your code impossible to read, too many prints. Suggest to edit by removing them – FelixIP Jul 8 '16 at 21:39
  • Try to add half cell size for both coordinates. Also set snap raster in environment settings. Much better solution create fishnet and use slice raster tool. It has polygon option in latest versions of arcgis – FelixIP Jul 9 '16 at 5:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.