RegionExtractorWithDifferentInputTests.java 5.82 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
5
6
7
8
import java.io.IOException;
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
9
import org.junit.jupiter.api.Test;
10
11
12
13
import org.locationtech.jts.geom.Polygon;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;
import org.locationtech.jts.io.WKTWriter;
14
15
16
17
import org.osgeo.proj4j.CoordinateReferenceSystem;
import com.ximpleware.NavException;
import com.ximpleware.XPathEvalException;
import com.ximpleware.XPathParseException;
18
import eu.simstadt.geo.RegionChooserUtils;
19
20
21
22


public class RegionExtractorWithDifferentInputTests
{
23
24
	private static final WKTReader WKT_READER = new WKTReader();
	private static final WKTWriter WKT_WRITER = new WKTWriter();
Matthias Betz's avatar
Matthias Betz committed
25
	private static final Path TEST_REPOSITORY = Paths.get("src/test/resources/testdata/");
26
27
28

	//NOTE: This test can be adapted to download a region which is too large for the server. Here with local coordinates
	@Test
Eric Duminil's avatar
Eric Duminil committed
29
30
	public void testExtractRegionWithLocalCRS()
			throws IOException, XPathParseException, NavException, XPathEvalException, ParseException {
31
32
		String citygml = "DA13_DA14_3D_Buildings_Port_Morris.gml";
		String projectName = "NewYork";
33
		Path project = TEST_REPOSITORY.resolve(projectName + ".proj");
34
35
36
		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);

37
		CoordinateReferenceSystem localCRS = RegionChooserUtils.crsFromCityGMLHeader(citygmlPath);
Eric Duminil's avatar
Eric Duminil committed
38
		StringBuilder sb = RegionExtractor.selectRegionDirectlyFromCityGML(citygmlPath, wktPolygon, localCRS.getName());
Eric Duminil's avatar
Eric Duminil committed
39
40
		assertTrue(sb.toString().contains("gml_ZVHMQQ6BZGRT0O3Q6RGXF12BDOV49QIZ58XB"),
				"One weird shaped roof should be inside the region");
41
42
43
44
	}

	//NOTE: This test can be adapted to download a region which is too large for the server. Here with WGS84 coordinates
	@Test
Eric Duminil's avatar
Eric Duminil committed
45
46
	public void testExtractRegionWithWGS84()
			throws ParseException, IOException, XPathParseException, NavException, XPathEvalException {
47
48
49
		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";
50
		Path project = TEST_REPOSITORY.resolve(projectName + ".proj");
51
52
		Path citygmlPath = project.resolve(citygml);

53
		Polygon wgs84Polygon = (Polygon) WKT_READER.read(wgs84WktPolygon);
54
		CoordinateReferenceSystem localCRS = RegionChooserUtils.crsFromCityGMLHeader(citygmlPath);
Eric Duminil's avatar
Eric Duminil committed
55
56
		String localWktPolygon = WKT_WRITER
				.write(RegionChooserUtils.changePolygonCRS(wgs84Polygon, RegionChooserUtils.WGS84, localCRS));
Eric Duminil's avatar
Eric Duminil committed
57
		StringBuilder sb = RegionExtractor.selectRegionDirectlyFromCityGML(citygmlPath, localWktPolygon,
58
				localCRS.getName());
Eric Duminil's avatar
Eric Duminil committed
59
60
		assertTrue(sb.toString().contains("gml_ZVHMQQ6BZGRT0O3Q6RGXF12BDOV49QIZ58XB"),
				"One weird shaped roof should be inside the region");
61
62
63
64
	}

	//NOTE: This test can be adapted to download a region which is too large for the server. Here with old coordinates from WebSimstadt
	@Test
Eric Duminil's avatar
Eric Duminil committed
65
66
	public void testExtractRegionWithOldCoordinates()
			throws ParseException, IOException, XPathParseException, NavException, XPathEvalException {
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
		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";
99
		Path project = TEST_REPOSITORY.resolve(projectName + ".proj");
100
101
		Path citygmlPath = project.resolve(citygml);

102
		Polygon wgs84Polygon = (Polygon) WKT_READER.read(wgs84WktPolygon);
103
		CoordinateReferenceSystem localCRS = RegionChooserUtils.crsFromCityGMLHeader(citygmlPath);
Eric Duminil's avatar
Eric Duminil committed
104
105
		String localWktPolygon = WKT_WRITER
				.write(RegionChooserUtils.changePolygonCRS(wgs84Polygon, RegionChooserUtils.WGS84, localCRS));
Eric Duminil's avatar
Eric Duminil committed
106
		StringBuilder sb = RegionExtractor.selectRegionDirectlyFromCityGML(citygmlPath, localWktPolygon,
107
108
				localCRS.getName());

Eric Duminil's avatar
Eric Duminil committed
109
110
		assertTrue(sb.toString().contains("gml_ZVHMQQ6BZGRT0O3Q6RGXF12BDOV49QIZ58XB"),
				"One weird shaped roof should be inside the region");
111
112
113
114
	}

	//TODO: Write a method to merge RegionChooser results from multiple gmls
}