Commit d8d783d8 authored by Eric Duminil's avatar Eric Duminil
Browse files

RegionChooser: Tests and scripts to extract region with different input formats.

parent fcb4c2d2
......@@ -37,6 +37,7 @@ java -classpath lib/* -Xms512m -Xmx2g -Djava.util.logging.config.file=logging.pr
<!-- RegionExtractor -->
<test name="eu.simstadt.regionchooser.RegionExtractorTests" haltonfailure="no" todir="${reports.dir}" />
<test name="eu.simstadt.regionchooser.RegionExtractorWithDifferentInputTests" haltonfailure="yes" todir="${reports.dir}" />
</junit>
</jacoco:coverage>
</target>
......
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;
import org.osgeo.proj4j.CoordinateReferenceSystem;
import com.vividsolutions.jts.geom.Polygon;
import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.io.WKTReader;
import com.vividsolutions.jts.io.WKTWriter;
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);
StringBuffer sb = RegionExtractor.selectRegionDirectlyFromCityGML(citygmlPath, wktPolygon, 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 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));
StringBuffer sb = RegionExtractor.selectRegionDirectlyFromCityGML(citygmlPath, localWktPolygon,
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));
StringBuffer sb = RegionExtractor.selectRegionDirectlyFromCityGML(citygmlPath, localWktPolygon,
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
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment