Select to view content in your preferred language

ArcGIS Raster

3587
7
11-17-2015 10:03 AM
SamanArmal1
Deactivated User

Hi all,

I have boundary which has stored in a raster. The only available data in this raster, resides on he boundary itself,  and there is no data available either inside or outside the boundary. I am trying to expand  the raster beyond the boundary in a way that each row of cells has the same value the adjacent cell on boundary shows. Any idea how I can do this extrapolation?

Many thanks in advance,

Tags (2)
0 Kudos
7 Replies
DanPatterson_Retired
MVP Emeritus

Are you wanting to reflect the edge values like the following numpy example? and if so, how far inwards do you want to reflect/mirror?

>>> import numpy as np
>>> a = np.array([[1,1,1],[1,0,1],[1,1,1]])
>>> a
array([[1, 1, 1],
      [1, 0, 1],
      [1, 1, 1]])
>>> np.pad(a,1,mode="edge")
array([[1, 1, 1, 1, 1],
      [1, 1, 1, 1, 1],
      [1, 1, 0, 1, 1],
      [1, 1, 1, 1, 1],
      [1, 1, 1, 1, 1]])
>>>

Perhaps a better illustration

  • set all the cells within 2 cells of the boundary to 0
  • pad the raster by mirroring the edge by 2 cells
>>> c = np.arange(100,dtype='int32').reshape((10,10))
>>> c
array([[ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
       [20, 21, 22, 23, 24, 25, 26, 27, 28, 29],
       [30, 31, 32, 33, 34, 35, 36, 37, 38, 39],
       [40, 41, 42, 43, 44, 45, 46, 47, 48, 49],
       [50, 51, 52, 53, 54, 55, 56, 57, 58, 59],
       [60, 61, 62, 63, 64, 65, 66, 67, 68, 69],
       [70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [80, 81, 82, 83, 84, 85, 86, 87, 88, 89],
       [90, 91, 92, 93, 94, 95, 96, 97, 98, 99]])
>>> c[2:8,2:8] = 0
>>> c
array([[ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
       [20, 21,  0,  0,  0,  0,  0,  0, 28, 29],
       [30, 31,  0,  0,  0,  0,  0,  0, 38, 39],
       [40, 41,  0,  0,  0,  0,  0,  0, 48, 49],
       [50, 51,  0,  0,  0,  0,  0,  0, 58, 59],
       [60, 61,  0,  0,  0,  0,  0,  0, 68, 69],
       [70, 71,  0,  0,  0,  0,  0,  0, 78, 79],
       [80, 81, 82, 83, 84, 85, 86, 87, 88, 89],
       [90, 91, 92, 93, 94, 95, 96, 97, 98, 99]])
>>> d = np.pad(c,2,mode='edge')
>>> d
array([[ 0,  0,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  9,  9],
       [ 0,  0,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  9,  9],
       [ 0,  0,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  9,  9],
       [10, 10, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 19, 19],
       [20, 20, 20, 21,  0,  0,  0,  0,  0,  0, 28, 29, 29, 29],
       [30, 30, 30, 31,  0,  0,  0,  0,  0,  0, 38, 39, 39, 39],
       [40, 40, 40, 41,  0,  0,  0,  0,  0,  0, 48, 49, 49, 49],
       [50, 50, 50, 51,  0,  0,  0,  0,  0,  0, 58, 59, 59, 59],
       [60, 60, 60, 61,  0,  0,  0,  0,  0,  0, 68, 69, 69, 69],
       [70, 70, 70, 71,  0,  0,  0,  0,  0,  0, 78, 79, 79, 79],
       [80, 80, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 89, 89],
       [90, 90, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 99, 99],
       [90, 90, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 99, 99],
       [90, 90, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 99, 99]])

>>> import arcpy
>>> raster = arcpy.NumPyArrayToRaster(d)
>>> raster.save("f:/temp/raster.tif")

pad_clip_raster.png

with some random color scheme

SamanArmal1
Deactivated User

Thank you for your respond. Yes, its generally the same procedure. The only difference is that  I am looking for producing cells with the same values.

0 Kudos
DanPatterson_Retired
MVP Emeritus

You can pretty well do what you want, the documentation is good, here is a small sampling

>>> a
array([[1, 1, 1],
       [1, 0, 1],
       [1, 1, 1]])
>>> aa = np.pad(a,pad_width=2,mode='constant', constant_values=(3,4))
>>> aa
array([[3, 3, 3, 3, 3, 4, 4],
       [3, 3, 3, 3, 3, 4, 4],
       [3, 3, 1, 1, 1, 4, 4],
       [3, 3, 1, 0, 1, 4, 4],
       [3, 3, 1, 1, 1, 4, 4],
       [3, 3, 4, 4, 4, 4, 4],
       [3, 3, 4, 4, 4, 4, 4]])
>>> ab = np.pad(a,pad_width=2,mode='constant', constant_values=(5,5))
>>> ab
array([[5, 5, 5, 5, 5, 5, 5],
       [5, 5, 5, 5, 5, 5, 5],
       [5, 5, 1, 1, 1, 5, 5],
       [5, 5, 1, 0, 1, 5, 5],
       [5, 5, 1, 1, 1, 5, 5],
       [5, 5, 5, 5, 5, 5, 5],
       [5, 5, 5, 5, 5, 5, 5]])
>>>
0 Kudos
DarrenWiens2
MVP Honored Contributor

I believe the out-of-the-box ArcGIS tool for this is Euclidean Allocation.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Yes after you expand the extents, change nodata to some value then allocate, but It won't give you a constant value unless your edge values are constant initially.  And SA doesn't handle the interior clipping as handlily as numpy.  Some things, even if it is prep work, are better done outside SA.

0 Kudos
DarrenWiens2
MVP Honored Contributor

I interpret this as wanting to smear the boundary values, which Euclidean Allocation should do.

0 Kudos
DanPatterson_Retired
MVP Emeritus

I read that he wanted a constant value around the edge...in any event, I can create any kind of value around the edge just as easily, you can even apply functions, like random etc

His post from above

"Thank you for your respond. Yes, its generally the same procedure. The only difference is that  I am looking for producing cells with the same values."

0 Kudos