Raster Calculation and Weighted Sum

1220
5
01-31-2018 04:49 PM
deleted-user-wXI1z2K2eX3q
New Contributor

I am attempting to create a cost surface that incorporates the use of a DEM (slope raster), a Landcover Raster, Strahler stream order raster, lakes raster, roads raster, and a trails raster. I am under the assumption that the traveler will ALWAYS choose the trail or the road. I have many start and end points to run my least cost paths. I have also already reclassified all the rasters to a common scale. 

I would like to know if there is anyone who knows how it is possible for me to somehow burn the roads and trails rasters into the other rasters. I would like the trails and roads to retain a value of "1" after raster calculation or weighted sum, while all other raster values are added together. Is this possible without weighting each raster differently?

0 Kudos
5 Replies
DanPatterson_Retired
MVP Emeritus

you can obviously just use the Con tool  if the road layer exists on its own, and your cost surface is another layer, it would be in the form

Con("Road" == 1, 1, "CostSurface")  assuming your roads are classed as 1 and non-road 0 

Check the examples in the help topics and on GeoNet, there are ton of 'Con' examples

deleted-user-wXI1z2K2eX3q
New Contributor

Obviously. Thank you, Dan.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Raymond, I meant 'obviously' in that there is so little in the strictly 'conditional' toolset to choose from.

Con should be renamed 'Where'

# ---- make a cost surface -----
costsurface = np.random.randint(2, 20, size=(10, 10))

# ---- make some roads ----
roads = np.zeros_like(costsurface)
roads[:, 2] = 1
roads[2, :] = 1
roads 
array([[0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
       [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
       [0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0, 0, 0, 0, 0, 0]])

# ---- Find out 'where' the roads are in the cost surface ---
# and 'embed' into it
embedded = np.where(roads == 1, roads, costsurface)

embedded
array([[ 6,  3,  1, 17, 16,  8,  5,  5,  2, 13],
       [13,  3,  1,  7,  6, 10,  7, 17,  5, 15],
       [ 1,  1,  1,  1,  1,  1,  1,  1,  1,  1],
       [14,  6,  1,  6, 10, 14, 15,  5,  9,  7],
       [ 4, 18,  1, 13, 11, 12, 16, 15,  3, 12],
       [ 7,  3,  1, 14,  3, 15, 19, 19, 12, 12],
       [ 7, 11,  1, 19,  7,  4, 13,  2, 11,  8],
       [17, 19,  1,  9,  9, 14, 14, 15, 13,  5],
       [11,  2,  1, 15,  8,  3, 15,  4, 19, 11],
       [17,  4,  1,  7,  2,  7,  7, 12, 12,  9]])
0 Kudos
deleted-user-wXI1z2K2eX3q
New Contributor

No worries! I must have read your reply during a state of frustration . I really appreciate your swift and accurate response! Con tool worked beautifully.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Glad it worked out Raymond

0 Kudos