Opened 7 years ago

Last modified 7 years ago

#11982 new Bugs

distance between point and linestring on spherical_equatorial ignores radius when using haversine.

Reported by: anonymous Owned by: Barend Gehrels
Milestone: To Be Determined Component: geometry
Version: Boost 1.60.0 Severity: Problem
Keywords: Cc:

Description

Distance between a point and a linestring is incorrect when using spherical_equatorial coordinates and haversine strategy. It looks like it is always using radius = 1.0.

Example:

#include <iostream>
#include <boost/geometry.hpp>

namespace bg = boost::geometry;
typedef bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > pt;
typedef bg::model::linestring<pt> pt_line;

int main()
{
    const double earthRadius = 6371.0 * 1000.0;
    pt oslo(10.733557, 59.911923);
    pt sandvika(10.521812, 59.887214);
    pt trondheim(10.4, 63.43);

    // works correct
    double d1 = bg::distance(sandvika, trondheim, bg::strategy::distance::haversine<double>(earthRadius));
    double d2 = bg::distance(oslo, trondheim, bg::strategy::distance::haversine<double>(earthRadius));
    std::cout << "Sandvika-Trondheim " << d1 << std::endl;
    std::cout << "Oslo-Trondheim     " << d2 << std::endl;

    pt_line ll;
    ll.push_back(oslo);
    ll.push_back(sandvika);

    // Does not work
    double d3 = bg::distance(trondheim, ll, bg::strategy::distance::haversine<double>(earthRadius));
    std::cout << "Oslo-Sandvika - Trondheim " << d3 << std::endl;

    return 0;
}

Output:

Sandvika-Trondheim 393992
Oslo-Trondheim     391587
Oslo-Sandvika - Trondheim 0.0614639

Note that the last number differs with a factor of 6371000 from the correct 391587.

It looks like distance/backward_compatibility.hpp is ignoring the incoming strategy in last argument to apply.

Attachments (1)

test_distance.cc (1002 bytes ) - added by anonymous 7 years ago.
Example program.

Download all attachments as: .zip

Change History (2)

by anonymous, 7 years ago

Attachment: test_distance.cc added

Example program.

comment:1 by awulkiew, 7 years ago

That's because distance() for Point-Linestring requires Point/Segment strategy, not Point/Point strategy. If you passed:

    bg::strategy::distance::cross_track<>(earthRadius)

the result would be correct.

We have a few options:

  1. As you suggest somehow pass radius from input strategy into the Point/Segment strategy created in backward_compatibility.hpp. This may be problematic currently.
  2. Remove backward compatibility since it allows to use strategies incorrectly.
  3. Something else?

Barend do you have a preference?

Note: See TracTickets for help on using tickets.