Files
maptology/service-tool/src/main/java/com/maptology/tool/ToolUtilities.java
T
Marcus Handte ac06575858
LocationBasedServices/maptology/master This commit looks good
Added simple analysis tools.
2019-12-05 21:16:48 +01:00

73 lines
2.3 KiB
Java

package com.maptology.tool;
import org.jboss.resteasy.client.jaxrs.BasicAuthentication;
import org.jboss.resteasy.client.jaxrs.ResteasyClient;
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
import org.jboss.resteasy.client.jaxrs.engines.URLConnectionEngine;
/**
* The tool configuration and utilities.
*
* @author Marcus
*/
public class ToolUtilities {
/**
* The url of the maptology api.
*/
public static String API_URL = "https://www.maptology.com/api";
/**
* The devices
*/
public static long[] DEVICES = new long[] { 361281 };
/**
* The output folder to write data.
*/
public static String OUTPUT_FOLDER = "temp";
/**
* The earth's radius in meters.
*/
public static final int EARTH_RADIUS = 6371000;
/**
* Returns a proxy for the service with the specified login data.
*
* @param <T> The type of the service.
* @param service The class representing the service interface.
* @param username The user name.
* @param password The user password.
* @return The proxy for the service.
*/
public static <T> T getProxy(Class<T> service, String username, String password) {
ResteasyClientBuilder builder = new ResteasyClientBuilder();
builder.httpEngine(new URLConnectionEngine());
ResteasyClient client = builder.build();
return client.register(new BasicAuthentication(username, password)).target(API_URL).proxy(service);
}
/**
* Returns the distance in meters between the two wgs coordinates specified by
* alon, alat and blon, blat.
*
* @param alon The longitude of the first point.
* @param alat The latitude of the first point.
* @param blon The longitude of the second point.
* @param blat The latitude of the second point.
* @return The distance in meters.
*/
public static double getDistance(double alon, double alat, double blon, double blat) {
double dlong = Math.toRadians(blon - alon);
double dlat = Math.toRadians(blat - alat);
double ax = Math.pow(Math.sin(dlat / 2.0), 2) + Math.cos(Math.toRadians(alat)) * Math.cos(Math.toRadians(blat))
* Math.pow(Math.sin(dlong / 2.0), 2);
double c = 2 * Math.atan2(Math.sqrt(ax), Math.sqrt(1 - ax));
return EARTH_RADIUS * c;
}
}