How to put two rasters at the same dimension

1938
8
Jump to solution
06-12-2018 05:01 AM
paulbonnard
New Contributor III

Hi everyone,

I have two identical rasters, i use extent to put them on the same lower left corner but they havent the same shape. I want to get the size of my first raster to  apply to my second.

Do you have any idea ?

Thank You.

0 Kudos
1 Solution

Accepted Solutions
paulbonnard
New Contributor III

I think i find what i was looking for, thank you guys for answering me.

  1. description = arcpy.Describe(raster)  
  2. cellsize = description.children[0].meanCellHeight  
  3.   
  4. print cellsize 

i get 10 with this

View solution in original post

0 Kudos
8 Replies
XanderBakker
Esri Esteemed Contributor

So you have two identical rasters but they don't have the same shape? Sounds like they are not completely identical. Can you explain how the shapes differ? Are the extents the same, but the resolution (cell size and therefore rows and columns) of the rasters different? Why do you want to do this with Python (do you have a number of rasters to process in the same way?

DanPatterson_Retired
MVP Emeritus

As Xander indicates, they may differ in other ways, like cell size,

The rows and columns must also match.  If they don't then you will have to use a Resample to replicate those.

If can get messy with a combination of extent, snap raster and sampling.

Outlining the purpose of what you are doing may lead to alternate procedures (ie using numpy)

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Hi Paul,

What type of rasters are you working with (i.e. .TIF)?  Check to see if the raster that is in the correct location contains a .aux.xml file in File Explorer.  You can try copying this file and renaming it the identical raster.

0 Kudos
paulbonnard
New Contributor III

In fact this is the same raster, but i did some processing on it.

I use arcpy.RasterToNumPyArray to use it like an array and finally i made the opposit way with arcpy.NumPyArrayToRaster.

But the default parameter for cell size is 1. I lose the cell size of my first raster.

I got this :

0 Kudos
DanPatterson_Retired
MVP Emeritus

When converting back you have options for lower left corner, cell size and nodata values

NumPyArrayToRaster (in_array, {lower_left_corner}, {x_cell_size}, {y_cell_size}, {value_to_nodata})

NumPyArrayToRaster—Help | ArcGIS Desktop 

paulbonnard
New Contributor III

Yes, in fact i would like to change xcell and ycell with the input cell size of my first raster.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Paul, next time, include the script you are using in your posts to help for provide targeted answers.

0 Kudos
paulbonnard
New Contributor III

I think i find what i was looking for, thank you guys for answering me.

  1. description = arcpy.Describe(raster)  
  2. cellsize = description.children[0].meanCellHeight  
  3.   
  4. print cellsize 

i get 10 with this

0 Kudos