JayDoe
JayDoe

Reputation: 153

Error accessing point data in boost::geometry polygon

I am trying to iterate through the points in a boost polygon to perform an operation on them. To show a simplified version of my problem:

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>

typedef boost::geometry::model::d2::point_xy<double> point_type;
typedef boost::geometry::model::polygon<point_type> polygon;

int main()
{
    polygon polygonTest;
    boost::geometry::read_wkt("POLYGON((-2 2, 2 2, 2 -2, -2 -2, -2 2))", polygonTest);

    for (point_type point : boost::geometry::exterior_ring(polygonTest))
    {
        double xCoord = point.x;
    }


    return 0;
}

I receive the following error:

'boost::geometry::model::d2::point_xy<double,boost::geometry::cs::cartesian>::x': function call missing argument list; use '&boost::geometry::model::d2::point_xy<double,boost::geometry::cs::cartesian>::x' to create a pointer to member

What am I overlooking to resolve this?

Upvotes: 1

Views: 552

Answers (1)

sehe
sehe

Reputation: 392893

You are using a member function x. But you forgot to call it:

    double xCoord = point.x();

See below for working sampel

Q. What am I overlooking

You're overlooking the information in the error message.

  • GCC: error: cannot resolve overloaded function ‘x’ based on conversion to type ‘double’

    It's telling you you're assigning a function x to a double...

  • Clang: error: reference to non-static member function must be called; did you mean to call it with no arguments?

    It even goes on to list the overloads that you could want

Live On Coliru

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>

typedef boost::geometry::model::d2::point_xy<double> point_type;
typedef boost::geometry::model::polygon<point_type> polygon;

int main() {
    polygon polygonTest;
    boost::geometry::read_wkt("POLYGON((-2 2, 2 2, 2 -2, -2 -2, -2 2))", polygonTest);

    for (point_type point : boost::geometry::exterior_ring(polygonTest)) {
        double xCoord = point.x();
    }
}

Upvotes: 1

Related Questions