arcpy RasterToNumPyArray causes shift in location of values

المشرف العام

Administrator
طاقم الإدارة
I am converting a couple rasters to arrays, then performing calculations on them. First step- polygon to raster. This creates a 1/0 mask that I can multiply the larger raster by. After noticing my final outputs were a little off, I output the intermediate steps to see what was going on.

# Set environmental variables for outputlossm = r'C:\data'
arcpy.env.overwriteOutput = True
arcpy.env.outputCoordinateSystem = lossm
arcpy.env.cellSize = lossm
arcpy.env.snapRaster = lossm
cell_size = 0.00025
# convert polygon to raster- the maskarcpy.PolygonToRaster_conversion(polygon,"ISO",country_boundary_tiff)
#get number of rows and columns of aoiarcpy.GetRasterProperties_management(country_boundary_tiff,"COLUMNCOUNT")numRowResult = arcpy.GetRasterProperties_management(country_boundary_tiff,"ROWCOUNT")numCol = int(numColResult.getOutput(0))numRow = int(numRowResult.getOutput(0))# Create raster object from fileboundary_obj = arcpy.Raster(country_boundary_tiff)# get the xy coords of lowerleft corner of boundary objectdesc = arcpy.Describe(boundary_obj)
gmb_mx = desc.extent.XMin
gmb_my = desc.extent.YMin
# convert boundary object to arrayboundary_array = arcpy.RasterToNumPyArray(boundary_obj,arcpy.Point(gmb_mx,gmb_my),numCol,numRow,cell_size)# conver array back to tifoutputraster = arcpy.NumPyArrayToRaster (boundary_array ,arcpy.Point(gmb_mx,gmb_my),0.00025)outputraster.save(r'C:\Users\' + '\\' + country+ '_boundary2.tif')At this point the file has gone from polygon -> raster -> numpyarray -> raster, and in the process has moved up 1 pixel. I did another test where I added another iteration of raster -> array, and it moved the output raster even further up.

The cell size, numrows, numcol, and extent are identical for these 2 files pictured (green= raster in the right place, orange= raster shifted). So fixing the x/y parameters when running rastertoarray won't change anything. It is the location of the cells being coded to 1 that is changing. The mask (value 1) is shifting around within the extent of the entire raster.

Can someone help by telling me how to keep the raster from shifting?Thanks



أكثر...
 
أعلى