microsoft / cpprestsdk

The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.
Other
7.97k stars 1.65k forks source link

GeoJSON parse coordinates and set values to custom structure #1614

Open jadhavshital opened 3 years ago

jadhavshital commented 3 years ago

I need to set GeoJSON coordinates to this structure:

struct coord {
   double lat,
   double lon 
};

My sample JSON:

{
 "geometry": {
        "type": "LineString",
        "coordinates": [
          [
            75.9814453125,
            10.919617760254697
          ],
          [
            76.2451171875,
            11.30770770776545
          ],
          [
            76.728515625,
            11.350796722383672
          ],
          [
            76.904296875,
            10.919617760254697
          ]
        ]
 }
}

The code snippet:

auto array =  value.as_object()["coordinates"].as_array();
for(auto v = array.begin() ; v < array.end() ; v++ ){
    auto a = (*v).as_array();
    coords.push_back(createCoord(a));
}

amp::AmpFeature::coordinate createCoord(web::json::array coordsJson) {
  coord c;
  if(a.size() == XY){
      c.lon = a.at(0).as_double();
      c.lat = a.at(1).as_double();
  } 
}

In the above code I need some other way to set the structure values. This is done using cpprest-sdk json parser. We are fetching the data from sqlite db.

We are dealing with tens of thousands of such lineString geometries. Is there more efficient and faster way to set these values?

Environment : OS : Ubuntu 18.04 C++ version : 17