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
*/
......
package eu.simstadt.nf;
package eu.simstadt.nf4j;
import java.util.Objects;
......@@ -14,7 +14,7 @@ public class ExportJob extends Job {
*
* @return Returns a new export job instance with unknown state.
*/
public static ExportJob getUnkownInstance() {
public static ExportJob getNewInstance() {
return new ExportJob(JobStatus.UNKOWN);
}
......
package eu.simstadt.nf;
package eu.simstadt.nf4j;
import java.util.ArrayList;
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.
......
package eu.simstadt.nf;
package eu.simstadt.nf4j;
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.
......
package eu.simstadt.nf;
package eu.simstadt.nf4j;
import java.io.File;
......
package eu.simstadt.nf;
package eu.simstadt.nf4j;
import java.io.File;
import java.io.FileInputStream;
......@@ -23,15 +23,10 @@
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.geotools.geometry.GeneralDirectPosition;
import org.geotools.referencing.CRS;
import org.opengis.geometry.DirectPosition;
import org.opengis.geometry.MismatchedDimensionException;
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.osgeo.proj4j.BasicCoordinateTransform;
import org.osgeo.proj4j.CRSFactory;
import org.osgeo.proj4j.CoordinateReferenceSystem;
import org.osgeo.proj4j.ProjCoordinate;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
......@@ -262,26 +257,13 @@ private void appendLayers(Document doc, Element layers,
* @param targetCRS The target SRS for the transformation.
* @return The transformed target position within the target SRS.
*/
public static DirectPosition transformCoordinate(DirectPosition wgs84Position,
public static ProjCoordinate transformCoordinate(ProjCoordinate wgs84Position,
CoordinateReferenceSystem targetCRS) {
DirectPosition result = null;
try {
CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326"); // WGS 84 (used by Google Maps)
MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS, true);
result = transform.transform(wgs84Position, null);
} 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();
}
ProjCoordinate result = new ProjCoordinate();
CRSFactory f = new CRSFactory();
CoordinateReferenceSystem sourceCRS = f.createFromName("EPSG:4326"); // WGS 84 (used by Google Maps / OpenStreetMap)
BasicCoordinateTransform transform = new BasicCoordinateTransform(sourceCRS, targetCRS);
transform.transform(wgs84Position, result);
return result;
}
......@@ -296,20 +278,15 @@ public static DirectPosition transformCoordinate(DirectPosition wgs84Position,
private static Element appendRegionPolygon(Document doc, List<Coord> regionPolygon) {
Element polygon = doc.createElement("polygon");
polygon.setAttribute("srs", "31467");
try {
CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:31467"); // DHDN Gauss-Kruger zone 3
for (Coord coord : regionPolygon) {
DirectPosition sourcePosition = new GeneralDirectPosition(coord.latitude, coord.longitude);
DirectPosition targetPosition = transformCoordinate(sourcePosition, targetCRS);
Element vertex = doc.createElement("vertex");
vertex.setAttribute("x", String.valueOf(targetPosition.getCoordinate()[1]));
vertex.setAttribute("y", String.valueOf(targetPosition.getCoordinate()[0]));
polygon.appendChild(vertex);
}
} catch (FactoryException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
CRSFactory f = new CRSFactory();
CoordinateReferenceSystem targetCRS = f.createFromName("EPSG:31467"); // DHDN Gauss-Kruger zone 3
for (Coord coord : regionPolygon) {
ProjCoordinate sourcePosition = new ProjCoordinate(coord.longitude, coord.latitude);
ProjCoordinate targetPosition = transformCoordinate(sourcePosition, targetCRS);
Element vertex = doc.createElement("vertex");
vertex.setAttribute("x", String.valueOf(targetPosition.x));
vertex.setAttribute("y", String.valueOf(targetPosition.y));
polygon.appendChild(vertex);
}
return polygon;
}
......@@ -337,7 +314,8 @@ public File buildImportJobFile(ImportJobDescriptor jobDescriptor) {
File cityGMLFile = jobDescriptor.getCityGMLFile();
writeBytesToZipFile(new FileInputStream(cityGMLFile), zos, jobDescriptor.getProduct() + "_"
+ jobDescriptor.getLeaf() + "_"
+ jobDescriptor.getLevel() + ".gml");
+ jobDescriptor.getLevel() + "_"
+ jobDescriptor.getOperation() + ".gml");
writeBytesToZipFile(new FileInputStream(startfile), zos, startFilename);
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
......
package eu.simstadt.nf;
package eu.simstadt.nf4j;
/**
* 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
......
package eu.simstadt.nf;
package eu.simstadt.nf4j;
public class Main {
public static void main(String[] args) {
public static void main(String[] args) {
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());
connector.requestExportJobResult(583);
}
}
\ No newline at end of file
package eu.simstadt.nf;
package eu.simstadt.nf4j;
import java.io.File;
......
package eu.simstadt.nf;
package eu.simstadt.nf4j;
import java.io.BufferedReader;
import java.io.File;
......@@ -133,7 +133,7 @@ public String supportsNFVersion() {
*/
@Override
public ExportJob requestExportJob(int jobId) {
ExportJob result = ExportJob.getUnkownInstance();
ExportJob result = ExportJob.getNewInstance();
try {
List<String> parameters = Arrays.asList(buildParameter("jobid", jobId));
getJobFromResponse(result, getResponse(buildURL(REMOTE_STATUS_SERVLET, parameters)));
......@@ -297,7 +297,7 @@ private void getJobFromResponse(Job job, String xml)
parser.parse(new InputSource(reader), handler);
if (Objects.nonNull(handler.statusId)) {
job.setStatusForCode(handler.statusId);
}
}
if (Objects.nonNull(handler.serviceException)) {
status.setMessage(handler.serviceException);
}
......@@ -354,7 +354,7 @@ private File downloadFile(URL url) throws IOException {
*/
@Override
public ExportJob sendExportJobFile(File file) {
ExportJob result = ExportJob.getUnkownInstance();
ExportJob result = ExportJob.getNewInstance();
try {
URL url = buildURL(REMOTE_ORDER_SERVLET, null);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
......
package eu.simstadt.nf;
package eu.simstadt.nf4j;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
......@@ -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
* 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
public void endElement(String uri, String localName, String qName) throws SAXException {
......
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