Boost logo

Geometry :

Subject: Re: [geometry] Distance between point_ll and polygon in 1.56
From: Branimir Betov (bbetov_at_[hidden])
Date: 2014-08-11 22:40:08


Thank you Menelaos. I submitted
https://svn.boost.org/trac/boost/ticket/10345

I have a workaround for the time being that seems to work for the distance,
but nowhere near complete for geographic coordinates.

Starting from the develop branch for Boost.Geometry, I defined:

   - A specialization for comparable_to_regular for the geographic_tag
   - A fix in boost\geometry\strategies\spherical\distance_cross_track.hpp
   - A fix in geometry\algorithms\detail\distance\backward_compatibility.hpp

Although I am sure the wrong fixes, I think this may help narrow what is
going wrong... (all code is below)

The Specialization in the boost::geometry::strategy::distance::services

                    template
                        <
                        typename ComparableStrategy,
                        typename Strategy,
                        typename Geometry1,
                        typename Geometry2
>
                    struct comparable_to_regular
                        <
                        ComparableStrategy, Strategy,
                        Geometry1, Geometry2,
                        geographic_tag, geographic_tag
>
                    {
                        typedef typename return_type
                            <
                            Strategy,
                            typename point_type<Geometry1>::type,
                            typename point_type<Geometry2>::type
> ::type calculation_type;

                        typedef typename return_type
                            <
                            ComparableStrategy,
                            typename point_type<Geometry1>::type,
                            typename point_type<Geometry2>::type
> ::type comparable_calculation_type;

                        static inline calculation_type
apply(comparable_calculation_type const& cd)
                        {
                            return cd;
                        }
                    };
and then a fix in
boost\geometry\strategies\spherical\distance_cross_track.hpp

Change was on line 229 from:
----------------------------------------------------------------------------------------------------------------------
template
<
    typename CalculationType,
    typename Strategy
>
struct get_comparable<cross_track<CalculationType, Strategy> >
{
    typedef typename comparable_type
        <
            cross_track<CalculationType, Strategy>
>::type comparable_type;
public :
    static inline comparable_type apply(cross_track<CalculationType,
Strategy> const& strategy)
    {
        return comparable_type(strategy.radius());
    }
};
----------------------------------------------------------------------------------------------------------------------

to (passing the radius was messing up the andoyer calcs):

----------------------------------------------------------------------------------------------------------------------
template
<
    typename CalculationType,
    typename Strategy
>
struct get_comparable<cross_track<CalculationType, Strategy> >
{
    typedef typename comparable_type
        <
            cross_track<CalculationType, Strategy>
>::type comparable_type;
public :
    static inline comparable_type apply(cross_track<CalculationType,
Strategy> const& strategy)
    {
        return comparable_type(strategy);
    }
};
----------------------------------------------------------------------------------------------------------------------

the fix in geometry\algorithms\detail\distance\backward_compatibility.hpp
starting at line 167

----------------------------------------------------------------------------------------------------------------------
// Point-polygon , where point-point strategy is specified
template <typename Point, typename Polygon, typename Strategy>
struct distance
<
    Point, Polygon, Strategy,
    point_tag, polygon_tag, strategy_tag_distance_point_point,
    false
>
{
    typedef typename strategy::distance::services::return_type
        <
            Strategy, Point, typename point_type<Polygon>::type
>::type return_type;

    static inline return_type apply(Point const& point,
            Polygon const& polygon,
            Strategy const&)
    {
        typedef typename detail::distance::default_ps_strategy
            <
                Point,
                typename point_type<Polygon>::type,
                Strategy
>::type ps_strategy_type;

        std::pair<return_type, bool>
            dc = detail::distance::point_to_polygon
            <
                Point, Polygon,
                geometry::closure<Polygon>::value,
                ps_strategy_type
>::apply(point, polygon, ps_strategy_type());

        return dc.second ? return_type(0) : dc.first;
    }
};
----------------------------------------------------------------------------------------------------------------------
to:

----------------------------------------------------------------------------------------------------------------------
// Point-polygon , where point-point strategy is specified
template <typename Point, typename Polygon, typename Strategy>
struct distance
<
    Point, Polygon, Strategy,
    point_tag, polygon_tag, strategy_tag_distance_point_point,
    false
>
{
    typedef typename strategy::distance::services::return_type
        <
            Strategy, Point, typename point_type<Polygon>::type
>::type return_type;

    static inline return_type apply(Point const& point,
            Polygon const& polygon,
            Strategy const& *strategy*)
    {
        typedef typename detail::distance::default_ps_strategy
            <
                Point,
                typename point_type<Polygon>::type,
                Strategy
>::type ps_strategy_type;

        std::pair<return_type, bool>
            dc = detail::distance::point_to_polygon
            <
                Point, Polygon,
                geometry::closure<Polygon>::value,
                ps_strategy_type
>::apply(point, polygon, *strategy*);

        return dc.second ? return_type(0) : dc.first;
    }
};
----------------------------------------------------------------------------------------------------------------------

