GeoJSON parse coordinates and set values to custom structure

207 Views Asked by At

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

0

There are 0 best solutions below