Commit 7e0e8154 authored by bruse's avatar bruse
Browse files

Task #169: The huge library "geotools" has been replaced by the lean library "Proj4J".

parent 48a81112
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
package eu.simstadt.nf; package eu.simstadt.nf4j;
/** /**
* This is an intermediate representation for WGS 84 coordinates. * Another class for coordinates. This is an intermediate representation for WGS 84 coordinates.
* *
* @author Marcel Bruse * @author Marcel Bruse
*/ */
......
package eu.simstadt.nf; package eu.simstadt.nf4j;
import java.util.Objects; import java.util.Objects;
...@@ -14,7 +14,7 @@ public class ExportJob extends Job { ...@@ -14,7 +14,7 @@ public class ExportJob extends Job {
* *
* @return Returns a new export job instance with unknown state. * @return Returns a new export job instance with unknown state.
*/ */
public static ExportJob getUnkownInstance() { public static ExportJob getNewInstance() {
return new ExportJob(JobStatus.UNKOWN); return new ExportJob(JobStatus.UNKOWN);
} }
......
package eu.simstadt.nf; package eu.simstadt.nf4j;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
......
package eu.simstadt.nf; package eu.simstadt.nf4j;
/** /**
* Import jobs are requests to store, change or delete CityGML models. Every valid import job has an id and a status. * Import jobs are requests to store, change or delete CityGML models. Every valid import job has an id and a status.
......
package eu.simstadt.nf; package eu.simstadt.nf4j;
import java.io.File; import java.io.File;
......
package eu.simstadt.nf; package eu.simstadt.nf4j;
/** /**
* This job class bundles the three attributes of every nF job: Id, status and last job related nF (error) message. * This job class bundles the three attributes of every nF job: Id, status and last job related nF (error) message.
......
package eu.simstadt.nf; package eu.simstadt.nf4j;
import java.io.File; import java.io.File;
......
package eu.simstadt.nf; package eu.simstadt.nf4j;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
...@@ -23,15 +23,10 @@ ...@@ -23,15 +23,10 @@
import javax.xml.transform.dom.DOMSource; import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamResult;
import org.geotools.geometry.GeneralDirectPosition; import org.osgeo.proj4j.BasicCoordinateTransform;
import org.geotools.referencing.CRS; import org.osgeo.proj4j.CRSFactory;
import org.opengis.geometry.DirectPosition; import org.osgeo.proj4j.CoordinateReferenceSystem;
import org.opengis.geometry.MismatchedDimensionException; import org.osgeo.proj4j.ProjCoordinate;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.NoSuchAuthorityCodeException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.TransformException;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
...@@ -262,26 +257,13 @@ private void appendLayers(Document doc, Element layers, ...@@ -262,26 +257,13 @@ private void appendLayers(Document doc, Element layers,
* @param targetCRS The target SRS for the transformation. * @param targetCRS The target SRS for the transformation.
* @return The transformed target position within the target SRS. * @return The transformed target position within the target SRS.
*/ */
public static DirectPosition transformCoordinate(DirectPosition wgs84Position, public static ProjCoordinate transformCoordinate(ProjCoordinate wgs84Position,
CoordinateReferenceSystem targetCRS) { CoordinateReferenceSystem targetCRS) {
DirectPosition result = null; ProjCoordinate result = new ProjCoordinate();
try { CRSFactory f = new CRSFactory();
CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326"); // WGS 84 (used by Google Maps) CoordinateReferenceSystem sourceCRS = f.createFromName("EPSG:4326"); // WGS 84 (used by Google Maps / OpenStreetMap)
MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS, true); BasicCoordinateTransform transform = new BasicCoordinateTransform(sourceCRS, targetCRS);
result = transform.transform(wgs84Position, null); transform.transform(wgs84Position, result);
} catch (NoSuchAuthorityCodeException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
} catch (FactoryException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
} catch (MismatchedDimensionException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
} catch (TransformException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
return result; return result;
} }
...@@ -296,20 +278,15 @@ public static DirectPosition transformCoordinate(DirectPosition wgs84Position, ...@@ -296,20 +278,15 @@ public static DirectPosition transformCoordinate(DirectPosition wgs84Position,
private static Element appendRegionPolygon(Document doc, List<Coord> regionPolygon) { private static Element appendRegionPolygon(Document doc, List<Coord> regionPolygon) {
Element polygon = doc.createElement("polygon"); Element polygon = doc.createElement("polygon");
polygon.setAttribute("srs", "31467"); polygon.setAttribute("srs", "31467");
try { CRSFactory f = new CRSFactory();
CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:31467"); // DHDN Gauss-Kruger zone 3 CoordinateReferenceSystem targetCRS = f.createFromName("EPSG:31467"); // DHDN Gauss-Kruger zone 3
for (Coord coord : regionPolygon) { for (Coord coord : regionPolygon) {
DirectPosition sourcePosition = new GeneralDirectPosition(coord.latitude, coord.longitude); ProjCoordinate sourcePosition = new ProjCoordinate(coord.longitude, coord.latitude);
DirectPosition targetPosition = transformCoordinate(sourcePosition, targetCRS); ProjCoordinate targetPosition = transformCoordinate(sourcePosition, targetCRS);
Element vertex = doc.createElement("vertex");
Element vertex = doc.createElement("vertex"); vertex.setAttribute("x", String.valueOf(targetPosition.x));
vertex.setAttribute("x", String.valueOf(targetPosition.getCoordinate()[1])); vertex.setAttribute("y", String.valueOf(targetPosition.y));
vertex.setAttribute("y", String.valueOf(targetPosition.getCoordinate()[0])); polygon.appendChild(vertex);
polygon.appendChild(vertex);
}
} catch (FactoryException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
} }
return polygon; return polygon;
} }
...@@ -337,7 +314,8 @@ public File buildImportJobFile(ImportJobDescriptor jobDescriptor) { ...@@ -337,7 +314,8 @@ public File buildImportJobFile(ImportJobDescriptor jobDescriptor) {
File cityGMLFile = jobDescriptor.getCityGMLFile(); File cityGMLFile = jobDescriptor.getCityGMLFile();
writeBytesToZipFile(new FileInputStream(cityGMLFile), zos, jobDescriptor.getProduct() + "_" writeBytesToZipFile(new FileInputStream(cityGMLFile), zos, jobDescriptor.getProduct() + "_"
+ jobDescriptor.getLeaf() + "_" + jobDescriptor.getLeaf() + "_"
+ jobDescriptor.getLevel() + ".gml"); + jobDescriptor.getLevel() + "_"
+ jobDescriptor.getOperation() + ".gml");
writeBytesToZipFile(new FileInputStream(startfile), zos, startFilename); writeBytesToZipFile(new FileInputStream(startfile), zos, startFilename);
zos.close(); zos.close();
......
package eu.simstadt.nf; package eu.simstadt.nf4j;
/** /**
* Every instance of this class describes an export or import job for the novaFACTORY. Instances of JobBuilder * Every instance of this class describes an export or import job for the novaFACTORY. Instances of JobBuilder
......
package eu.simstadt.nf; package eu.simstadt.nf4j;
/** /**
* The list of all possible export and import job states. * The list of all possible export and import job states.
......
package eu.simstadt.nf; package eu.simstadt.nf4j;
/** /**
* A layer describes an aspect of a nF product and the type of its data. For instance, a layer could contain * A layer describes an aspect of a nF product and the type of its data. For instance, a layer could contain
......
package eu.simstadt.nf; package eu.simstadt.nf4j;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
NFConnector connector = new NFConnectorImpl("193.196.136.164"); NFConnector connector = new NFConnectorImpl("193.196.136.164");
Job job = connector.requestExportJob(566); ExportJob job = connector.requestExportJob(583);
System.out.println(job.getJobId() + ": " + job.getStatus() + " - " + job.getStatus().getMessage()); System.out.println(job.getJobId() + ": " + job.getStatus() + " - " + job.getStatus().getMessage());
connector.requestExportJobResult(583);
} }
} }
\ No newline at end of file
package eu.simstadt.nf; package eu.simstadt.nf4j;
import java.io.File; import java.io.File;
......
package eu.simstadt.nf; package eu.simstadt.nf4j;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
...@@ -133,7 +133,7 @@ public String supportsNFVersion() { ...@@ -133,7 +133,7 @@ public String supportsNFVersion() {
*/ */
@Override @Override
public ExportJob requestExportJob(int jobId) { public ExportJob requestExportJob(int jobId) {
ExportJob result = ExportJob.getUnkownInstance(); ExportJob result = ExportJob.getNewInstance();
try { try {
List<String> parameters = Arrays.asList(buildParameter("jobid", jobId)); List<String> parameters = Arrays.asList(buildParameter("jobid", jobId));
getJobFromResponse(result, getResponse(buildURL(REMOTE_STATUS_SERVLET, parameters))); getJobFromResponse(result, getResponse(buildURL(REMOTE_STATUS_SERVLET, parameters)));
...@@ -297,7 +297,7 @@ private void getJobFromResponse(Job job, String xml) ...@@ -297,7 +297,7 @@ private void getJobFromResponse(Job job, String xml)
parser.parse(new InputSource(reader), handler); parser.parse(new InputSource(reader), handler);
if (Objects.nonNull(handler.statusId)) { if (Objects.nonNull(handler.statusId)) {
job.setStatusForCode(handler.statusId); job.setStatusForCode(handler.statusId);
} }
if (Objects.nonNull(handler.serviceException)) { if (Objects.nonNull(handler.serviceException)) {
status.setMessage(handler.serviceException); status.setMessage(handler.serviceException);
} }
...@@ -354,7 +354,7 @@ private File downloadFile(URL url) throws IOException { ...@@ -354,7 +354,7 @@ private File downloadFile(URL url) throws IOException {
*/ */
@Override @Override
public ExportJob sendExportJobFile(File file) { public ExportJob sendExportJobFile(File file) {
ExportJob result = ExportJob.getUnkownInstance(); ExportJob result = ExportJob.getNewInstance();
try { try {
URL url = buildURL(REMOTE_ORDER_SERVLET, null); URL url = buildURL(REMOTE_ORDER_SERVLET, null);
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); HttpURLConnection connection = (HttpURLConnection) url.openConnection();
......
package eu.simstadt.nf; package eu.simstadt.nf4j;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
...@@ -49,7 +49,7 @@ public void startElement(String uri, String localName, String qName, Attributes ...@@ -49,7 +49,7 @@ public void startElement(String uri, String localName, String qName, Attributes
/** /**
* If a tag has been read, its contents will be tested here. If it contains either a status id, job id or * If a tag has been read, its contents will be tested here. If it contains either a status id, job id or
* service exception messege, then the contents will be stored in the appropriate member variable. * service exception message, then the contents will be stored in the appropriate member variable.
*/ */
@Override @Override
public void endElement(String uri, String localName, String qName) throws SAXException { public void endElement(String uri, String localName, String qName) throws SAXException {
......
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