ConvexHullCalculatorTests.java 3.61 KB
Newer Older
1
2
3
4
package eu.simstadt.geo.fast_xml_parser;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
5
import java.io.IOException;
6
7
8
9
10
11
12
13
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Test;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.Point;
14
import com.ximpleware.XPathParseException;
15
16
17
18
19
20
import eu.simstadt.geo.GeoUtils;


public class ConvexHullCalculatorTests
{
	private static final GeometryFactory gf = new GeometryFactory();
Matthias Betz's avatar
Matthias Betz committed
21
	private static final Path repository = Paths.get("../RegionChooser/src/test/resources/testdata");
22
23

	@Test
24
25
	public void testExtractConvexHullFromOneBuilding() throws IOException, XPathParseException {
		Path citygmlPath = repository.resolve("Gruenbuehl.proj/20140218_Gruenbuehl_LOD2_1building.gml");
26
27
28
29
30
31
32
		Geometry hull = ConvexHullCalculator.calculateFromCityGML(citygmlPath);
		assertEquals(hull.getCoordinates().length, 4 + 1); // Convex hull of a building should be a closed rectangle
		Point someBuildingPoint = gf.createPoint(new Coordinate(9.216845, 48.878196)); // WGS84
		assertTrue("Hull should contain every building point", hull.contains(someBuildingPoint));
	}

	@Test
33
34
	public void testExtractConvexHullFromOneSmallRegion() throws IOException, XPathParseException {
		Path citygmlPath = repository.resolve("Gruenbuehl.proj/Gruenbuehl_LOD2_ALKIS_1010.gml");
35
36
37
38
39
40
41
42
		Geometry hull = ConvexHullCalculator.calculateFromCityGML(citygmlPath);
		assertTrue(hull.getCoordinates().length > 4); // Convex hull should have at least 4 corners
		//		Point somewhereBetweenBuildings = gf.createPoint(new Coordinate(3515883.6668538367, 5415843.300640578)); // Original coordinates, GSK3
		Point somewhereBetweenBuildings = gf.createPoint(new Coordinate(9.21552249084, 48.87980446)); // WGS84
		assertTrue("Hull should contain region between buildings", hull.contains(somewhereBetweenBuildings));
	}

	@Test
43
44
	public void testExtractConvexHullFromStoeckachNoBuildingPart() throws IOException, XPathParseException {
		Path citygmlPath = repository.resolve("Stuttgart.proj/Stöckach_überarbeitete GML-NoBuildingPart.gml");
45
46
47
48
49
50
51
		Geometry hull = ConvexHullCalculator.calculateFromCityGML(citygmlPath);
		assertTrue(hull.getCoordinates().length > 4); // Convex hull should have at least 4 corners
		Point somewhereBetweenBuildings = gf.createPoint(new Coordinate(9.195212, 48.789062)); // WGS84
		assertTrue("Hull should contain region between buildings", hull.contains(somewhereBetweenBuildings));
	}

	@Test
52
53
	public void testExtractConvexHullFromEveryCitygmlInRepository() throws IOException {
		int minHullCount = 6;
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
		//NOTE: Should cache be deleted first?
		// Files.walk(repository.resolve(".cache/hulls"), 1).forEach(System.out::println);
		long gmlCount = GeoUtils.everyCityGML(repository).count();
		AtomicInteger hullCount = new AtomicInteger(0);
		ConvexHullCalculator.extractHullsForEveryCityGML(repository, kmlHull -> {
			assertTrue("KML hull should contain project name", kmlHull.contains("Data name=\"project\""));
			assertTrue("KML hull should contain srs name", kmlHull.contains("Data name=\"srsName\""));
			assertTrue("KML hull should contain epsg id", kmlHull.contains("<value>EPSG:"));
			assertTrue("KML hull should contain coordinates", kmlHull.contains("<coordinates>"));
			hullCount.getAndIncrement();
		});
		assertTrue("At least " + minHullCount + " citygmls should be present in repository", gmlCount >= minHullCount);
		assertTrue("At least " + minHullCount + " hulls should have been calculated", hullCount.get() >= minHullCount);
	}
}