Demystifying geographic data for display
A fellow Hacker Schooler wanted to show some geographic data on a grid-aligned set of terrain splines with *three.js*, but he was having some trouble. His data came as a flat JSON array grouped by threes. ... [-118.433333333,32,-821], ... The data was on a grid, but he didn't know the dimensions of the grid. Furthermore, the grid seemed to have been rotated; both the **x** and **y** values changed, rather than one staying constant along each row.
He needed to find the resolution of the data before he could generate terrain splines and iterate through to make an elevation map.
Finding the jumps
If the data is on a grid, there should be an easy way to detect the resolution by looking for when the data jumps. If we detect how often the jumps are, then we'll have found the major axis of the 2D storage arrangement of the grid.
To do this generally, I wrote some routines in javascript to calculate the distance between every adjacent pair of data points.
Having obtained a list of deltas, I found the standard deviation of the deltas and then searched for the indexes of deltas that jumped more than a standard deviation. These deltas are the row-reset.
After finding the unusual deltas, I looked at the deltas of their indexes to find the major axis' resolution.
deltas_indexes = [6, 13, 20]; deltas_indexes_deltas = [7, 7];
With the major axis, the minor axis is easy to find.
major = 7; minor = data.length / major;
And then the problem is solved! Axis aligned data is then easily shunted into splines of the proper resolution.








