CitygmlParserTests.java 3.39 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package eu.simstadt.geo.fast_xml_parser;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.junit.Test;
import com.ximpleware.NavException;
import com.ximpleware.XPathEvalException;
import com.ximpleware.XPathParseException;


public class CitygmlParserTests
{
	private void testNoNanInCoordinates(Path citygmlPath)
			throws NumberFormatException, XPathParseException, NavException, XPathEvalException, IOException {
		CityGmlIterator buildingXmlNodes = new CityGmlIterator(citygmlPath);
		for (BuildingXmlNode buildingXmlNode : buildingXmlNodes) {
			assertTrue("Buildings should have coordinates", buildingXmlNode.hasCoordinates());
			assertFalse("Coordinate should be a double", Double.isNaN(buildingXmlNode.x));
			assertFalse("Coordinate should be a double", Double.isNaN(buildingXmlNode.y));
			assertFalse("Coordinate should be a double", Double.isNaN(buildingXmlNode.xMax));
			assertFalse("Coordinate should be a double", Double.isNaN(buildingXmlNode.yMax));
			assertFalse("Coordinate should be a double", Double.isNaN(buildingXmlNode.xMin));
			assertFalse("Coordinate should be a double", Double.isNaN(buildingXmlNode.yMin));
			assertTrue("Coordinates Min/Max should be plausible", buildingXmlNode.xMax > buildingXmlNode.x);
			assertTrue("Coordinates Min/Max should be plausible", buildingXmlNode.yMax > buildingXmlNode.y);
			assertTrue("Coordinates Min/Max should be plausible", buildingXmlNode.xMin < buildingXmlNode.x);
			assertTrue("Coordinates Min/Max should be plausible", buildingXmlNode.yMin < buildingXmlNode.y);
		}
	}

	@Test
	public void testExtractCoordsFromStuttgart()
			throws NumberFormatException, XPathParseException, NavException, XPathEvalException, IOException {
38
39
		Path repo = Paths.get("../RegionChooser/test/testdata");
		Path citygmlPath = repo.resolve("Stuttgart_LOD0_LOD1_buildings_and_trees.gml");
40
41
42
43
44
		testNoNanInCoordinates(citygmlPath);
	}

	@Test
	public void testExtractCoordsFromGruenbuehl() throws Throwable {
45
46
		Path repo = Paths.get("../RegionChooser/test/testdata");
		Path citygmlPath = repo.resolve("20140218_Gruenbuehl_LOD2_1building.gml");
47
48
49
50
51
		testNoNanInCoordinates(citygmlPath);
	}

	@Test
	public void testExtractCoordsFromMunich() throws Throwable {
52
53
		Path repo = Paths.get("../RegionChooser/test/testdata");
		Path citygmlPath = repo.resolve("Munich_v_1_0_0.gml");
54
55
56
57
58
		testNoNanInCoordinates(citygmlPath);
	}

	@Test
	public void testExtractCoordsFromNYC() throws Throwable {
59
60
		Path repo = Paths.get("../RegionChooser/test/testdata");
		Path citygmlPath = repo.resolve("ManhattanSmall.gml");
61
62
63
64
65
		testNoNanInCoordinates(citygmlPath);
	}

	@Test
	public void testExtractNoCoordsFromEmptyBuilding() throws Throwable {
66
67
		Path repo = Paths.get("../RegionChooser/test/testdata");
		Path citygmlPath = repo.resolve("Stöckach_empty_buildings.gml");
68
69
70
71
72
73
74
75
76
77
78
		CityGmlIterator buildingXmlNodes = new CityGmlIterator(citygmlPath);
		int counter = 0;
		for (BuildingXmlNode buildingXmlNode : buildingXmlNodes) {
			assertFalse("Empty Buildings shouldn't have coordinates", buildingXmlNode.hasCoordinates());
			assertTrue("Coordinate should be a Nan", Double.isNaN(buildingXmlNode.x));
			assertTrue("Coordinate should be a Nan", Double.isNaN(buildingXmlNode.y));
			counter++;
		}
		assertEquals("3 buildings should have been analyzed", counter, 3);
	}
}