Menu

invalid use of incomplete type ‘class GeographicLib::GeodesicLine’GCC Geodesic.hpp(28, 9): forward declaration of ‘class GeographicLib::GeodesicLine’

Help
Master
2022-04-18
2022-04-18
  • Master

    Master - 2022-04-18

    Hi,
    I'm trying to port my python code to its C++ counter part, but when trying to use InverseLine, I'm facing the following error :

    invalid use of incomplete type ‘class GeographicLib::GeodesicLine’GCC
    Geodesic.hpp(28, 9): forward declaration of ‘class GeographicLib::GeodesicLine’
    

    and this is the snippet I'm trying to run:

    struct Waypoints
    {
        std::vector<std::tuple<float,float>> gps_coordinate;
        float total_distance;
    };
    Waypoints create_waypoints(float lat1, float lon1, float lat2, float lon2, float distance, bool display_result=false)
    {
        const Geodesic& geod = Geodesic::WGS84();
        auto l = GeographicLib::Geodesic::WGS84().InverseLine(lat1, lon1, lat2, lon2);
        auto parts = int(std::ceil(l.s13 / distance));
        std::vector<std::tuple<float,float>>waypoints;
        auto total_distance = l.s13; 
        for(int i =0; i<parts+1; i++)
        {
            if (display_result)
                if (i == 0)
                    printf("latitude longitude azimuth distance ");
            auto s = std::min(distance * i, l.s13);
            auto g = l.Position(s, geod.LONG_UNROLL);
            waypoints.emplace_back((g["lat2"],g["lon2"]));
            if (display_result)
                std::cout<<g["lat2"]<< g["lon2"]<< g["azi2"]<<g["s12"]<<"\n";
    
        }
    }
    

    Whats wrong here and how can I use this method?
    Thanks a lot in advance

     

    Last edit: Master 2022-04-18
  • Master

    Master - 2022-04-18

    I found another sample here : https://geographiclib.sourceforge.io/html/classGeographicLib_1_1GeodesicLine.html which uses
    Geodesic geod(Constants::WGS84_a(), Constants::WGS84_f());
    to construct a geod and that fixes the issues (the commented alternative which I used fails)
    and instead of l.s13, I guess I should be using Distance() method instead right?
    now how should I port position:

    # python
    g = l.Position(s, Geodesic.STANDARD | Geodesic.LONG_UNROLL)
    

    to C++? it seems position here is completely different!
    for the reference this is my python snippet I'm trying to port to C++:

     # python 
     def create_waypoints(point_a, point_b, distance, display_result=False):
        """
            Creats a series of waypoints between two gps coordinate with distance 
            meters apart.
    
        Args:
            point_a (tuple(float, float)): gps coordinate for point a 
            point_b (tuple(float, float)): gps coordinate for point b 
            distance (float, optional): distance between waypoints in meters.
            display_result (bool, optional): whether to display intermediate results (like gps, azimuth, etc). Defaults to False.
    
        Returns:
            list: a list of waypoints between the given gps coordinates
        """
        lat1, lon1 = point_a
        lat2, lon2 = point_b
        l = geodesic.Geodesic.WGS84.InverseLine(lat1, lon1,lat2, lon2)
        parts = int(math.ceil(l.s13 / distance))
        waypoints = []
        total_distance = l.s13 
        for i in range(parts + 1):
            if display_result:
                if i == 0:
                    print("latitude longitude azimuth distance ")
            s = min(distance * i, l.s13)
            g = l.Position(s, Geodesic.STANDARD | Geodesic.LONG_UNROLL)
            waypoints.append((g['lat2'],g['lon2']))
            if display_result:
                print(f"{g['lat2']:.5f} {g['lon2']:.5f} {g['azi2']:.5f} {g['s12']:.0f} ")
                # print(f"{g['lat2']:.5f}, {g['lon2']:.5f}")
    
        return waypoints, total_distance
    
     

    Last edit: Master 2022-04-18
  • Master

    Master - 2022-04-18

    OK, I guess I found it, Position, takes out variables, which I believe would initialize them after the method call.

     
  • Charles Karney

    Charles Karney - 2022-04-18

    Correct. The methods in C++ library typically only return single values. For most methods, the results are via reference arguments.

     

Anonymous
Anonymous

Add attachments
Cancel