I am trying to generate a route where each point in the route has progressively a lower elevation than the last point.

So a route would look like this:

  [A, B, C, D, E]

So E, would be lower than D in elevation, and D would be lower than C and so on.

I have generated an array of objects with some topography data, each having that elevation value:

  var topographyData = [{
    "latlng": {
        "lat": 40.74519262218158,
        "lng": -73.76163064211683
    "address": {},
    "topography": {
        "elevation": 29.400000000001455,
        "slope": 2.384061102283327,
        "aspect": 175.2363583094472,
        "resolution": 57.84535686132979
}..{...}, {...}]

I am trying to connect each point based on the elevation property. I want to find the closet other point which has a lower elevation.

function closestLatLangLowerInElevation() {
  const dataForClosest = topographyData
      (data) =>
        data.topography.elevation < 36 &&
        (data.latlng.lat != lowestEl.latlng.lat ||
          data.latlng.lng != lowestEl.latlng.lng)
    .map((dataObj) => [dataObj.latlng.lat, dataObj.latlng.lng]);

  return L.marker(
    L.GeometryUtil.closest(map, dataForClosest, lowestEl.latlng),
    { icon: violetIcon }

This is a visual example.

enter image description here

That function does find the closest LatLng with a lower elevation point but i'd like the search to be below latitude.

Referring back to the image maybe with each call to the function it has a clause which searches in a forward motion, but on a downward (or upward if the elevation was going in another direction) trend.

Is there a method or plugin in Leaflet which can help with this problem?

  • 1
    So if I understand you correctly, for a given point you want to find closest point with lower elevation and lower latitude?
    – TomazicM
    Aug 24 at 7:51
  • @TomazicM Yes that is what I am looking for! Aug 24 at 19:29
  • One more question: what is the total number of points that are being searched when constructing the route?
    – TomazicM
    Aug 24 at 19:50
  • Well that was the rational for the last post. Because i am using a circle as the scope of the search, I start with an array of degrees [0, 345, 330, 315, 300, 285, 270, 255, 240, 225, 210, 195, 180, 165, 150, 135, 120, 105, 90, 75, 60, 45, 30, 15], Aug 24 at 21:00
  • And I have 4 points for each degree; If you look at the other post you can get a visualization of what is happening. Aug 24 at 21:06


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy