Changing the size of rasters with Snap Raster and Extent environments

447
0
07-18-2022 11:54 AM
Labels (3)
BeckB
by
New Contributor III

I'm using ArcGIS Pro 2.9.3 and Python 3.3. I have a large number of rasters that I'd like to make have the same number of rows and columns. To do that, I want to set their extent to be the same as a shapefile called Hudson_Plain_coast_Project.shp. I've tried multiple combinations of the Snap Raster and Extent environments, as suggested by this post, but none of them have produced the desired result of all of the rasters having a box of NoData (changed to -3*), like this:

 
 
 
BeckB_7-1658169912940.png

In this image, the teal polygon is the Hudson_Plain_coast_Project.shp that I want to use as the extent. I've used the Feature to Raster tool to make a raster copy of it (named RasHudson_Plain_coast) for using in the Snap Raster environment.

In the Environments tab, it says the project has the correct extent environment, which I set to be "Same As: Hudson_Plain_coast_Project." The left is -2432.32899999991, right 1044642.9029, bottom 5633641.8129, top 6660766.088 (in metres).

My code is:

# Import modules
import arcpy
import glob
import os
import collections
import sys
from arcpy.sa import *
from arcpy import env
from osgeo import gdal
from osgeo.gdalconst import *
from osgeo import gdalconst

##setting environment parameters
#set snapraster environment
arcpy.env.snapRaster = r'C:\Users\orang\Documents\ArcGIS\Projects\sentinel3\sentinel3.gdb\RasHudson_Plain_coast'
#set extent environment
arcpy.env.extent = arcpy.Extent(-2432.329000, 5633641.812900, 1044642.902900, 6660766.088000)
#set name
file = r'C:\Users\orang\OneDrive\Beck\Uploads\sentinel\evi2016\Merged_20160201.tif'

##apply function ans save setnull images
null2016 = arcpy.sa.Con(IsNull(file),-3,file)

I've tried running this code with and without setting the Snap Raster and/or Extent environment, but it has consistently led to the extent being slightly to the side instead of centred on Hudson_Plain_coast.

 
BeckB_5-1658169677382.png
BeckB_6-1658169704396.png

 

What do I have to change for my extent to consistently be in the desired location?

*I am changing the NoData cells to -3 because I am processing the outputs in a separate program called TIMESAT, which does not do well with NoData.

0 Kudos
0 Replies