001package org.gbif.api.util;
002
003/**
004 *
005 */
006public class LengthUtils {
007  public static final int LAT_DEGREE_IN_METER = 110580;
008
009  /**
010   * Latitude degrees are roughly linear to meters on the earth spheroid.
011   * Just the longitudinal degree changes considerably with distance to the equator
012   * See https://en.wikipedia.org/wiki/Geographic_coordinate_system#Expressing_latitude_and_longitude_as_linear_units
013   *
014   * @return the decimal latitudinal degree equivalent to the given length in meters
015   */
016  public static double metersToLatDegree(double meter) {
017    // http://gis.stackexchange.com/questions/14449/java-vividsolutions-jts-wgs-84-distance-to-meters
018    return Math.round(meter/ LAT_DEGREE_IN_METER * 1000000.0) / 1000000.0;
019  }
020
021  /**
022   * Latitude degrees are roughly linear to meters on the earth spheroid.
023   * Just the longitudinal degree changes considerably with distance to the equator
024   * See https://en.wikipedia.org/wiki/Geographic_coordinate_system#Expressing_latitude_and_longitude_as_linear_units
025   *
026   * @return the length in meters equivalent to the given decimal latitudinal degree
027   */
028  public static double latDegreeToMeters(double latDegrees) {
029    // http://gis.stackexchange.com/questions/14449/java-vividsolutions-jts-wgs-84-distance-to-meters
030    return Math.round(latDegrees * LAT_DEGREE_IN_METER * 100.0) / 100.0;
031  }
032
033}