2021-12-23 10:42:24 +00:00
|
|
|
package com.onthegomap.planetiler.examples;
|
2021-08-17 01:51:49 +00:00
|
|
|
|
2021-12-23 10:42:24 +00:00
|
|
|
import static com.onthegomap.planetiler.TestUtils.assertContains;
|
2021-08-17 01:51:49 +00:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
2021-12-23 10:42:24 +00:00
|
|
|
import com.onthegomap.planetiler.FeatureCollector;
|
|
|
|
import com.onthegomap.planetiler.TestUtils;
|
|
|
|
import com.onthegomap.planetiler.config.Arguments;
|
|
|
|
import com.onthegomap.planetiler.geo.GeoUtils;
|
|
|
|
import com.onthegomap.planetiler.mbtiles.Mbtiles;
|
|
|
|
import com.onthegomap.planetiler.reader.SimpleFeature;
|
2021-08-17 01:51:49 +00:00
|
|
|
import java.nio.file.Path;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.junit.jupiter.api.io.TempDir;
|
|
|
|
import org.locationtech.jts.geom.Point;
|
|
|
|
|
2022-04-23 10:36:24 +00:00
|
|
|
class ToiletsProfileTest {
|
2021-08-17 01:51:49 +00:00
|
|
|
|
|
|
|
private final ToiletsOverlay profile = new ToiletsOverlay();
|
|
|
|
|
|
|
|
@Test
|
2022-04-23 10:36:24 +00:00
|
|
|
void testSourceFeatureProcessing() {
|
2021-09-10 00:46:20 +00:00
|
|
|
var node = SimpleFeature.create(
|
2021-08-17 01:51:49 +00:00
|
|
|
TestUtils.newPoint(1, 2),
|
2021-09-10 00:46:20 +00:00
|
|
|
Map.of("amenity", "toilets")
|
2021-08-17 01:51:49 +00:00
|
|
|
);
|
|
|
|
List<FeatureCollector.Feature> mapFeatures = TestUtils.processSourceFeature(node, profile);
|
|
|
|
|
|
|
|
// verify output feature
|
|
|
|
assertEquals(1, mapFeatures.size());
|
|
|
|
var feature = mapFeatures.get(0);
|
|
|
|
assertEquals("toilets", feature.getLayer());
|
|
|
|
// no attributes
|
|
|
|
assertEquals(Map.of(), feature.getAttrsAtZoom(14));
|
|
|
|
assertEquals(0, feature.getMinZoom());
|
|
|
|
assertEquals(14, feature.getMaxZoom());
|
2021-09-18 00:18:06 +00:00
|
|
|
assertEquals(1, feature.getSortKey());
|
2021-08-17 01:51:49 +00:00
|
|
|
|
|
|
|
// at z12 - use label grid to limit output
|
2022-01-10 11:41:15 +00:00
|
|
|
assertEquals(4, feature.getPointLabelGridLimitAtZoom(12));
|
|
|
|
assertEquals(32, feature.getPointLabelGridPixelSizeAtZoom(12));
|
2021-08-17 01:51:49 +00:00
|
|
|
assertEquals(32, feature.getBufferPixelsAtZoom(12));
|
|
|
|
|
|
|
|
// at z13 - no label grid (0 disables filtering)
|
2022-01-10 11:41:15 +00:00
|
|
|
assertEquals(0, feature.getPointLabelGridLimitAtZoom(13));
|
|
|
|
assertEquals(0, feature.getPointLabelGridPixelSizeAtZoom(13));
|
2021-08-17 01:51:49 +00:00
|
|
|
assertEquals(4, feature.getBufferPixelsAtZoom(13));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2022-04-23 10:36:24 +00:00
|
|
|
void integrationTest(@TempDir Path tmpDir) throws Exception {
|
2021-08-17 01:51:49 +00:00
|
|
|
Path dbPath = tmpDir.resolve("output.mbtiles");
|
|
|
|
ToiletsOverlay.run(Arguments.of(
|
|
|
|
// Override input source locations
|
2021-09-10 00:46:20 +00:00
|
|
|
"osm_path", TestUtils.pathToResource("monaco-latest.osm.pbf"),
|
2021-08-17 01:51:49 +00:00
|
|
|
// Override temp dir location
|
|
|
|
"tmp", tmpDir.toString(),
|
|
|
|
// Override output location
|
2023-03-18 18:38:04 +00:00
|
|
|
"output", dbPath.toString()
|
2021-08-17 01:51:49 +00:00
|
|
|
));
|
|
|
|
try (Mbtiles mbtiles = Mbtiles.newReadOnlyDatabase(dbPath)) {
|
2023-03-18 18:38:04 +00:00
|
|
|
Map<String, String> metadata = mbtiles.metadata().toMap();
|
2021-08-17 01:51:49 +00:00
|
|
|
assertEquals("Toilets Overlay", metadata.get("name"));
|
|
|
|
assertContains("openstreetmap.org/copyright", metadata.get("attribution"));
|
|
|
|
|
|
|
|
TestUtils.assertNumFeatures(mbtiles, "toilets", 14, Map.of(), GeoUtils.WORLD_LAT_LON_BOUNDS,
|
2021-08-22 09:37:57 +00:00
|
|
|
34, Point.class);
|
2021-08-17 01:51:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|