| 1 |
var tape = require("tape"), |
| 2 |
topojson = require("../"); |
| 3 |
|
| 4 |
// |
| 5 |
// +----+----+ +----+----+ |
| 6 |
// | | | | | |
| 7 |
// | | | ==> | | |
| 8 |
// | | | | | |
| 9 |
// +----+----+ +----+----+ |
| 10 |
// |
| 11 |
tape("merge stitches together two side-by-side polygons", function(test) { |
| 12 |
var topology = topojson.topology({collection: {type: "FeatureCollection", features: [ |
| 13 |
{type: "Feature", geometry: {type: "Polygon", coordinates: [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]]}}, |
| 14 |
{type: "Feature", geometry: {type: "Polygon", coordinates: [[[1, 0], [1, 1], [2, 1], [2, 0], [1, 0]]]}} |
| 15 |
]}}, { |
| 16 |
quantization: 0 |
| 17 |
}); |
| 18 |
test.deepEqual(topojson.merge(topology, topology.objects.collection.geometries), { |
| 19 |
type: "MultiPolygon", |
| 20 |
coordinates: [[[[1, 0], [0, 0], [0, 1], [1, 1], [2, 1], [2, 0], [1, 0]]]] |
| 21 |
}); |
| 22 |
test.end(); |
| 23 |
}); |
| 24 |
|
| 25 |
// |
| 26 |
// +----+ +----+ +----+ +----+ |
| 27 |
// | | | | | | | | |
| 28 |
// | | | | ==> | | | | |
| 29 |
// | | | | | | | | |
| 30 |
// +----+ +----+ +----+ +----+ |
| 31 |
// |
| 32 |
tape("merge does not stitch together two separated polygons", function(test) { |
| 33 |
var topology = topojson.topology({collection: {type: "FeatureCollection", features: [ |
| 34 |
{type: "Feature", geometry: {type: "Polygon", coordinates: [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]]}}, |
| 35 |
{type: "Feature", geometry: {type: "Polygon", coordinates: [[[2, 0], [2, 1], [3, 1], [3, 0], [2, 0]]]}} |
| 36 |
]}}, { |
| 37 |
quantization: 0 |
| 38 |
}); |
| 39 |
test.deepEqual(topojson.merge(topology, topology.objects.collection.geometries), { |
| 40 |
type: "MultiPolygon", |
| 41 |
coordinates: [[[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]], [[[2, 0], [2, 1], [3, 1], [3, 0], [2, 0]]]] |
| 42 |
}); |
| 43 |
test.end(); |
| 44 |
}); |
| 45 |
|
| 46 |
// |
| 47 |
// +-----------+ +-----------+ |
| 48 |
// | | | | |
| 49 |
// | +---+ | ==> | +---+ | |
| 50 |
// | | | | | | | | |
| 51 |
// | +---+ | | +---+ | |
| 52 |
// | | | | |
| 53 |
// +-----------+ +-----------+ |
| 54 |
// |
| 55 |
tape("merge does not stitch together a polygon and its hole", function(test) { |
| 56 |
var topology = topojson.topology({collection: {type: "FeatureCollection", features: [ |
| 57 |
{type: "Feature", geometry: {type: "Polygon", coordinates: [[[0, 0], [0, 3], [3, 3], [3, 0], [0, 0]], [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]]]}} |
| 58 |
]}}, { |
| 59 |
quantization: 0 |
| 60 |
}); |
| 61 |
test.deepEqual(topojson.merge(topology, topology.objects.collection.geometries), { |
| 62 |
type: "MultiPolygon", |
| 63 |
coordinates: [[[[0, 0], [0, 3], [3, 3], [3, 0], [0, 0]], [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]]]] |
| 64 |
}); |
| 65 |
test.end(); |
| 66 |
}); |
| 67 |
|
| 68 |
// |
| 69 |
// +-----------+ +-----------+ |
| 70 |
// | | | | |
| 71 |
// | +---+ | ==> | | |
| 72 |
// | | | | | | |
| 73 |
// | +---+ | | | |
| 74 |
// | | | | |
| 75 |
// +-----------+ +-----------+ |
| 76 |
// |
| 77 |
tape("merge stitches together a polygon surrounding another polygon", function(test) { |
| 78 |
var topology = topojson.topology({collection: {type: "FeatureCollection", features: [ |
| 79 |
{type: "Feature", geometry: {type: "Polygon", coordinates: [[[0, 0], [0, 3], [3, 3], [3, 0], [0, 0]], [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]]]}}, |
| 80 |
{type: "Feature", geometry: {type: "Polygon", coordinates: [[[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]]]}} |
| 81 |
]}}, { |
| 82 |
quantization: 0 |
| 83 |
}); |
| 84 |
test.deepEqual(topojson.merge(topology, topology.objects.collection.geometries), { |
| 85 |
type: "MultiPolygon", |
| 86 |
coordinates: [[[[0, 0], [0, 3], [3, 3], [3, 0], [0, 0]]]] |
| 87 |
}); |
| 88 |
test.end(); |
| 89 |
}); |
| 90 |
|
| 91 |
// |
| 92 |
// +-----------+-----------+ +-----------+-----------+ |
| 93 |
// | | | | | |
| 94 |
// | +---+ | +---+ | ==> | +---+ +---+ | |
| 95 |
// | | | | | | | | | | | | | |
| 96 |
// | +---+ | +---+ | | +---+ +---+ | |
| 97 |
// | | | | | |
| 98 |
// +-----------+-----------+ +-----------+-----------+ |
| 99 |
// |
| 100 |
tape("merge stitches together two side-by-side polygons with holes", function(test) { |
| 101 |
var topology = topojson.topology({collection: {type: "FeatureCollection", features: [ |
| 102 |
{type: "Feature", geometry: {type: "Polygon", coordinates: [[[0, 0], [0, 3], [3, 3], [3, 0], [0, 0]], [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]]]}}, |
| 103 |
{type: "Feature", geometry: {type: "Polygon", coordinates: [[[3, 0], [3, 3], [6, 3], [6, 0], [3, 0]], [[4, 1], [5, 1], [5, 2], [4, 2], [4, 1]]]}} |
| 104 |
]}}, { |
| 105 |
quantization: 0 |
| 106 |
}); |
| 107 |
test.deepEqual(topojson.merge(topology, topology.objects.collection.geometries), { |
| 108 |
type: "MultiPolygon", |
| 109 |
coordinates: [[[[3, 0], [0, 0], [0, 3], [3, 3], [6, 3], [6, 0], [3, 0]], [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]], [[4, 1], [5, 1], [5, 2], [4, 2], [4, 1]]]] |
| 110 |
}); |
| 111 |
test.end(); |
| 112 |
}); |
| 113 |
|
| 114 |
// |
| 115 |
// +-------+-------+ +-------+-------+ |
| 116 |
// | | | | | |
| 117 |
// | +---+---+ | ==> | +---+---+ | |
| 118 |
// | | | | | | | | |
| 119 |
// | +---+---+ | | +---+---+ | |
| 120 |
// | | | | | |
| 121 |
// +-------+-------+ +-------+-------+ |
| 122 |
// |
| 123 |
tape("merge stitches together two horseshoe polygons, creating a hole", function(test) { |
| 124 |
var topology = topojson.topology({collection: {type: "FeatureCollection", features: [ |
| 125 |
{type: "Feature", geometry: {type: "Polygon", coordinates: [[[0, 0], [0, 3], [2, 3], [2, 2], [1, 2], [1, 1], [2, 1], [2, 0], [0, 0]]]}}, |
| 126 |
{type: "Feature", geometry: {type: "Polygon", coordinates: [[[2, 0], [2, 1], [3, 1], [3, 2], [2, 2], [2, 3], [4, 3], [4, 0], [2, 0]]]}} |
| 127 |
]}}, { |
| 128 |
quantization: 0 |
| 129 |
}); |
| 130 |
test.deepEqual(topojson.merge(topology, topology.objects.collection.geometries), { |
| 131 |
type: "MultiPolygon", |
| 132 |
coordinates: [[[[2, 0], [0, 0], [0, 3], [2, 3], [4, 3], [4, 0], [2, 0]], [[2, 2], [1, 2], [1, 1], [2, 1], [3, 1], [3, 2], [2, 2]]]] |
| 133 |
}); |
| 134 |
test.end(); |
| 135 |
}); |
| 136 |
|
| 137 |
// |
| 138 |
// +-------+-------+ +-------+-------+ |
| 139 |
// | | | | | |
| 140 |
// | +---+---+ | ==> | | |
| 141 |
// | | | | | | | |
| 142 |
// | +---+---+ | | | |
| 143 |
// | | | | | |
| 144 |
// +-------+-------+ +-------+-------+ |
| 145 |
// |
| 146 |
tape("merge stitches together two horseshoe polygons surrounding two other polygons", function(test) { |
| 147 |
var topology = topojson.topology({collection: {type: "FeatureCollection", features: [ |
| 148 |
{type: "Feature", geometry: {type: "Polygon", coordinates: [[[0, 0], [0, 3], [2, 3], [2, 2], [1, 2], [1, 1], [2, 1], [2, 0], [0, 0]]]}}, |
| 149 |
{type: "Feature", geometry: {type: "Polygon", coordinates: [[[2, 0], [2, 1], [3, 1], [3, 2], [2, 2], [2, 3], [4, 3], [4, 0], [2, 0]]]}}, |
| 150 |
{type: "Feature", geometry: {type: "Polygon", coordinates: [[[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]]]}}, |
| 151 |
{type: "Feature", geometry: {type: "Polygon", coordinates: [[[2, 1], [2, 2], [3, 2], [3, 1], [2, 1]]]}} |
| 152 |
]}}, { |
| 153 |
quantization: 0 |
| 154 |
}); |
| 155 |
test.deepEqual(topojson.merge(topology, topology.objects.collection.geometries), { |
| 156 |
type: "MultiPolygon", |
| 157 |
coordinates: [[[[2, 0], [0, 0], [0, 3], [2, 3], [4, 3], [4, 0], [2, 0]]]] |
| 158 |
}); |
| 159 |
test.end(); |
| 160 |
}); |