RegionExtractorWithDifferentInputTests.java 5.01 KB
Newer Older
1
2
package eu.simstadt.regionchooser;

Eric Duminil's avatar
Eric Duminil committed
3
import static org.junit.jupiter.api.Assertions.assertTrue;
4
import java.io.IOException;
Eric Duminil's avatar
Eric Duminil committed
5
import java.io.StringWriter;
6
7
8
9
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.stream.Collectors;
Eric Duminil's avatar
Eric Duminil committed
10
import org.junit.jupiter.api.Test;
11
import org.locationtech.jts.io.ParseException;
12
13
14
15
16
17
import org.osgeo.proj4j.CoordinateReferenceSystem;
import com.ximpleware.NavException;
import com.ximpleware.XPathEvalException;
import com.ximpleware.XPathParseException;


Eric Duminil's avatar
Eric Duminil committed
18
class RegionExtractorWithDifferentInputTests
19
{
Matthias Betz's avatar
Matthias Betz committed
20
	private static final Path TEST_REPOSITORY = Paths.get("src/test/resources/testdata/");
21
22

	@Test
Eric Duminil's avatar
Eric Duminil committed
23
	void testExtractRegionWithLocalCRS()
Eric Duminil's avatar
Eric Duminil committed
24
			throws IOException, XPathParseException, NavException, XPathEvalException, ParseException {
25
26
		String citygml = "DA13_DA14_3D_Buildings_Port_Morris.gml";
		String projectName = "NewYork";
27
		Path project = TEST_REPOSITORY.resolve(projectName + ".proj");
28
29
30
		String wktPolygon = "POLYGON ((307475.5578835043 70804.63316765877, 307236.984333501 70360.67156492763, 307650.1509142817 70061.64902227426, 307964.8070375744 70462.43265268637, 307627.75063951925 70710.99549733262, 307475.5578835043 70804.63316765877))";
		Path citygmlPath = project.resolve(citygml);

31
		CoordinateReferenceSystem localCRS = RegionChooserUtils.crsFromCityGMLHeader(citygmlPath);
Eric Duminil's avatar
Eric Duminil committed
32
33
34
		StringWriter gmlWriter = new StringWriter();
		RegionExtractor.selectRegionDirectlyFromCityGML(wktPolygon, localCRS.getName(), gmlWriter, citygmlPath);
		assertTrue(gmlWriter.toString().contains("gml_ZVHMQQ6BZGRT0O3Q6RGXF12BDOV49QIZ58XB"),
Eric Duminil's avatar
Eric Duminil committed
35
				"One weird shaped roof should be inside the region");
36
37
38
	}

	@Test
Eric Duminil's avatar
Eric Duminil committed
39
	void testExtractRegionWithWGS84()
Eric Duminil's avatar
Eric Duminil committed
40
			throws ParseException, IOException, XPathParseException, NavException, XPathEvalException {
41
42
43
		String wgs84WktPolygon = "POLYGON((-73.91140940026597 40.804246732157196,-73.91424181298568 40.80025100302325,-73.90934946374252 40.79755456207104,-73.90561582879378 40.80116062104605,-73.90960695580794 40.80340212653638,-73.91140940026597 40.804246732157196))";
		String citygml = "DA13_DA14_3D_Buildings_Port_Morris.gml";
		String projectName = "NewYork";
44
		Path project = TEST_REPOSITORY.resolve(projectName + ".proj");
45
46
		Path citygmlPath = project.resolve(citygml);

47
		CoordinateReferenceSystem localCRS = RegionChooserUtils.crsFromCityGMLHeader(citygmlPath);
Eric Duminil's avatar
Eric Duminil committed
48
		String localWktPolygon = RegionChooserUtils.wktPolygonToLocalCRS(wgs84WktPolygon, localCRS);
Eric Duminil's avatar
Eric Duminil committed
49
50
51
		StringWriter gmlWriter = new StringWriter();
		RegionExtractor.selectRegionDirectlyFromCityGML(localWktPolygon, localCRS.getName(), gmlWriter, citygmlPath);
		assertTrue(gmlWriter.toString().contains("gml_ZVHMQQ6BZGRT0O3Q6RGXF12BDOV49QIZ58XB"),
Eric Duminil's avatar
Eric Duminil committed
52
				"One weird shaped roof should be inside the region");
53
54
55
	}

	@Test
Eric Duminil's avatar
Eric Duminil committed
56
	void testExtractRegionWithOldCoordinates()
Eric Duminil's avatar
Eric Duminil committed
57
			throws ParseException, IOException, XPathParseException, NavException, XPathEvalException {
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
		String oldFormatPolygon = "(40.81173171854368,-73.93268437431763)\r\n" +
				"(40.81069231965162,-73.93068165999941)\r\n" +
				"(40.809176499753505,-73.92907948540162)\r\n" +
				"(40.806924362178165,-73.92433018905214)\r\n" +
				"(40.80328613125832,-73.91620488213013)\r\n" +
				"(40.803546011509866,-73.91425938739778)\r\n" +
				"(40.80649124858661,-73.90750737411074)\r\n" +
				"(40.81069231965162,-73.90184254867128)\r\n" +
				"(40.81285771431433,-73.89806599837831)\r\n" +
				"(40.811688409259915,-73.89537663331359)\r\n" +
				"(40.80874340284353,-73.89486164918273)\r\n" +
				"(40.80943635693916,-73.89011235283326)\r\n" +
				"(40.80553839032126,-73.88919682374328)\r\n" +
				"(40.80501864440376,-73.90207142701476)\r\n" +
				"(40.79674547521796,-73.9115128027472)\r\n" +
				"(40.798868011290665,-73.9190086863666)\r\n" +
				"(40.801553568920895,-73.92135472343872)\r\n" +
				"(40.802506484398094,-73.92324299858521)\r\n" +
				"(40.80259311095742,-73.92759175521425)\r\n" +
				"(40.803762576287,-73.92787785576294)\r\n" +
				"(40.806967670606156,-73.93113942192505)\r\n" +
				"(40.80878671206696,-73.93262715473178)\r\n" +
				"(40.81173171854368,-73.93268437431763)\r\n";

		String wgs84WktPolygon = "POLYGON((" +
				Arrays.stream(oldFormatPolygon.replaceAll("\\(", "").replaceAll("\\)", "").split("\\r?\\n")).map(latLon -> {
					String lat = latLon.split(",")[0];
					String lon = latLon.split(",")[1];
					return lon + " " + lat;
				}).collect(Collectors.joining(",")) + "))";
		String citygml = "DA13_DA14_3D_Buildings_Port_Morris.gml";
		String projectName = "NewYork";
90
		Path project = TEST_REPOSITORY.resolve(projectName + ".proj");
91
92
		Path citygmlPath = project.resolve(citygml);

93
		CoordinateReferenceSystem localCRS = RegionChooserUtils.crsFromCityGMLHeader(citygmlPath);
Eric Duminil's avatar
Eric Duminil committed
94
		String localWktPolygon = RegionChooserUtils.wktPolygonToLocalCRS(wgs84WktPolygon, localCRS);
Eric Duminil's avatar
Eric Duminil committed
95
96
		StringWriter gmlWriter = new StringWriter();
		RegionExtractor.selectRegionDirectlyFromCityGML(localWktPolygon, localCRS.getName(), gmlWriter, citygmlPath);
97

Eric Duminil's avatar
Eric Duminil committed
98
		assertTrue(gmlWriter.toString().contains("gml_ZVHMQQ6BZGRT0O3Q6RGXF12BDOV49QIZ58XB"),
Eric Duminil's avatar
Eric Duminil committed
99
				"One weird shaped roof should be inside the region");
100
101
	}
}