1

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. Here are some examples of these input rasters:

enter image description here enter image description here enter image description here

In these images, the NoData is symbolized in black, and 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. I've tried multiple combinations of the Snap Raster and Extent environments, but none of them have produced the desired result of all of the rasters having a box of NoData (changed to -3*), like this:

image desc

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.

enter image description here enter image description here

These images show two different outputs of the above code. 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.

7
  • Can you edit your question and show some examples of what your input raster looks like with respects to your polygon dataset. Also when you show this make sure nodata is symbolized to some random colour. I assume what you are showing in your images now is the result of your con() tool? Better still if you could share your data that would allow others to test whats wrong.
    – Hornbydd
    Jul 18, 2022 at 19:22
  • Re-calculation of raster to new extent is missing. You compute NULL cells of old raster.
    – FelixIP
    Jul 18, 2022 at 19:25
  • @FelixIP I'm not sure I understand what you mean, could you please elaborate?
    – Beck
    Jul 18, 2022 at 19:44
  • NewR = Raster(file) tempR = newR+0 Con(isnull(tempR ....
    – FelixIP
    Jul 18, 2022 at 20:02
  • 2nd line will adjust original to new extent.
    – FelixIP
    Jul 18, 2022 at 20:06

1 Answer 1

0

It's not entirely clear in your screen shots if your input datasets have a larger extent to what is visible (the grey dotty area), hence me asking to symbolize nodata is some other colour so we can see the True extents of your inputs. So assuming the extents of input rasters are literally no bigger than the dotty areas then a workflow would be this:

  1. Create a constant value raster of -3, set extent to your polygon dataset, cell size to your input raster, snap raster to your input raster. So you have one big raster with only -3 values.
  2. Mosaic your input with your -3 constant raster using the mosaic to new raster tool and have a play with the Mosaic Operator, assuming negative numbers ever occur in your input raster you could use maximum or try first/last depending upon input sequence of rasters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.