I'm using ArcGIS 10.4x and Python/numpy for this question. Can anyone suggest an efficient way to determine the array location of the nearest element whose value is less than the search element? As an example, if I provide the script a row/col number of a numpy array (the element value for example = 42.5), what is the most efficient way to find the row/col values for the nearest element whose value is less than the 42.5 value? I will have many source cells to iterate through and more often than not, an element with a lower value will be relatively close, so ideally I'd have a way where the search originates from the elements nearest to the source and radiates outwards until a solution is found.
[GIS] Nearest numpy array element whose value is less than the current element
arcgis-10.4arcpynumpy
Related Solutions
This error means that you are trying to get data from the 656th row of the sediment_transport
array which is only 655 rows long. This is probably happening at the outlet of the flow direction raster. At this spot, the flow direction raster is saying something like "water will flow south from this cell." When you try to index the cell in sediment_transport
that is one cell south, it doesn't exist and is throwing the error.
To get around this, you could just add a try
and except
and fill elevation_change
with some placeholder value like -1
:
for [i, j], flow in np.ndenumerate(flow_direction_np):
try:
if flow == 32:
elevation_change[i, j] = sediment_transport_np[i - 1, j - 1]
elif flow == 16:
elevation_change[i, j] = sediment_transport_np[i, j - 1]
elif flow == 8:
elevation_change[i, j] = sediment_transport_np[i + 1, j - 1]
elif flow == 4:
elevation_change[i, j] = sediment_transport_np[i + 1, j]
elif flow == 64:
elevation_change[i, j] = sediment_transport_np[i - 1, j]
elif flow == 128:
elevation_change[i, j] = sediment_transport_np[i - 1, j + 1]
elif flow == 1:
elevation_change[i, j] = sediment_transport_np[i, j + 1]
elif flow == 2:
elevation_change[i, j] = sediment_transport_np[i + 1, j + 1]
except IndexError:
elevation_change[i, j] = -1 #Placeholder for flow direction outlet
I also want to point out that if you are trying to do a flow accumulation of the sediment_transport
data, the Flow Accumulation geoprocessing tool in ArcGIS has a parameter for an optional weight raster. The result would have the accumulated values from the in_weight_raster
instead of just a count of upstream cells.
Okay, posting for posterity's sake now.
My team and I did find a way to successfully implement data driven pages with domain values (for the ultimate purpose of a printing service) using a combination of python and spatial views that were created in the database. Basically, every field I wanted on the print layout was included in the spatial view. The python still looped through element names and domain lists as I described above.
The problem with this is that it's abominably slow. We didn't want our end users to wait a solid minute or more (depending on number of pages) for any response from the print button.
The eventual solution we settled on is much simpler and faster. We have the print button generating an html page that pulls data from the database and formats it in pretty much an exact replica of the .mxd we were using. For the map it uses a function on the rest endpoint to generate an image from the map service.
Best Answer
You can do this with scipy (I hope it is included in ArcGis 10.4).