RegionExtractorTests.java 4.43 KB
Newer Older
1
2
3
package eu.simstadt.regionchooser.test;

import static org.junit.Assert.assertEquals;
4
import static org.junit.Assert.assertFalse;
5
6
7
import static org.junit.Assert.assertTrue;
import java.nio.file.Path;
import java.nio.file.Paths;
duminil's avatar
duminil committed
8
9
import java.util.regex.Matcher;
import java.util.regex.Pattern;
10
11
12
13
14
15
import org.junit.Test;
import eu.simstadt.regionchooser.RegionExtractor;


public class RegionExtractorTests
{
duminil's avatar
duminil committed
16
17
18
19
20
21
22
23
	public static int countRegexMatches(String str, String subStr) {
		Pattern pattern = Pattern.compile(subStr);
		Matcher matcher = pattern.matcher(str);
		int count = 0;
		while (matcher.find()) {
			count++;
		}
		return count;
24
25
26
27
28
29
30
	}

	@Test
	public void testExtract3BuildingsFromGSK3Model() throws Throwable {
		//NOTE: Small region around Martinskirche in Grünbühl
		String wktPolygon = "POLYGON((3515848.896028535 5415823.108586172,3515848.9512289143 5415803.590347393,3515829.0815150724 5415803.338023346,3515830.9784850604 5415793.437034622,3515842.0946056456 5415793.272282251,3515843.3515515197 5415766.204935087,3515864.1064344468 5415766.557899496,3515876.489172751 5415805.433782301,3515876.343844858 5415822.009293416,3515848.896028535 5415823.108586172))";
		Path repo = Paths.get("../TestRepository");
duminil's avatar
duminil committed
31
		Path citygmlPath = repo.resolve("Gruenbuehl.proj/20140218_Gruenbuehl_LOD2.gml");
32
33
		String churchGMLString = RegionExtractor.selectRegionDirectlyFromCityGML(citygmlPath, wktPolygon, "EPSG:31467")
				.toString();
duminil's avatar
duminil committed
34
		assertEquals(countRegexMatches(churchGMLString, "<(core:)?cityObjectMember"), 3);
35
36
37
38
		assertTrue(churchGMLString.contains("Donaustr"));
		assertTrue(churchGMLString.contains("DEBW_LOD2_203056"));
		assertTrue(churchGMLString.contains("DEBW_LOD2_2869"));
		assertTrue(churchGMLString.contains("DEBW_LOD2_2909"));
39
40
		assertTrue(churchGMLString.contains("<core:CityModel")); // Header
		assertTrue(churchGMLString.contains("</core:CityModel")); // Footer
41
	}
42
43
44
45
46
47
48

	@Test
	public void testExtract3BuildingsFromNAD83Model() throws Throwable {
		//NOTE: Small region around WashingtonSquare
		String wktPolygon = "POLYGON((300259.78663489706 62835.835907766595,300230.33294975647 62792.0482567884,300213.5667431851 62770.83143720031,300183.6592861123 62730.20347659383,300252.9947486632 62676.938468840905,300273.3862256562 62701.767105345614,300257.5250407747 62715.760413539596,300308.2754543957 62805.14198211394,300259.78663489706 62835.835907766595))";
		Path repo = Paths.get("../TestRepository");
		Path citygmlPath = repo.resolve("NewYork.proj/ManhattanSmall.gml");
49
		String archGMLString = RegionExtractor.selectRegionDirectlyFromCityGML(citygmlPath, wktPolygon, "EPSG:32118")
50
51
52
53
54
				.toString();
		assertEquals(countRegexMatches(archGMLString, "<(core:)?cityObjectMember"), 2);
		assertTrue(archGMLString.contains("WASHINGTON SQUARE"));
		assertTrue(archGMLString.contains("uuid_c0980a6e-05ea-4d09-bc83-efab226945a1"));
		assertTrue(archGMLString.contains("uuid_0985cebb-922d-4b3e-95e5-15dc6089cd28"));
55
56
		assertTrue(archGMLString.contains("<CityModel")); // Header
		assertTrue(archGMLString.contains("</CityModel")); // Footer
57
58
		assertFalse(archGMLString.contains("comment between buildings")); // Comment
		assertFalse(archGMLString.contains("comment after last building")); // Comment
59
60
61
62
63
64
65
66
	}

	@Test
	public void testExtract0BuildingsWithWrongCoordinates() throws Throwable {
		//NOTE: Small region, far away from NYC
		String wktPolygon = "POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))";
		Path repo = Paths.get("../TestRepository");
		Path citygmlPath = repo.resolve("NewYork.proj/ManhattanSmall.gml");
67
		String emptyGMLString = RegionExtractor.selectRegionDirectlyFromCityGML(citygmlPath, wktPolygon, "EPSG:32118")
68
				.toString();
69
		assertEquals(countRegexMatches(emptyGMLString, "<(core:)?cityObjectMember"), 0);
70
71
		assertTrue(emptyGMLString.contains("<CityModel")); // Header
		assertTrue(emptyGMLString.contains("</CityModel")); // Footer
72
	}
duminil's avatar
duminil committed
73
74
75
76
77
78
79
80
81
82
83
84
85

	@Test
	public void testExtract0BuildingsFromWeirdGML() throws Throwable {
		//NOTE: Small region, with too many spaces between coordinates
		String wktPolygon = "POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))";
		Path repo = Paths.get("../TestRepository");
		Path citygmlPath = repo.resolve("NewYork.proj/broken_nyc_lod2.gml");
		String emptyGMLString = RegionExtractor.selectRegionDirectlyFromCityGML(citygmlPath, wktPolygon, "EPSG:32118")
				.toString();
		assertEquals(countRegexMatches(emptyGMLString, "<(core:)?cityObjectMember"), 0);
		assertTrue(emptyGMLString.contains("<core:CityModel")); // Header
		assertTrue(emptyGMLString.contains("</core:CityModel")); // Footer
	}
86
}