Boost logo

Boost :

From: Barend Gehrels (barend_at_[hidden])
Date: 2008-01-17 03:58:46


Martin Bonner wrote:
> From: Barend Gehrels
>
>> Phil Endecott wrote:
>>
>>> Barend Gehrels wrote:
>>>
>>>> Or he can implement his own point type. So I think it
>>>> approaches your "arbitrary structs".
>>>>
>>> Well not if I have lat and long in my legacy code instead of x and y,
>>>
>>> for example. I'm not certain how useful this is, but the GTL
>>> proponents were very enthusiastic about it.
>>>
>>
>> Yes you can. You can define a point class like this [snip ...]
>>
>
> The problem surely is that lat+long are coordinates in a non-euclidean
> geometry. Pythagorus's theorum is not true, two straight line segments
> can have TWO points of intersection - I just don't see how it can
> /begin/ to work.
>

Martin,

My sample was more to indicate that you can use your own points. But
you're very right, most calculations are nonsense if you use latlong
coordinates and make no specializations.

If you make the right specializations, you'll get correct answers for
latlong. It is a generic framework. If you specialize the algorithm for
point-to-point distance and implement for example Vincenty there, that
specialization is used for lat long points (of course). If you then
calculate the length of a linestring you will get that length in meters,
kilometers, or miles, depending how you implement it. Because the length
algorithm uses distance, which uses square_distance_point_to_point,
which takes the right version automatically (by C++).

    template <>
    inline double square_distance_point_to_point(const lola& p1, const
lola& p2)
    {
        // vincenty implementation
    }

Same for intersections. However, if you use latlong everywhere you have
to specialize most or all algorithms.We normally first project the points.

You can even specialize for two different points - calculate the
distance between latlong and something else, for example, if you make
that specialization. It is a generic framework.

Best regards, Barend

-------------------------------------
Barend Gehrels, Geodan Holding b.v., Amsterdam, The Netherlands, www.geodan.nl


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk