tkrajina / srtm.py

Geo elevation data parser for "The Shuttle Radar Topography Mission" data
Apache License 2.0
240 stars 57 forks source link

"Approximation" algorithm #36

Open nawagers opened 6 years ago

nawagers commented 6 years ago

The "approximation" algorithm is poorly named and the implementation doesn't make sense to me.

The word approximation means an estimate or "not exact". Generally an approximation is used when the algorithm is faster or requires less memory. The trade off is less accuracy. Based on what the functions are doing, the code is "interpolating". Interpolation tries to improve accuracy by building a model of multiple points and calculating the most likely value. Approximation and Interpolation are basically opposites in this context. I suggest the public interface is changed to use "Interpolate" instead.

In regards to implementation, the function "approximation" appears to be using a linear distance weighted function. However, it doesn't use the closest value to the point of interest. Currently, if the point lies in the center cell of a 3x3 grid:

---
-+-
---

The cells used to compute the elevations and the weights are as follows:

-*-
*-*
-*-

The center cell is not checked. This is illogical since it contains the closest point. Also, the weighting function does not appear to be any standard GIS method

I suggest the library offer 3 spatial interpolation methods: Nearest Neighbor, Natural Neighbor, Inverse Distance Weighted.

Nearest Neighbor would return the elevation of the cell that contains the point, same as the current implementation using "Approximate=False" Natural Neighbor would use the four closest points and weighting them based on the new areas of a voronoi tesselation: Natural Neighbor IDW includes all point in some radius and weighted by 1/distance. This could be offered by "IDW5"

-*-
***
-*-

and "IDW13"

--*--
-***-
*****
-***-
--*--

Thoughts?