Hope this helps

Thanks,
Branimir

On Mon, Aug 11, 2014 at 6:49 AM, Menelaos Karavelas <
menelaos.karavelas_at_[hidden]> wrote:

> Hi Braminir.
>
>
> On 10/08/2014 08:52 μμ, Branimir Betov wrote:
>
> I did some more experimentation and seems like distance between point
> and a polygon only works for Cartesian coordinates. I tried spherical,
> sperical_equatorial, and geographic - none work, but Cartesian compiles
> fine and returns a distance.
>
> I guess some specialization is missing, but I am not sure how to solve it.
>
>
>
> I tried your example program with both 1.55 and 1.54 and I could not get
> it to compile. Maybe it is my setup, and will try again.
>
> It is true, however, that for spherical_equatorial your program should
> work, but it doesn't (it was indeed working with 1.55).
> I have spotted the problem, and I am working towards a solution.
>
> I suggest that you create a ticket on trac about this, so that we can take
> it from there.
> Here is the link for the trac system: https://svn.boost.org/trac/boost/
> Follow the link for submitting patches, bug reports and feature requests
> at the top of the page. This will let you create a new ticket.
>
> Best,
>
> - m.
>
>
>
>
>
> On Sat, Aug 9, 2014 at 9:07 AM, Branimir Betov <bbetov_at_[hidden]> wrote:
>
>> Here is the full example I came up with. I am using visual studio (tried
>> 2010, 2012, and 2013). For completeness I am attaching a file with the
>> polygon definition (test.txt).
>>
>> #include "stdafx.h"
>> #include <string>
>> #include <fstream>
>> #include <streambuf>
>> #include <boost/geometry.hpp>
>> #include "boost/geometry/geometry.hpp"
>> #include <boost/geometry/extensions/gis/latlong/point_ll.hpp>
>> #include <boost/geometry/io/io.hpp>
>>
>> namespace bg = boost::geometry;
>> using namespace std;
>>
>>
>> typedef bg::model::ll::point<> point;
>> typedef bg::model::polygon<point> polygon;
>>
>> int _tmain(int argc, _TCHAR* argv[])
>> {
>> polygon poly;
>> std::string str;
>>
>> std::ifstream t("c:\\temp\\test.txt");
>>
>> t.seekg(0, std::ios::end);
>> str.reserve(t.tellg());
>> t.seekg(0, std::ios::beg);
>>
>> str.assign((std::istreambuf_iterator<char>(t)),
>> std::istreambuf_iterator<char>());
>>
>>
>> bg::read_wkt(str, poly);
>>
>> const bg::latitude<double> lat_out(37.69311);
>> const bg::longitude<double> lon_out(-122.13865);
>> point p_out(lat_out, lon_out);
>>
>> bg::distance(poly, p_out); // This fails to compile for some reason.
>>
>> return 0;
>> }
>>
>>
>>
>>
>> On Sat, Aug 9, 2014 at 12:12 AM, Menelaos Karavelas <
>> menelaos.karavelas_at_[hidden]> wrote:
>>
>>> Hi Branimir.
>>>
>>>
>>> On 09/08/2014 05:26 πμ, Branimir Betov wrote:
>>>
>>> Hi,
>>>
>>> I am trying to figure out what is wrong with my code and am stuck, so I
>>> thought someone might help. The code used to work in 1.55 and in 1.56 no
>>> longer compiles; I am at a loss what might be wrong. I am using the GIS
>>> extension from the develop-1.56 branch.
>>>
>>> Here is the relevant snippet:
>>>
>>> typedef bg::model::ll::point<> point;
>>> typedef bg::model::polygon<point> polygon;
>>>
>>> polygon poly;
>>>
>>> bg::read_wkt(str, poly);
>>>
>>> const bg::latitude<double> lat_out(37.69311);
>>> const bg::longitude<double> lon_out(-122.13865);
>>> point p_out(lat_out, lon_out);
>>>
>>> bg::distance(p_out, poly); // It fails to compile right here.
>>>
>>>
>>> Does anyone have any suggestions?
>>>
>>>
>>> Would it be possible to provide a minimal complete example that fails?
>>>
>>> Thanks a lot.
>>>
>>> - m.
>>>
>>>
>>> Thank you,
>>> Branimir
>>>
>>>
>>>
>>> _______________________________________________
>>> Geometry mailing listGeometry_at_[hidden]http://lists.boost.org/mailman/listinfo.cgi/geometry
>>>
>>>
>>>
>>> _______________________________________________
>>> Geometry mailing list
>>> Geometry_at_[hidden]
>>> http://lists.boost.org/mailman/listinfo.cgi/geometry
>>>
>>>
>>
>
>
> _______________________________________________
> Geometry mailing listGeometry_at_[hidden]http://lists.boost.org/mailman/listinfo.cgi/geometry
>
>
>
> _______________________________________________
> Geometry mailing list
> Geometry_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/geometry
>
>



Geometry list run by mateusz at loskot.net