Package org.opensextant.util
Class GeodeticUtility
java.lang.Object
org.opensextant.util.GeodeticUtility
A collection of geodetic routines used within OpenSextant. This is a light
wrapper around the most common routines - a full API exists in other APIs
such as GISCore, Geodesy, or Spatial4J
- Author:
- ubaldino
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final long
Precision -- this is a first draft attempt at assigning some error bars to geocoding results.static final int
static final int
-
Method Summary
Modifier and TypeMethodDescriptionstatic double
distanceDegrees
(double lat1, double lon1, double lat2, double lon2) This returns distance in degrees, e.g., this is a Cartesian distance.static double
distanceDegrees
(GeoBase p1, GeoBase p2) This returns distance in degrees, e.g., this is a Cartesian distance.static long
distanceMeters
(LatLon p1, LatLon p2) Haversine distance using LL1 to LL2;static String
formatLatLon
(LatLon yx) Create a string representation of a decimal lat/lon.static String
geohash
(double lat, double lon) static String
static int
getFeaturePrecision
(String feat_type, String feat_code) For a given feature type and code, determine what sort of resolution or precision should be considered for that place, approximately.static int
getGeohashPrecision
(String feat_type, String feat_code) For a given Geonames feature class/designation provide a guess about how long geohash should be.static boolean
isCoord
(double lat, double lon) static boolean
static boolean
static boolean
isValidNonZeroCoordinate
(double lat, double lon) A common check required by practical applications -- 0,0 is not interesting, so this is a simple java-based check.static boolean
isZeroCoord
(double lat, double lon) Just tests if location is not 0,0 ...static LatLon
parseLatLon
(Object lat, Object lon) Parse coordinate from objectstatic LatLon
parseLatLon
(String lat_lon) The most simplistic parsing and validation of "lat lon" or "lat, lon" any amount of whitespace is allowed, provided the lat lon order is there.static boolean
validateCoordinate
(double lat, double lon) TODO: consider using geodesy, however that API has no obvious simple validator.
-
Field Details
-
LAT_MAX
public static final int LAT_MAX- See Also:
-
LON_MAX
public static final int LON_MAX- See Also:
-
EARTH_RADIUS
public static final long EARTH_RADIUS- See Also:
-
FEATURE_PRECISION
Precision -- this is a first draft attempt at assigning some error bars to geocoding results. TODO: move this to a configuration file feat/code: prec # precision is meters of error for a given gazetteer entry with feat/code) A/ADM1: 50000 # ADM1 is generally +/- 50km, world wide P/PPL: 1000 # city is generally +/- 1km within center point P/PPLC: 10000 # major capital city is 10km of error, etc. -
FEATURE_GEOHASH_PRECISION
-
DEFAULT_PRECISION
public static final int DEFAULT_PRECISION- See Also:
-
DEFAULT_GEOHASH_PRECISION
public static final int DEFAULT_GEOHASH_PRECISION- See Also:
-
-
Method Details
-
validateCoordinate
public static boolean validateCoordinate(double lat, double lon) TODO: consider using geodesy, however that API has no obvious simple validator.- Parameters:
lat
- latitudelon
- longitude- Returns:
- if lat/lon is valid
-
isValidNonZeroCoordinate
public static boolean isValidNonZeroCoordinate(double lat, double lon) A common check required by practical applications -- 0,0 is not interesting, so this is a simple java-based check. double (and all number) values by default have a value = 0. This appears to be true for class attributes, but not for locals. Hence the NaN check in validateCoordinate.- Parameters:
lat
- in degreeslon
- in degress- Returns:
- true if coordinate is non-zero (0.000, 0.000) AND is valid abs(lon) < 180.0, etc.
-
isCoord
- Parameters:
xy
- a geocoding- Returns:
- true if geocoding has a non-zero coordinate
-
isZeroCoord
public static boolean isZeroCoord(double lat, double lon) Just tests if location is not 0,0 ... if provided as floating point objects Java has rounding error off in 0.0000001 place. Close enough to 0,0 counts as zero-coordinate.- Parameters:
lat
- latitudelon
- longitude- Returns:
- true if coordinate is set and is other than (0,0)
-
isCoord
public static boolean isCoord(double lat, double lon) -
isCoord
-
distanceDegrees
This returns distance in degrees, e.g., this is a Cartesian distance. Only to be used for fast comparison of two locations relatively close together, e.g., within the same 1 or 2 degrees of lat or lon. Beyond that there can be a lot of distortion in the physical distance.- Parameters:
p1
- pointp2
- point- Returns:
- distance between p1 and p2 in degrees.
-
distanceMeters
Haversine distance using LL1 to LL2;- Parameters:
p1
- geodesy API LatLonp2
- geodesy API LatLon- Returns:
- distance in meters.
-
distanceDegrees
public static double distanceDegrees(double lat1, double lon1, double lat2, double lon2) This returns distance in degrees, e.g., this is a Cartesian distance. Only to be used for fast comparison of two locations relatively close together, e.g., within the same 1 or 2 degrees of lat or lon. Beyond that there can be a lot of distortion in the physical distance.- Parameters:
lat1
- P1.latlon1
- P1.lonlat2
- P2.latlon2
- P2.lon- Returns:
- distance between p1 and p2 in degrees.
-
getFeaturePrecision
For a given feature type and code, determine what sort of resolution or precision should be considered for that place, approximately.- Parameters:
feat_type
- major feature typefeat_code
- minor feature type or designation- Returns:
- precision approx error in meters for a given feature. -1 if no feature type given.
-
getGeohashPrecision
For a given Geonames feature class/designation provide a guess about how long geohash should be. Geohash in this use is very approximate- Parameters:
feat_type
- major feature typefeat_code
- minor feature type or designation- Returns:
- prefix length for a geohash, e.g., for a province in general is 3 chars of geohash sufficient?
-
parseLatLon
The most simplistic parsing and validation of "lat lon" or "lat, lon" any amount of whitespace is allowed, provided the lat lon order is there.- Parameters:
lat_lon
- string form of a simple lat/lon, e.g., "Y X"; No symbols- Returns:
- LatLon object
- Throws:
ParseException
- if string is unparsable
-
parseLatLon
Parse coordinate from object- Parameters:
lat
- latitudelon
- longitude- Returns:
- LatLon object
- Throws:
ParseException
- if objects are not valid numbers
-
formatLatLon
Create a string representation of a decimal lat/lon.- Parameters:
yx
- LatLon object- Returns:
- "lat, lon" formatted with 4 decimal places; that is an average amount of precision for common XY=> String uses.
-
geohash
- Parameters:
yx
- lat,lon obj- Returns:
- geohash representation of the lat,lon
-
geohash
-