Commit e910bf8c authored by Matthias Betz's avatar Matthias Betz
Browse files

remove test code

parent 7e7235d9
package de.hft.stuttgart.sektorsim.server;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.citygml4j.core.model.core.AbstractCityObject;
import org.citygml4j.core.model.core.AbstractFeature;
import org.citygml4j.core.model.core.CityModel;
import org.citygml4j.xml.CityGMLContext;
import org.citygml4j.xml.CityGMLContextException;
import org.citygml4j.xml.reader.CityGMLInputFactory;
import org.citygml4j.xml.reader.CityGMLReadException;
import org.citygml4j.xml.reader.CityGMLReader;
public class ExtractIDList {
public static void main(String[] args) throws CityGMLReadException, CityGMLContextException {
String zipFilePath = "part_1131.zip";
Path output = Path.of("deleteList_1131.txt");
try (ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFilePath))) {
ZipEntry entry;
List<String> ids = new ArrayList<>();
ids.add("GMLID");
CityGMLContext context = CityGMLContext.newInstance();
CityGMLInputFactory in = context.createCityGMLInputFactory();
while ((entry = zis.getNextEntry()) != null) {
System.out.println("Entry: " + entry.getName());
if (!entry.isDirectory()) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[4096];
int len;
while ((len = zis.read(buffer)) != -1) {
baos.write(buffer, 0, len);
}
// Create a new input stream from the entry's content
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
try (CityGMLReader reader = in.createCityGMLReader(bais)) {
while (reader.hasNext()) {
AbstractFeature citygml = reader.next();
if (citygml instanceof CityModel cityModel) {
cityModel.getCityObjectMembers().forEach(prop -> {
AbstractCityObject aco = prop.getObject();
ids.add(aco.getId());
});
}
}
}
}
zis.closeEntry();
}
Files.write(output, ids, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
} catch (IOException e) {
e.printStackTrace();
}
}
}
package de.hft.stuttgart.sektorsim.server.controller;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Collections;
import org.junit.jupiter.api.Test;
import org.locationtech.jts.io.ParseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;
@SpringBootTest
class CityGMLServerControllerTest {
@Autowired
CityGMLServerController controller;
@Test
void testGetCityGML() throws ParseException, IOException {
String wktString = "POLYGON ((9.872730080693117 48.58178884030471,"
+ " 9.873389990085997 48.58267166044939,"
+ " 9.874665814913612 48.58201197212753,"
+ " 9.874211210664527 48.583767888178585,"
+ " 9.871630231703818 48.583428351158176,"
+ " 9.872730080693117 48.58178884030471))";
// https://owsproxy.lgl-bw.de/owsproxy/wfs/WFS_INSP_BW_Gebauede_3D_LoD2?
// CityGMLServerController controller = new CityGMLServerController("https://owsproxy.lgl-bw.de/owsproxy/wfs/WFS_INSP_BW_Gebauede_3D_LoD2");
// CityGMLServerController controller = new CityGMLServerController(new CityDB5Connector());
ResponseEntity<StreamingResponseBody> cityGML = controller.getCityGML(wktString, Collections.emptyList(), 2019);
HttpStatusCode statusCode = cityGML.getStatusCode();
assertEquals(HttpStatusCode.valueOf(200), statusCode);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
cityGML.getBody().writeTo(baos);
byte[] byteArray = baos.toByteArray();
assertEquals(1278220, byteArray.length);
}
}
package de.hft.stuttgart.sektorsim.server.wfs;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.Test;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.Polygon;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;
import jakarta.xml.bind.JAXBException;
class GetFeatureTest {
@Test
void testWriteTo() throws JAXBException, IOException, ParseException, URISyntaxException, InterruptedException {
GetFeatureRequest getFeature = new GetFeatureRequest();
getFeature.setService("WFS");
getFeature.setVersion("2.0.0");
getFeature.setHandle("GetFeatureRequest");
Query query = new Query();
query.setTypeNames("bldg:Building");
query.setHandle("Q01");
getFeature.setQuery(query);
Filter filter = new Filter();
query.setFilter(filter);
Intersects intersects = new Intersects();
filter.setIntersects(intersects);
intersects.setValueReference("gml:boundedBy");
GeometryFactory factory = new GeometryFactory();
WKTReader wktReader = new WKTReader(factory);
Geometry geometry = wktReader.read("POLYGON ((9.872730080693117 48.58178884030471,\r\n"
+ " 9.873389990085997 48.58267166044939,\r\n"
+ " 9.874665814913612 48.58201197212753,\r\n"
+ " 9.874211210664527 48.583767888178585,\r\n"
+ " 9.871630231703818 48.583428351158176,\r\n"
+ " 9.872730080693117 48.58178884030471))");
if (!(geometry instanceof Polygon polygon)) {
throw new IllegalArgumentException("Geometry is not a polygon");
}
polygon.setUserData(new PolygonAttributes("id_poly", "EPSG:4326"));
intersects.setPolygon(polygon);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
getFeature.writeTo(outputStream);
outputStream.flush();
outputStream.close();
String xmlOutput = outputStream.toString();
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(new URI("http://localhost:8080/wfs"))
.header("Content-Type", "application/xml")
.POST(BodyPublishers.ofString(xmlOutput))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println("Status code: " + response.statusCode());
System.out.println("Response: " + response.body());
}
@Test
void parseXml() throws JAXBException {
String xml = "<?xml version=\"1.0\" ?>\r\n" + "<GetFeature\r\n" + "version=\"2.0.0\"\r\n"
+ "service=\"WFS\"\r\n" + "handle=\"Example Query\"\r\n"
+ "xmlns=\"http://www.opengis.net/wfs/2.0\"\r\n" + "xmlns:fes=\"http://www.opengis.net/fes/2.0\"\r\n"
+ "xmlns:gml=\"http://www.opengis.net/gml/3.2\"\r\n"
+ "xmlns:myns=\"http://www.someserver.com/myns\"\r\n"
+ "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n"
+ "xsi:schemaLocation=\"http://www.opengis.net/wfs/2.0\r\n"
+ "http://schemas.opengis.net/wfs/2.0.0/wfs.xsd\r\n" + "http://www.opengis.net/gml/3.2\r\n"
+ "http://schemas.opengis.net/gml/3.2.1/gml.xsd\">\r\n"
+ "<Query typeNames=\"myns:Roads\" handle=\"Q01\">\r\n" + "<fes:Filter>\r\n" + "<fes:Intersects>\r\n"
+ "<fes:ValueReference>myns:path</fes:ValueReference>\r\n"
+ "<gml:Polygon srsName=\"urn:ogc:def:crs:EPSG::4326\" gml:id=\"P1\">\r\n" + "<gml:exterior>\r\n"
+ "<gml:LinearRing>\r\n" + "<gml:posList>-19.06099128723145 -169.9416961669922 -19.0565"
+ "3190612793 -169.9346008300781 -19.0523681640625 -169.9278564453125 -19.047290802"
+ "00195 -169.9230346679688 -19.03918266296387 -169.9215698242188 -19.0405883789062"
+ "5 -169.9138641357422 -19.04656600952148 -169.9136047363281 -19.05992698669434 -1"
+ "69.9196014404297 -19.06432342529297 -169.9275665283203 -19.06826400756836 -169.9"
+ "364929199219 -19.06099128723145 -169.9416961669922</gml:posList>\r\n" + "</gml:LinearRing>\r\n"
+ "</gml:exterior>\r\n" + "</gml:Polygon>\r\n" + "</fes:Intersects>\r\n" + "</fes:Filter>\r\n"
+ "</Query>\r\n" + "</GetFeature>";
GetFeatureRequest getFeature = GetFeatureRequest.parse(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)));
assertEquals(
"POLYGON ((-19.06099128723145 -169.9416961669922, -19.05653190612793"
+ " -169.9346008300781, -19.0523681640625 -169.9278564453125, -19.04729080200195"
+ " -169.9230346679688, -19.03918266296387 -169.9215698242188, -19.04058837890625"
+ " -169.9138641357422, -19.04656600952148 -169.9136047363281, -19.05992698669434"
+ " -169.9196014404297, -19.06432342529297 -169.9275665283203, -19.06826400756836"
+ " -169.9364929199219, -19.06099128723145 -169.9416961669922))",
getFeature.getQuery().getFilter().getIntersects().getPolygon().toString());
}
}
Supports Markdown
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