Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support samples along a path #37

Closed
ajnisbet opened this issue Mar 28, 2021 · 6 comments
Closed

Support samples along a path #37

ajnisbet opened this issue Mar 28, 2021 · 6 comments

Comments

@ajnisbet
Copy link
Owner

ajnisbet commented Mar 28, 2021

The google maps api lets you sample along a path. I don't have plans to support this any time soon in Open Topo Data, but a user submitted a patch for v1.5.0 to add this functionality!

Update 2021-09-04: The patch below has some issues, here's a better method that I'm adding: Sampling points along a lat,lon path

Old patch
--- opentopodata.orig/api.py	2021-03-10 16:36:58.761755648 +0100
+++ opentopodata/api.py	2021-03-21 09:43:48.369460334 +0100
@@ -190,6 +190,44 @@
         return _parse_polyline_locations(locations, max_n_locations)
 
 
+def _create_path_with_samples(lats, lons, samples):
+    """Create a path with the requested samples starting from given path
+
+
+    Args:
+        lats: The latitudes
+        lons: The longitudes
+        samples: Number of point in the segments of the path.
+
+    Returns:
+        lats: List of latitude floats.
+        lons: List of longitude floats.
+    """
+
+    if(len(lats) < 2):
+        return lats, lons
+    if(int(samples) < 2):
+        samples = 2;
+    lats1 = []
+    lons1 = []
+    lat1 = lats[0]
+    lon1 = lons[0]
+    for i in range(1, len(lats)):
+        lat2 = lats[i]
+        lon2 = lons[i]
+        dlat = (lat2 - lat1) / (int(samples) - 1)
+        dlon = (lon2 - lon1) / (int(samples) - 1)
+        lat = lat1
+        lon = lon1
+        for i in range(0, int(samples)):
+            lats1.append(lat)
+            lons1.append(lon)
+            lat += dlat
+            lon += dlon
+
+    return lats1, lons1
+
+
 def _parse_polyline_locations(locations, max_n_locations):
     """Parse and validate locations in Google polyline format.
 
@@ -399,6 +437,11 @@
             request.args.get("locations"), _load_config()["max_locations_per_request"]
         )
 
+        samples = request.args.get("samples")
+        if not samples:
+            samples = 2
+        lats, lons = _create_path_with_samples(lats, lons, samples)
+
         # Get the z values.
         datasets = _get_datasets(dataset_name)
         elevations, dataset_names = backend.get_elevation(

@ajnisbet
Copy link
Owner Author

Closing for now, will consider reopening if there's more demand

@dansku
Copy link

dansku commented Aug 31, 2021

This would be extremely valuable for LOS calculations.

@ajnisbet
Copy link
Owner Author

This is a well-timed reminder, I implemented this for a different project recently so I'll work on adding it to Open Topo Data. I also notice now that the code I shared above is incorrect, it doesn't account for projection properly.

@dansku out of curiosity, what are LOS calculations?

@ajnisbet ajnisbet reopened this Aug 31, 2021
@bluthen
Copy link

bluthen commented Aug 31, 2021

LOS is line of sight I think. So if you are planning radio or free space optic networks, maybe other applications.

@dansku
Copy link

dansku commented Aug 31, 2021

Sorry indeed that is line of sight.
I would like to know how can I get the altitude map between two points, for that i would need a few samples between points. Any idea how to add the correct implementation? Thank you

@ajnisbet
Copy link
Owner Author

ajnisbet commented Sep 7, 2021

This is now live: https://api.opentopodata.org/v1/ned10m?locations=36.3407,-121.7061|36.4212,-121.4990&samples=10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants