Commit 0e4e2b7d authored by Matija Obreza's avatar Matija Obreza
Browse files

Javadoc

parent 861f39a2
...@@ -27,11 +27,16 @@ import org.slf4j.Logger; ...@@ -27,11 +27,16 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* This is the default entry point for the -jar execution * This is the default entry point for the -jar execution.
*/ */
public class CLI { public class CLI {
/** The LOG. */
private final static Logger LOG = LoggerFactory.getLogger(CLI.class); private final static Logger LOG = LoggerFactory.getLogger(CLI.class);
/**
* Prints the help.
*/
private static void printHelp() { private static void printHelp() {
System.out.println("Usage: java -jar geo-tools.jar country|landorsea [options] <inputFile> <outputFile>"); System.out.println("Usage: java -jar geo-tools.jar country|landorsea [options] <inputFile> <outputFile>");
System.out.println("\nOptions:"); System.out.println("\nOptions:");
...@@ -43,6 +48,11 @@ public class CLI { ...@@ -43,6 +48,11 @@ public class CLI {
System.out.println("\nThe program writes log messages to STDERR."); System.out.println("\nThe program writes log messages to STDERR.");
} }
/**
* The main method.
*
* @param args the arguments
*/
public static void main(String[] args) { public static void main(String[] args) {
String sourceName = null; String sourceName = null;
String outputName = null; String outputName = null;
...@@ -138,6 +148,12 @@ public class CLI { ...@@ -138,6 +148,12 @@ public class CLI {
} }
} }
/**
* Get the next LOG level.
*
* @param level the level
* @return the level
*/
private static Level nextLevel(Level level) { private static Level nextLevel(Level level) {
if (level.equals(Level.FATAL)) { if (level.equals(Level.FATAL)) {
return Level.ERROR; return Level.ERROR;
......
...@@ -21,7 +21,17 @@ import java.io.InputStreamReader; ...@@ -21,7 +21,17 @@ import java.io.InputStreamReader;
import com.opencsv.CSVReader; import com.opencsv.CSVReader;
/**
* Generate a KML/KMZ file from CSV data.
*/
public class CSV2KML { public class CSV2KML {
/**
* The main method.
*
* @param args the arguments
* @throws IOException Signals that an I/O exception has occurred.
*/
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
int columnGenesysId = 0; int columnGenesysId = 0;
int columnAcceNumb = 1; int columnAcceNumb = 1;
......
...@@ -19,11 +19,14 @@ import java.io.IOException; ...@@ -19,11 +19,14 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
/**
* GeoTool interface for CLI programs.
*/
public interface GeoTool { public interface GeoTool {
/** /**
* Execute the tool * Execute the tool.
* *
* @param inputStream CSV input stream * @param inputStream CSV input stream
* @param outputStream output stream for resulting CSV * @param outputStream output stream for resulting CSV
* @param separatorChar separator char (,) * @param separatorChar separator char (,)
......
...@@ -39,15 +39,33 @@ import org.slf4j.LoggerFactory; ...@@ -39,15 +39,33 @@ import org.slf4j.LoggerFactory;
import com.opencsv.CSVReader; import com.opencsv.CSVReader;
import com.opencsv.CSVWriter; import com.opencsv.CSVWriter;
/**
* The Class LandOrSeaCLI.
*/
public class LandOrSeaCLI implements GeoTool { public class LandOrSeaCLI implements GeoTool {
/** The Constant LOG. */
private final static Logger LOG = LoggerFactory.getLogger(LandOrSeaCLI.class); private final static Logger LOG = LoggerFactory.getLogger(LandOrSeaCLI.class);
/** The Constant ALLOWED_DISTANCE_MARGIN. */
// 2000 meters // 2000 meters
private static final int ALLOWED_DISTANCE_MARGIN = 2000; private static final int ALLOWED_DISTANCE_MARGIN = 2000;
/** The Constant HEADER_LATITUDE. */
private static final String HEADER_LATITUDE = "DECLATITUDE"; private static final String HEADER_LATITUDE = "DECLATITUDE";
/** The Constant HEADER_LONGITUDE. */
private static final String HEADER_LONGITUDE = "DECLONGITUDE"; private static final String HEADER_LONGITUDE = "DECLONGITUDE";
/** The Constant HEADER_LANDORSEA_CHECK. */
private static final String HEADER_LANDORSEA_CHECK = "LANDorSEA_check"; private static final String HEADER_LANDORSEA_CHECK = "LANDorSEA_check";
/**
* The main method.
*
* @param arg the arguments
* @throws Exception the exception
*/
public static void main(String arg[]) throws Exception { public static void main(String arg[]) throws Exception {
if (arg.length == 0) { if (arg.length == 0) {
...@@ -84,6 +102,9 @@ public class LandOrSeaCLI implements GeoTool { ...@@ -84,6 +102,9 @@ public class LandOrSeaCLI implements GeoTool {
} }
} }
/* (non-Javadoc)
* @see org.genesys.geotools.cli.GeoTool#execute(java.io.InputStream, java.io.OutputStream, char, char, char)
*/
public void execute(InputStream input, OutputStream output, char separatorChar, char quoteChar, char escapeChar) throws IOException { public void execute(InputStream input, OutputStream output, char separatorChar, char quoteChar, char escapeChar) throws IOException {
try (CSVReader reader = new CSVReader(new BufferedReader(new InputStreamReader(input), 10000), separatorChar, quoteChar, escapeChar, 0, false)) { try (CSVReader reader = new CSVReader(new BufferedReader(new InputStreamReader(input), 10000), separatorChar, quoteChar, escapeChar, 0, false)) {
......
...@@ -16,8 +16,21 @@ ...@@ -16,8 +16,21 @@
package org.genesys.geotools.service; package org.genesys.geotools.service;
/**
* The Interface CountryOfOriginService.
*/
public interface CountryOfOriginService { public interface CountryOfOriginService {
/**
* Gets the countries.
*
* @param longitude the longitude
* @param latitude the latitude
* @param origCty the orig cty
* @param allowedDistanceMargin the allowed distance margin
* @return the countries
* @throws Exception the exception
*/
String getCountries(float longitude, float latitude, String origCty, int allowedDistanceMargin) throws Exception; String getCountries(float longitude, float latitude, String origCty, int allowedDistanceMargin) throws Exception;
} }
...@@ -27,14 +27,16 @@ import org.slf4j.Logger; ...@@ -27,14 +27,16 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* Helper for CSV header management * Helper for CSV header management.
*/ */
public abstract class HeaderUtils { public abstract class HeaderUtils {
/** The Constant LOG. */
private final static Logger LOG = LoggerFactory.getLogger(HeaderUtils.class); private final static Logger LOG = LoggerFactory.getLogger(HeaderUtils.class);
/** /**
* Check for invalid headers and throw IOException if one is found * Check for invalid headers and throw IOException if one is found.
* *
* @param headers input headers * @param headers input headers
* @param notAllowedHeaders array of unacceptable headers * @param notAllowedHeaders array of unacceptable headers
* @throws IOException when one unacceptable header is found * @throws IOException when one unacceptable header is found
...@@ -49,10 +51,10 @@ public abstract class HeaderUtils { ...@@ -49,10 +51,10 @@ public abstract class HeaderUtils {
} }
/** /**
* Check for required headers and throw IOException if one is missing * Check for required headers and throw IOException if one is missing.
* *
* @param headers input headers * @param headers input headers
* @param notAllowedHeaders array of unacceptable headers * @param requiredHeaders the array of required headers
* @throws IOException when one unacceptable header is found * @throws IOException when one unacceptable header is found
*/ */
public static void throwIfHeaderNotFound(final String[] headers, final String[] requiredHeaders) throws IOException { public static void throwIfHeaderNotFound(final String[] headers, final String[] requiredHeaders) throws IOException {
...@@ -65,10 +67,10 @@ public abstract class HeaderUtils { ...@@ -65,10 +67,10 @@ public abstract class HeaderUtils {
} }
/** /**
* Map CSV headers to their positions * Map CSV headers to their positions.
* *
* @param headers CSV header list * @param headers CSV header list
* @return a new List<Integer> with header indexes * @return a new List with header indexes
*/ */
public static List<Integer> mapHeaderPositions(final String[] headers) { public static List<Integer> mapHeaderPositions(final String[] headers) {
List<Integer> outputMapping = new ArrayList<>(); List<Integer> outputMapping = new ArrayList<>();
...@@ -82,7 +84,8 @@ public abstract class HeaderUtils { ...@@ -82,7 +84,8 @@ public abstract class HeaderUtils {
/** /**
* We are mostly interested in only a few supported headers. Get their indexes. * We are mostly interested in only a few supported headers. Get their indexes.
* *
* @param headers the headers
* @param supportedHeaders Array of supported headers * @param supportedHeaders Array of supported headers
* @return Map of positions of supported headers * @return Map of positions of supported headers
*/ */
...@@ -104,8 +107,8 @@ public abstract class HeaderUtils { ...@@ -104,8 +107,8 @@ public abstract class HeaderUtils {
} }
/** /**
* Copy data from input CSV line to output CSV line with appropriate destination mapping * Copy data from input CSV line to output CSV line with appropriate destination mapping.
* *
* @param nextLine source line * @param nextLine source line
* @param outputHeaders output headers * @param outputHeaders output headers
* @param outputMapping mapping of output columns * @param outputMapping mapping of output columns
......
...@@ -16,8 +16,20 @@ ...@@ -16,8 +16,20 @@
package org.genesys.geotools.service; package org.genesys.geotools.service;
/**
* The Interface LandOrSeaService.
*/
public interface LandOrSeaService { public interface LandOrSeaService {
/**
* Checks if is on land.
*
* @param longitude the longitude
* @param latitude the latitude
* @param allowedDistanceFromLand the allowed distance from land
* @return the boolean
* @throws Exception the exception
*/
public Boolean isOnLand(float longitude, float latitude, int allowedDistanceFromLand) throws Exception; public Boolean isOnLand(float longitude, float latitude, int allowedDistanceFromLand) throws Exception;
} }
...@@ -18,20 +18,47 @@ package org.genesys.geotools.service; ...@@ -18,20 +18,47 @@ package org.genesys.geotools.service;
import java.io.Serializable; import java.io.Serializable;
/**
* LonLatCacheKey is used as caching key.
*/
public class LonLatCacheKey implements Serializable { public class LonLatCacheKey implements Serializable {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -3626533849742141104L; private static final long serialVersionUID = -3626533849742141104L;
/** The longitude. */
private float longitude; private float longitude;
/** The latitude. */
private float latitude; private float latitude;
/** The orig cty. */
private String origCty; private String origCty;
/** The allowed distance margin. */
private int allowedDistanceMargin; private int allowedDistanceMargin;
/**
* Instantiates a new lon lat cache key.
*
* @param longitude the longitude
* @param latitude the latitude
* @param allowedDistanceMargin the allowed distance margin
*/
public LonLatCacheKey(float longitude, float latitude, int allowedDistanceMargin) { public LonLatCacheKey(float longitude, float latitude, int allowedDistanceMargin) {
this.longitude = longitude; this.longitude = longitude;
this.latitude = latitude; this.latitude = latitude;
this.allowedDistanceMargin = allowedDistanceMargin; this.allowedDistanceMargin = allowedDistanceMargin;
} }
/**
* Instantiates a new lon lat cache key.
*
* @param longitude the longitude
* @param latitude the latitude
* @param origCty the orig cty
* @param allowedDistanceMargin the allowed distance margin
*/
public LonLatCacheKey(float longitude, float latitude, String origCty, int allowedDistanceMargin) { public LonLatCacheKey(float longitude, float latitude, String origCty, int allowedDistanceMargin) {
this.longitude = longitude; this.longitude = longitude;
this.latitude = latitude; this.latitude = latitude;
...@@ -39,6 +66,9 @@ public class LonLatCacheKey implements Serializable { ...@@ -39,6 +66,9 @@ public class LonLatCacheKey implements Serializable {
this.allowedDistanceMargin = allowedDistanceMargin; this.allowedDistanceMargin = allowedDistanceMargin;
} }
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
...@@ -50,6 +80,9 @@ public class LonLatCacheKey implements Serializable { ...@@ -50,6 +80,9 @@ public class LonLatCacheKey implements Serializable {
return result; return result;
} }
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj)
...@@ -73,18 +106,38 @@ public class LonLatCacheKey implements Serializable { ...@@ -73,18 +106,38 @@ public class LonLatCacheKey implements Serializable {
return true; return true;
} }
/**
* Gets the longitude.
*
* @return the longitude
*/
public float getLongitude() { public float getLongitude() {
return longitude; return longitude;
} }
/**
* Gets the latitude.
*
* @return the latitude
*/
public float getLatitude() { public float getLatitude() {
return latitude; return latitude;
} }
/**
* Gets the allowed distance margin.
*
* @return the allowed distance margin
*/
public int getAllowedDistanceMargin() { public int getAllowedDistanceMargin() {
return allowedDistanceMargin; return allowedDistanceMargin;
} }
/**
* Gets the orig cty.
*
* @return the orig cty
*/
public String getOrigCty() { public String getOrigCty() {
return origCty; return origCty;
} }
......
...@@ -37,10 +37,25 @@ import com.vividsolutions.jts.geom.Geometry; ...@@ -37,10 +37,25 @@ import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Polygon; import com.vividsolutions.jts.geom.Polygon;
/**
* The Class ShapefileUtils.
*/
public class ShapefileUtils { public class ShapefileUtils {
/** The Constant RING_POINTS. */
private static final int RING_POINTS = 12; private static final int RING_POINTS = 12;
/** The Constant geometryFactory. */
private static final GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null); private static final GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);
/**
* Open shape file.
*
* @param shapeFilePath the shape file path
* @return the data store
* @throws MalformedURLException the malformed url exception
* @throws IOException Signals that an I/O exception has occurred.
*/
public static DataStore openShapeFile(String shapeFilePath) throws MalformedURLException, IOException { public static DataStore openShapeFile(String shapeFilePath) throws MalformedURLException, IOException {
File file = new File("data", shapeFilePath); File file = new File("data", shapeFilePath);
...@@ -55,14 +70,14 @@ public class ShapefileUtils { ...@@ -55,14 +70,14 @@ public class ShapefileUtils {
/** /**
* Uses ideas from * Uses ideas from
* https://geoaware.wordpress.com/2013/10/16/geodetic-buffers-with-geotools/ * https://geoaware.wordpress.com/2013/10/16/geodetic-buffers-with-geotools/
* *
* @param longitude * @param longitude the longitude
* @param latitude * @param latitude the latitude
* @param distanceMeters * @param distanceMeters the distance meters
* @return * @return the point buffer
* @throws MismatchedDimensionException * @throws MismatchedDimensionException the mismatched dimension exception
* @throws TransformException * @throws TransformException the transform exception
* @throws FactoryException * @throws FactoryException the factory exception
*/ */
public static Geometry getPointBuffer(double longitude, double latitude, double distanceMeters) public static Geometry getPointBuffer(double longitude, double latitude, double distanceMeters)
throws MismatchedDimensionException, TransformException, FactoryException { throws MismatchedDimensionException, TransformException, FactoryException {
......
...@@ -37,6 +37,8 @@ import org.opengis.feature.simple.SimpleFeature; ...@@ -37,6 +37,8 @@ import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType; import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.filter.Filter; import org.opengis.filter.Filter;
import org.opengis.filter.FilterFactory2; import org.opengis.filter.FilterFactory2;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
...@@ -47,16 +49,29 @@ import com.vividsolutions.jts.geom.GeometryFactory; ...@@ -47,16 +49,29 @@ import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point; import com.vividsolutions.jts.geom.Point;
/** /**
* Polygons used here are derived from OSM data, © OpenStreetMap contributors * Polygons used here are derived from OSM data, © OpenStreetMap contributors.
*/ */
public class CountryOfOriginServiceImpl implements CountryOfOriginService { public class CountryOfOriginServiceImpl implements CountryOfOriginService {
/** LOG */
private final static Logger LOG = LoggerFactory.getLogger(CountryOfOriginServiceImpl.class);
/** The Constant ff. */
private static final FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(); private static final FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
/** The Constant geometryFactory. */
private static final GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); private static final GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
/** The source admin0. */
private FeatureSource<SimpleFeatureType, SimpleFeature> sourceAdmin0; private FeatureSource<SimpleFeatureType, SimpleFeature> sourceAdmin0;
/** The source admin0 x. */
private FeatureSource<SimpleFeatureType, SimpleFeature> sourceAdmin0X; private FeatureSource<SimpleFeatureType, SimpleFeature> sourceAdmin0X;
/** The country cache. */
private LoadingCache<LonLatCacheKey, String> countryCache; private LoadingCache<LonLatCacheKey, String> countryCache;
/** The debug. */
private boolean debug = false; private boolean debug = false;
static { static {
...@@ -69,6 +84,12 @@ public class CountryOfOriginServiceImpl implements CountryOfOriginService { ...@@ -69,6 +84,12 @@ public class CountryOfOriginServiceImpl implements CountryOfOriginService {
} }
} }
/**
* After properties set.
*
* @throws MalformedURLException the malformed url exception
* @throws IOException Signals that an I/O exception has occurred.
*/
public void afterPropertiesSet() throws MalformedURLException, IOException { public void afterPropertiesSet() throws MalformedURLException, IOException {
// http://www.gadm.org/version2 // http://www.gadm.org/version2
// Use "six dissolved layers" // Use "six dissolved layers"
...@@ -78,15 +99,13 @@ public class CountryOfOriginServiceImpl implements CountryOfOriginService { ...