I have built an array of a geotiff surface taken from a LiDAR elevation map in .tif format using numpy array. See below
geotiff_array = np.array(geotiff_surface)
Since the .tif file I am importing to be manipulated in python exists on my desktop I'm not positive I can provide the file here.
from the geotiff_array I converted the array to a list using the below code snippet.
example_list = geotiff_array.tolist()
the example_list is now a nested list that I can use to manipulate the values within.
With the help of others we created the below code to iterate through the nested lists and change the following within the example_list
The below code will: 1.) skip the first and last lists in the nested list sequence - meaning not changing the values in the first and last list. 2.) skip the first and last values within the lists it is changing values within - meaning not changing the fist and last values in the individual lists. 3.) Add 100 to the values that exist between the first and last values of the individual lists and between the first and last nested lists.
for i, sub_list in enumerate(example_list[1:-1], start= 1):
for j, entry in enumerate(sub_list[1:-1][1:-1], start= 1):
if entry > 1 and j != 2 and j != len(sub_list) - 1:
example_list[i][j] += 100
print(example_list)
The issue I am running into is that when I apply the above for loop code it is correctly skipping the first and last list but it is only skipping the last value in the lists between the first and last list and not correctly skipping the first and last values within the lists it is iterating through.
Because the Geotiff file I am working in is hundreds of lists long and each lists has hundreds of values, I attempted to create a small example code to get my above code to work with an attempt at an easier troubleshoot.
The below code does work and does exactly what it is suppose to do, but when I apply the exact same code to the geotiff it runs into the errors described above.
example_list = [[ 0, 4, 5, 0, 0, 0, 0, 0],
[ 0, 4, 2, 3, 5, 5, 0, 0],
[ 0, 4, 2, 3, 5, 5, 0, 0],
[ 0, 4, 2, 3, 5, 5, 0, 0],
[ 0, 4, 2, 3, 5, 5, 0, 0],
[ 0, 4, 5, 0, 0, 0, 0, 0]]
print(example_list)
for i, sub_list in enumerate(example_list[1:-1], start=1):
for j, entry in enumerate(sub_list[1:-1][1:-1], start=1):
if entry > 1 and j != 1 and j != len(sub_list) + 1:
example_list[i][j] += 1
print(example_list)