Boost logo

Geometry :

Subject: [ggl] RE: A few Boost.Geometry questions
From: Bill Zissimopoulos (ggl)
Date: 2010-09-26 15:49:09


Bruno wrote:
>> BTW, when I tried to implement union() it appeared that some of the required
>> expressions went beyond those of Boost.Range and push_back(), clear() that
>> are stated in the documentation. As I have not looked into this in the last
>> couple of days I cannot reliably report on the error messages, but will do
>> so as soon as I can.
>
> OK, please give a few examples (not necessarily with the error
> messages) just to see if we forgot to mention a concept or if we
> really missed a requirement.

I enclose here some code that shows the minimum definitions required to make intersection() compile:
<<
struct _GeometryPath : GeometryPath
{
    typedef const Point &const_reference;
    //typedef Point &reference;
    typedef const Point *const_iterator;
    typedef Point *iterator;
    _GeometryPath(char tag);
        // used by subclasses default constructors, not required by boost::geometry
    _GeometryPath(const _GeometryPath &other);
    ~_GeometryPath();
    _GeometryPath &operator=(const _GeometryPath &other);
    const Point *begin() const;
    const Point *end() const;
    const Point &operator[](size_t index) const;
    Point *begin();
    Point *end();
    Point &operator[](size_t index);
    void push_back(const Point &point);
    void clear();
};
struct _GeometryMultiPoint : _GeometryPath
{
    _GeometryMultiPoint() : _GeometryPath('P')
    {
    }
};
struct _GeometryLinestring : _GeometryPath
{
    _GeometryLinestring() : _GeometryPath('L')
    {
    }
};
struct _GeometryRing : _GeometryPath
{
    _GeometryRing(char tag = 'A') : _GeometryPath(tag)
    {
    }
};
struct _GeometryPolygon
{
    _GeometryPolygon();
    {
    }
    _GeometryPolygon(const _GeometryRing &exterior_ring) : exterior_ring(exterior_ring)
        // not required by boost::geometry
    {
    }
    _GeometryRing exterior_ring;
    std::vector<_GeometryRing> interior_rings;
};
>>

It is not entirely clear to me whether operator[] and const_reference were mentioned in the documentation.

>> 2. GeometryPath's actually hold the z-values in a separate array:
>
> Not sure what your question is here. If it's how to adapt that to the
> 3P point concept in the library in order to perform 3D operations, you
> will need to adapt your point by defining metafunctions directly
> rather than relying on the macros you used so far. Basically those
> macros are there to make it easy to adapt the most straight-forward
> situations (when all the coordinates are accessed in the same, obvious
> way). They define a set of metafunctions for you that say the library
> how to use your point.

I think I understand how to adapt a 3D point. My issue is that my points are not 3D, but they are sometimes 2D and sometimes 3D and that the z-coordinate information is not carried nicely inside the Point container, but in a separate location.

Let us consider how I would define the "metafunctions" for this point and see if it is possible.
<<
namespace boost { namespace geometry { namespace traits {
template <> struct tag<Point>
{
    typedef point_tag type;
};
template <> struct coordinate_type<Point>
{
    typedef double type;
};
template <> struct coordinate_system<Point>
{
    typedef cs::cartesian type;
};
template <> struct dimension<Point> : boost::mpl::int_<3>
{
};
template <> struct access<Point, 0>
{
    static Float get(const Point &p)
    {
        return p.x;
    }
    static void set(Point &p, Float const &value)
    {
        p.x = value;
    }
};
template <> struct access<Point, 1>
{
    static Float get(const Point &p)
    {
        return p.y;
    }
    static void set(Point &p, Float const &value)
    {
        p.y = value;
    }
};
template <> struct access<Point, 2>
{
    static Float get(const Point &p)
    {
        // how to access z-coordinate? it does not live in this structure
        return 0;
    }
    static void set(Point &p, Float const &value)
    {
        // how to access z-coordinate? it does not live in this structure
    }
};
}}}
>>

How do we access the z-coordinate information in "template <> struct access<Point, 2>"?

Bill

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/ggl/attachments/20100926/fb4f21a2/attachment.html


Geometry list run by mateusz at loskot.net