Boost logo

Geometry :

Subject: Re: [geometry] Integrating OGR library with Boost.Geometry
From: Eric MSP Veith (eveith_at_[hidden])
Date: 2015-05-21 11:35:04

Hello list,

earlier this year I adapted the OGRGeometry subclasses to the boost.Geometry
models. My adapter code is available at <>.

Everything was done on the basis of boost 1.56.0, where tests ran
successfully. I've now upgraded my Linux distribution, which also pulled boost
1.57.0. I recompiled everything, but much to my surprise, my adapter code
stopped working!

At first I thought the iterator code somehow had a bug lurking in it that
caused the failure, but I can successfully retrieve all points on an
OGRLineString without problems.

However, bg::distance() between two OGRLineStrings returns 0 instead of the
proper result. Is anybody aware of a change in bg::distance or Boost.Range
that might cause the failure? After having checked that the iterator works
forwards and backwards, I'm unsure where to begin with the debugging.

Here's the test code that I use. bg::distance(OGRLineString &, OGRLineString
&) always returns 0.0:

void BoostOGRLineStringAdapterTest::testGeometryMultiLineString()
    typedef bg::model::linestring<OGRPoint> boostLinestring;
    boostLinestring bls1, bls2;

    OGRLineString *ls1 = new OGRLineString(),
            *ls2 = new OGRLineString(),
            *ls3 = new OGRLineString();
    auto distantPoint = new OGRPoint(15.0, 15.0);
    OGRSpatialReference *sref = new OGRSpatialReference();

    OGRErr rc = sref->importFromEPSG(4326);

    ls1->addPoint(0.0, 0.0);
    ls1->addPoint(1.0, 1.0);
    ls1->addPoint(2.0, 2.0);
    ls1->addPoint(3.0, 3.0);
    ls1->addPoint(4.0, 4.0);

    bls1.push_back(OGRPoint(0.0, 0.0));
    bls1.push_back(OGRPoint(1.0, 1.0));
    bls1.push_back(OGRPoint(2.0, 2.0));
    bls1.push_back(OGRPoint(3.0, 3.0));
    bls1.push_back(OGRPoint(4.0, 4.0));

    ls2->addPoint(17.0, 17.0);
    ls2->addPoint(21.0, 21.0);
    ls2->addPoint(33.0, 33.0);
    ls2->addPoint(76.0, 56.0);

    bls2.push_back(OGRPoint(17.0, 17.0));
    bls2.push_back(OGRPoint(21.0, 21.0));
    bls2.push_back(OGRPoint(33.0, 33.0));
    bls2.push_back(OGRPoint(76.0, 56.0));

    ls3->addPoint(42.0, 34.2);
    ls3->addPoint(72.0, 14.2);
    ls3->addPoint(67.0, 34.2);
    ls3->addPoint(82.0, 2.2);
    ls3->addPoint(5.0, 17.2);

            bg::crosses(*ls1, *distantPoint),
            bg::intersects(*ls1, *distantPoint),

    for (int i = 0; i != ls1->getNumPoints(); ++i) {
        auto p = new OGRPoint();
        ls1->getPoint(i, p);

                bg::distance(*p, *distantPoint),

            bg::distance(*ls1, *distantPoint),
            bg::distance(*ls3, *distantPoint),
            bg::distance(*ls2, *distantPoint),
            bg::distance(bls1, bls2),
            bg::distance(bls1, bls2),
            bg::distance(*ls1, *ls2));
            bg::distance(*ls1, *ls2),

    delete sref;

Thanks alot in advance for any hints!

                        --- Eric

Geometry list run by mateusz at