My problem is like the problem in the thread Finding index of nearest point in numpy arrays of x and y coordinates, but it's extended:
For better visualization here's an image
(manipulated image, original from: by 112BKS - Eigenes WerkOriginal graph/Data from [.. ? ..], CC BY-SA 3.0, link to page):
On the one hand there is a array datafield
. It consists of a numpy array with elements [value x y]
. That are the thin blue lines with the numbers (they are the value
). On the other hand there is the array orangeline
in a numpy array with elements [x y]
.
What I want to do is to calculate the value
of any elements in orangeline
.
I visualized one concrete element of orangeline
with the green circle. The value for it can I interpolate with the two elements from datafield
, visualized with the triangles. As result I get for the green circle a value
between 225 and 230.
First step:
Find for every element in orangeline
the closest element in datafield
.
(In the example that is the pink triangle.)
Second step:
Find for every element in 'orangeline' the closest element in datafield
but with another value
than the one from the first step.
(In the example that is the brown triangle.)
Third step: Interpolate the value
for every element in orangeline
from those the two founded values and the distances to those elements.
First step can be solved with
mytree = scipy.spatial.cKDTree(datafield[:, 1:3])
dist1, indexes1 = mytree.query(orangeline)
But now I don't know how to filter the datafield for the second step. Is there a solution?