1

I'm currently taking a class of Algorithms and have to do a project related to Graphs, more specifically finding the shortest path in a set of locations. The problem is we not only have to take distance between points into account, we also need to know their altitude. Now, I've searched openstreetmaps, google elevation api, etc, and I've yet to find a way to get the elevation. From what I understand, osm only has elevation for a short amount of nodes.

Here is an example using curl from open-elevation's API. Is there a way to make a simple program (preferably C/C++) to do what I want? I've tried already but couldn't get it to work.

My first thought was using system(). If it worked, then I could read locations and create a string to pass to the function. However, I'm gettint a lot of compiler errors related to the quotes. Didn't I already escape everything? Here is the code:

#include <stdlib.h>

int main()
{
    system("curl -X POST \\
    https://api.open-elevation.com/api/v1/lookup \\
    -H \'Accept: application/json\' \\
    -H \'Content-Type: application/json\' \\
    -d \'{
    \"locations\":
    [
          {
              \"latitude\": 41.1488064,
              \"longitude\": -8.6094618
          },
          {
              \"latitude\":20,
              \"longitude\": 20
          },
          {
              \"latitude\":41.161758,
              \"longitude\":-8.583933
          }
      ]

  }\'");

    return 0;
}

EDIT: Apparently removing the spaces worked. Even then, is there a better way to do this?

mrzephyr
  • 79
  • 1
  • 5

1 Answers1

2

I'm the author of the Open-Elevation service you used :) Feel free to ask me any questions.

It is generally not good practice to use system(). You should look into a library that allows you make simple GET requests in C. Since you already know how to use cURL, here's a fun trick! You can ask cURL to generate C code for you, and then adapt it. Just pass it the --libcurl option!

Jorl17
  • 361
  • 3
  • 5
  • Great project. But it seems to be down. And I can't find the source of the provided date? Where does it come from? Thanks :) – vomi Jun 30 '20 at 12:49