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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
|
//
// Test Suite for C-API GEOSPolygonize*
#include <tut/tut.hpp>
// geos
#include <geos_c.h>
#include "capi_test_utils.h"
namespace tut {
//
// Test Group
//
// Common data used in test cases.
struct test_capigeospolygonize_data : public capitest::utility {
};
typedef test_group<test_capigeospolygonize_data> group;
typedef group::object object;
group test_capigeospolygonize_group("capi::GEOSPolygonize");
//
// Test Cases
//
template<>
template<>
void object::test<1>
()
{
constexpr int size = 2;
GEOSGeometry* geoms[size] = { nullptr };
geoms[0] = GEOSGeomFromWKT("LINESTRING(1 3, 3 3, 3 1, 1 1, 1 3)");
geoms[1] = GEOSGeomFromWKT("LINESTRING(1 3, 3 3, 3 1, 1 1, 1 3)");
GEOSGeometry* g = GEOSPolygonizer_getCutEdges(geoms, size);
ensure(nullptr != g);
ensure_equals(GEOSGetNumGeometries(g), size);
GEOSGeom_destroy(g);
for(auto& input : geoms) {
GEOSGeom_destroy(input);
}
}
template<>
template<>
void object::test<2>
()
{
constexpr int size = 6;
GEOSGeometry* geoms[size] = { nullptr };
// Example from JTS Developer's Guide, Chapter 6 - Polygonization
geoms[0] = GEOSGeomFromWKT("LINESTRING(0 0, 10 10)"); // isolated edge
geoms[1] = GEOSGeomFromWKT("LINESTRING(185 221, 100 100)"); // dangling edge
geoms[2] = GEOSGeomFromWKT("LINESTRING(185 221, 88 275, 180 316)");
geoms[3] = GEOSGeomFromWKT("LINESTRING(185 221, 292 281, 180 316)");
geoms[4] = GEOSGeomFromWKT("LINESTRING(189 98, 83 187, 185 221)");
geoms[5] = GEOSGeomFromWKT("LINESTRING(189 98, 325 168, 185 221)");
GEOSGeometry* g = GEOSPolygonizer_getCutEdges(geoms, size);
ensure(nullptr != g);
ensure_equals(GEOSGetNumGeometries(g), 0);
GEOSGeom_destroy(g);
for(auto& input : geoms) {
GEOSGeom_destroy(input);
}
}
template<>
template<>
void object::test<3>
()
{
constexpr int size = 2;
GEOSGeometry* geoms[size];
geoms[0] = GEOSGeomFromWKT("LINESTRING (100 100, 100 300, 300 300, 300 100, 100 100)");
geoms[1] = GEOSGeomFromWKT("LINESTRING (150 150, 150 250, 250 250, 250 150, 150 150)");
// GEOSPolygonize gives us a collection of two polygons
GEOSGeometry* g = GEOSPolygonize(geoms, size);
ensure(nullptr != g);
ensure_equals(GEOSGetNumGeometries(g), 2);
ensure_equals(GEOSGeomTypeId(g), GEOS_GEOMETRYCOLLECTION);
GEOSGeom_destroy(g);
// GEOSPolygonize_valid gives us a single polygon with a hole
g = GEOSPolygonize_valid(geoms, 2);
ensure(nullptr != g);
ensure_equals(GEOSGetNumGeometries(g), 1);
ensure_equals(GEOSGeomTypeId(g), GEOS_POLYGON);
GEOSGeom_destroy(g);
for(auto& input : geoms) {
GEOSGeom_destroy(input);
}
}
template<>
template<>
void object::test<4>
()
{
constexpr int size = 1;
GEOSGeometry* geoms[size];
geoms[0] = GEOSGeomFromWKT("LINESTRING (0 0, 1 1)");
GEOSGeometry* g = GEOSPolygonize_valid(geoms, size);
ensure(nullptr != g);
ensure_equals(GEOSGetNumGeometries(g), 0);
ensure_equals(GEOSGeomTypeId(g), GEOS_GEOMETRYCOLLECTION);
GEOSGeom_destroy(g);
for(auto& input : geoms) {
GEOSGeom_destroy(input);
}
}
template<>
template<>
void object::test<5>
()
{
constexpr int size = 2;
GEOSGeometry* geoms[size];
geoms[0] = GEOSGeomFromWKT("LINESTRING (0 0, 1 0, 1 1, 0 1, 0 0)");
geoms[1] = GEOSGeomFromWKT("LINESTRING (1 1, 2 1, 2 2, 1 2, 1 1)");
GEOSGeometry* g = GEOSPolygonize_valid(geoms, size);
ensure(nullptr != g);
ensure_equals(GEOSGetNumGeometries(g), 2);
ensure_equals(GEOSGeomTypeId(g), GEOS_MULTIPOLYGON);
GEOSGeom_destroy(g);
for(auto& input : geoms) {
GEOSGeom_destroy(input);
}
}
// Test GEOSPolygonize_full
template<>
template<>
void object::test<6>
()
{
geom1_ = GEOSGeomFromWKT("MULTILINESTRING ((0 0, 1 0, 1 1, 0 1, 0 0), (0 0, 0.5 0.5), (1 1, 2 2, 1 2, 2 1, 1 1))");
GEOSGeometry* cuts;
GEOSGeometry* dangles;
GEOSGeometry* invalidRings;
result_ = GEOSPolygonize_full(geom1_, &cuts, &dangles, &invalidRings);
expected_ = GEOSGeomFromWKT("GEOMETRYCOLLECTION(POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)))");
GEOSGeometry* expected_cuts = GEOSGeomFromWKT("GEOMETRYCOLLECTION EMPTY");
GEOSGeometry* expected_dangles = GEOSGeomFromWKT("GEOMETRYCOLLECTION(LINESTRING (0 0, 0.5 0.5))");
GEOSGeometry* expected_invalidRings = GEOSGeomFromWKT("GEOMETRYCOLLECTION(LINESTRING (1 1, 2 2, 1 2, 2 1, 1 1))");
ensure_geometry_equals(result_, expected_);
ensure_geometry_equals(cuts, expected_cuts);
ensure_geometry_equals(dangles, expected_dangles);
ensure_geometry_equals(invalidRings, expected_invalidRings);
GEOSGeom_destroy(cuts);
GEOSGeom_destroy(dangles);
GEOSGeom_destroy(invalidRings);
GEOSGeom_destroy(expected_cuts);
GEOSGeom_destroy(expected_dangles);
GEOSGeom_destroy(expected_invalidRings);
}
template<>
template<>
void object::test<7>
()
{
constexpr int size = 2;
GEOSGeometry* geoms[size];
geoms[0] = GEOSGeomFromWKT("LINESTRING (0 0, 2 0)");
geoms[1] = GEOSGeomFromWKT("CIRCULARSTRING (0 0, 1 1, 2 0)");
for (auto& geom : geoms) {
ensure(geom != nullptr);
}
GEOSGeometry* g = GEOSPolygonize(geoms, size);
ensure("curved geometries not supported", g == nullptr);
for(auto& input : geoms) {
GEOSGeom_destroy(input);
}
}
} // namespace tut
|