File: MCIndexSnapRounderTest.cpp

package info (click to toggle)
geos 3.14.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 31,212 kB
  • sloc: cpp: 199,103; xml: 56,065; ansic: 6,162; sh: 287; makefile: 26
file content (149 lines) | stat: -rw-r--r-- 4,435 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//
// Test Suite for geos::noding::snapround::MCIndexSnapRounder class.

#include <tut/tut.hpp>
// geos
#include <geos/noding/SegmentNode.h>
#include <geos/noding/Noder.h>
#include <geos/noding/NodedSegmentString.h>
#include <geos/noding/SegmentString.h>
#include <geos/noding/snapround/MCIndexSnapRounder.h>
#include <geos/io/WKTWriter.h>
#include <geos/io/WKBWriter.h>
#include <geos/io/WKTReader.h>
#include <geos/io/WKBReader.h>
#include <geos/geom/PrecisionModel.h>
#include <geos/geom/CoordinateSequence.h>
#include <geos/geom/GeometryFactory.h>
#include <geos/geom/Geometry.h>
#include <geos/geom/LineString.h>
#include <geos/geom/MultiLineString.h>
// std
#include <memory>
#include <string>

namespace tut {
//
// Test Group
//

// Common data used by all tests
struct test_mcidxsnprndr_data {

    typedef geos::noding::SegmentString SegmentString;
    typedef geos::noding::NodedSegmentString NodedSegmentString;
    typedef geos::noding::snapround::MCIndexSnapRounder MCIndexSnapRounder;
    typedef geos::noding::Noder Noder;
    typedef geos::io::WKTReader WKTReader;
    typedef geos::io::WKBReader WKBReader;
    typedef geos::io::WKTWriter WKTWriter;
    typedef geos::io::WKBWriter WKBWriter;
    typedef geos::geom::Geometry Geometry;
    typedef geos::geom::PrecisionModel PrecisionModel;
    typedef geos::geom::CoordinateSequence CoordinateSequence;

    typedef std::unique_ptr<CoordinateSequence> CoordSeqPtr;
    typedef std::unique_ptr<Geometry> GeomPtr;

    typedef std::vector<SegmentString*> SegStrVct;
    typedef std::vector<Geometry*> GeomVct;

    const geos::geom::GeometryFactory* gf_;

    test_mcidxsnprndr_data()
        : gf_(geos::geom::GeometryFactory::getDefaultInstance())
    {}

    GeomPtr
    getGeometry(SegStrVct& vct)
    {
        std::vector<std::unique_ptr<Geometry>> lines;
        for(SegStrVct::size_type i = 0, n = vct.size(); i < n; ++i) {
            SegmentString* ss = vct[i];
            lines.push_back(gf_->createLineString(*(ss->getCoordinates())));
        }
        return gf_->createMultiLineString(std::move(lines));
    }

    void
    getSegmentStrings(const Geometry& g, SegStrVct& vct)
    {
        CoordSeqPtr s(g.getCoordinates());
        vct.push_back(new NodedSegmentString(s.release(), g.hasZ(), g.hasM(), nullptr));
    }

    GeomPtr
    readGeometry(const std::string& wkt)
    {
        GeomPtr g;
        if(wkt[0] == '0' || wkt[0] == '1') {
            WKBReader r;
            std::istringstream is(wkt);
            g = r.readHEX(is);
        }
        else {
            WKTReader r;
            g = r.read(wkt);
        }
        return g;
    }

    void
    getSegmentStrings(const std::string& wkt, SegStrVct& vct)
    {
        GeomPtr g = readGeometry(wkt);
        getSegmentStrings(*g, vct);
    }

    void
    freeSegmentStrings(SegStrVct& vct)
    {
        for(SegStrVct::size_type i = 0, n = vct.size(); i < n; ++i) {
            delete vct[i];
        }
    }

private:
    test_mcidxsnprndr_data(test_mcidxsnprndr_data const&); // = delete
    test_mcidxsnprndr_data& operator=(test_mcidxsnprndr_data const&); // = delete
};


typedef test_group<test_mcidxsnprndr_data> group;
typedef group::object object;

group test_mcidxsnprndr_group(
    "geos::noding::snapround::MCIndexSnapRounder"
);

//
// Test Cases
//

// This test would fail before fix in r3528
template<>
template<>
void object::test<1>
()
{
    std::string
    wkt0("LINESTRING(99739.70596 -2239218.0625,99739.85604 -2239218.21258,99739.85605 -2239218.21258, 99739.85605 -2239218.21258,99739.86851 -2239218.21258,99739.86851 -2239218.20012, 99739.86851 -2239218.20012,99739.86851 -2239218.04, 99739.95848 -2239218.11015,99739.86851 -2239218.20012, 99739.86851 -2239218.20012,99739.85605 -2239218.21258, 99739.85605 -2239218.21258,99739.80901 -2239218.25961, 99739.80901 -2239218.25961,99739.68863 -2239218.38, 99739.86204 -2239218.31264,99739.80901 -2239218.25961, 99739.80901 -2239218.25961,99739.66841 -2239218.11901)");
    SegStrVct nodable;
    getSegmentStrings(wkt0, nodable);
    ensure_equals(nodable.size(), 1u);

    PrecisionModel pm(1e-5);
    MCIndexSnapRounder noder(pm);

    ensure_equals(nodable.size(), 1u);
    noder.computeNodes(&nodable);
    std::unique_ptr<SegStrVct> noded(noder.getNodedSubstrings());

    ensure_equals("1e-5", noded->size(), 178u);

    freeSegmentStrings(*noded);
    freeSegmentStrings(nodable);
}


} // namespace tut