Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
*
*/
package eu.europa.ec.eurostat.searoute;
import java.io.File;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Map;
import java.util.Set;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import eu.europa.ec.eurostat.jgiscotools.feature.Feature;
import eu.europa.ec.eurostat.jgiscotools.feature.util.Util;
import eu.europa.ec.eurostat.jgiscotools.io.geo.GeoData;
/**
* Main method for executable program.
* Apply to csv file.
*
* @author julien Gaffuri
*
*/
public class SeaRouteJarMain {
public static void main(String[] args) {
Options options = new Options();
options.addOption(Option.builder("i").longOpt("inputFile").desc("Input file (CSV format).")
.hasArg().argName("file").build());
options.addOption(Option.builder("o").longOpt("outputFile").desc("Optional. Output file (GeoJSON format). Default: 'out.geojson'.")
.hasArg().argName("file").build());
options.addOption(Option.builder("res").longOpt("resolution").desc("Optional. The resolution of the output geometries, in km. Default: '20'.")
.hasArg().argName("5, 10, 20, 50 or 100").build());
options.addOption(Option.builder("olonCol").desc("Optional. The name of the column in the input file where the origin longitude is specified. Default: 'olon'.")
.hasArg().argName("Column name").build());
options.addOption(Option.builder("olatCol").desc("Optional. The name of the column in the input file where the origin latitude is specified. Default: 'olat'.")
.hasArg().argName("Column name").build());
options.addOption(Option.builder("dlonCol").desc("Optional. The name of the column in the input file where the destination longitude is specified. Default: 'dlon'.")
.hasArg().argName("Column name").build());
options.addOption(Option.builder("dlatCol").desc("Optional. The name of the column in the input file where the destination latitude is specified. Default: 'dlat'.")
.hasArg().argName("Column name").build());
options.addOption(Option.builder("suez").desc("Optional. Set to '1' to allow trips using Suez channel. Default: '1'.")
.hasArg().argName("0 or 1").build());
options.addOption(Option.builder("panama").desc("Optional. Set to '1' to allow trips using Panama channel. Default: '1'.")
.hasArg().argName("0 or 1").build());
options.addOption(Option.builder("h").desc("Show this help message").build());
CommandLine cmd = null;
try { cmd = new DefaultParser().parse( options, args); } catch (ParseException e) {
System.err.println( "Parsing failed. Reason: " + e.getMessage() );
return;
}
//help statement
if(cmd.hasOption("h")) {
new HelpFormatter().printHelp("java -jar searoute.jar", options);
return;
}
//read parameters
//input file
String inFile = cmd.getOptionValue("i");
if(inFile==null) {
System.err.println("An input file should be specified with -i option. Use -h option to show the help message.");
return;
} else if(!new File(inFile).exists()) {
System.err.println("Input file does not exist: " + inFile);
return;
}
//output file
String outFile = cmd.getOptionValue("o");
if(outFile == null) outFile = Paths.get("").toAbsolutePath().toString() + "/out.geojson";
//resolution
String resP = cmd.getOptionValue("res"); if(resP == null) resP = "20";
int res = 20;
try {
res = Integer.parseInt(resP);
} catch (NumberFormatException e) {
System.out.println("Could not handle resolution: " + resP);
res = 20;
}
//column names
String olonCol = cmd.getOptionValue("olonCol"); if(olonCol == null) olonCol = "olon";
String olatCol = cmd.getOptionValue("olatCol"); if(olatCol == null) olatCol = "olat";
String dlonCol = cmd.getOptionValue("dlonCol"); if(dlonCol == null) dlonCol = "dlon";
String dlatCol = cmd.getOptionValue("dlatCol"); if(dlatCol == null) dlatCol = "dlat";
//channels
String suez = cmd.getOptionValue("suez"); if(suez == null) suez = "1";
String panama = cmd.getOptionValue("panama"); if(panama == null) panama = "1";
//load data
ArrayList