Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6916959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:40:11+00:00 2026-05-27T09:40:11+00:00

I try to figure out how boost::geometry ‘s for_each_segment ist working. The documentation tells

  • 0

I try to figure out how boost::geometry‘s for_each_segment ist working. The documentation tells me, that for_each_segment expects a geometry and a Functor. This functor is called polylength_helper in my example, as long as this snippet is not compiling I just increment a number there to keep things simple until it compiles.

// foo.h

typedef boost::geometry::model::point<double, 2, bg::cs::cartesian> GeographicPoint;
typedef boost::geometry::model::linestring<GeographicPoint> GeographicPolyLine;
typedef boost::geometry::model::segment<GeographicPoint> GeographicSegment;

double poly_length(const GeographicPolyLine&);

template<typename Segment>
struct polylength_helper{
    polylength_helper() : length(0){};

    inline void operator()(Segment s){
        length += 1;
    };

    double length;
};

// foo.cpp

double poly_length(GeographicPolyLine &poly){
    polylength_helper<GeographicSegment> helper;
    bg::for_each_segment(poly, helper);
    return helper.length;
}

Well, this does not compile. I used clang for a more understandable output, it says:

note: candidate function not viable: no known
conversion from 'model::referring_segment<point_type>' to
'boost::geometry::model::segment<boost::geometry::model::point<double, 2,
  boost::geometry::cs::cartesian> >' for 1st argument
inline void operator()(Segment s){
            ^

Can anyone help me out? Especially I have no idea where the referring_segment in the message comes from.

Here is an example from the docs:

http://www.boost.org/doc/libs/1_48_0/libs/geometry/doc/html/geometry/reference/algorithms/for_each/for_each_segment_2_const_version.html

But I cannot figure out how this differs from my version, except for the typedefs.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:40:11+00:00Added an answer on May 27, 2026 at 9:40 am

    Change the line

    typedef boost::geometry::model::segment<GeographicPoint> GeographicSegment;
    

    to

    typedef boost::geometry::model::referring_segment<GeographicPoint> GeographicSegment;
    

    That will get you compiling.


    From the documentation on segment and referring_segment, the only difference between the two is that referring_segment holds a reference to the points. This is what is needed in a for each that modifies the segment since the points modified should be reflected in the linestring. In a for each that does not modify the points, it should still take a reference (most likely a const reference) since it reduces the amount of copying.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been searching for hours to try and figure this out, and it seems
I try to figure out something intersting that happen in Scheme: (define last-pair (lambda
I'm using the following tester to try and figure out this regex: http://derekslager.com/blog/posts/2007/09/a-better-dotnet-regular-expression-tester.ashx My
I've done everything to try and figure out why this is happening. It has
I try to figure out what -beginUpdates and -endUpdates is actually good for. Adding
I'm try to figure out how to handle the following scenario. In general, i
I try to learn how Boost.Spirit works. Unfortunately, the documentation is too laconic for
OK, So i've looked at alof of posts to try and figure out how
I try to figure out which devices are online and which are offline in
I've been googling around to try to figure out what sort of event handles

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.