RegionExtractorWithDifferentInputTests.java 5.73 KB
Newer Older
1
2
3
4
5
6
7
8
9
package eu.simstadt.regionchooser;

import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.stream.Collectors;
import org.junit.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
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import org.osgeo.proj4j.CoordinateReferenceSystem;
import com.ximpleware.NavException;
import com.ximpleware.XPathEvalException;
import com.ximpleware.XPathParseException;
import eu.simstadt.geo.GeoUtils;


public class RegionExtractorWithDifferentInputTests
{
	WKTReader reader = new WKTReader();
	WKTWriter writer = new WKTWriter();

	//NOTE: This test can be adapted to download a region which is too large for the server. Here with local coordinates
	@Test
	public void testExtractRegionWithLocalCRS() throws NumberFormatException, XPathParseException, NavException,
			XPathEvalException, ParseException, IOException {
		String citygml = "DA13_DA14_3D_Buildings_Port_Morris.gml";
		String projectName = "NewYork";
		Path repo = Paths.get("../TestRepository");
		Path project = repo.resolve(projectName + ".proj");
		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);

		CoordinateReferenceSystem localCRS = GeoUtils.crsFromCityGMLHeader(citygmlPath);
Eric Duminil's avatar
Eric Duminil committed
38
		StringBuilder sb = RegionExtractor.selectRegionDirectlyFromCityGML(citygmlPath, wktPolygon, localCRS.getName());
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
		assertTrue("One weird shaped roof should be inside the region",
				sb.toString().contains("gml_ZVHMQQ6BZGRT0O3Q6RGXF12BDOV49QIZ58XB"));
	}

	//NOTE: This test can be adapted to download a region which is too large for the server. Here with WGS84 coordinates
	@Test
	public void testExtractRegionWithWGS84() throws ParseException, IOException, NumberFormatException,
			XPathParseException, NavException, XPathEvalException {
		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";
		Path repo = Paths.get("../TestRepository");
		Path project = repo.resolve(projectName + ".proj");
		Path citygmlPath = project.resolve(citygml);

		Polygon wgs84Polygon = (Polygon) reader.read(wgs84WktPolygon);
		CoordinateReferenceSystem localCRS = GeoUtils.crsFromCityGMLHeader(citygmlPath);
		String localWktPolygon = writer.write(GeoUtils.changePolygonCRS(wgs84Polygon, GeoUtils.WGS84, localCRS));
Eric Duminil's avatar
Eric Duminil committed
57
		StringBuilder sb = RegionExtractor.selectRegionDirectlyFromCityGML(citygmlPath, localWktPolygon,
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
				localCRS.getName());
		assertTrue("One weird shaped roof should be inside the region",
				sb.toString().contains("gml_ZVHMQQ6BZGRT0O3Q6RGXF12BDOV49QIZ58XB"));
	}

	//NOTE: This test can be adapted to download a region which is too large for the server. Here with old coordinates from WebSimstadt
	@Test
	public void testExtractRegionWithOldCoordinates() throws ParseException, IOException, NumberFormatException,
			XPathParseException, NavException, XPathEvalException {
		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";
		Path repo = Paths.get("../TestRepository");
		Path project = repo.resolve(projectName + ".proj");
		Path citygmlPath = project.resolve(citygml);

		Polygon wgs84Polygon = (Polygon) reader.read(wgs84WktPolygon);
		CoordinateReferenceSystem localCRS = GeoUtils.crsFromCityGMLHeader(citygmlPath);
		String localWktPolygon = writer.write(GeoUtils.changePolygonCRS(wgs84Polygon, GeoUtils.WGS84, localCRS));
Eric Duminil's avatar
Eric Duminil committed
106
		StringBuilder sb = RegionExtractor.selectRegionDirectlyFromCityGML(citygmlPath, localWktPolygon,
107
108
109
110
111
112
113
114
				localCRS.getName());

		assertTrue("One weird shaped roof should be inside the region",
				sb.toString().contains("gml_ZVHMQQ6BZGRT0O3Q6RGXF12BDOV49QIZ58XB"));
	}

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