Package jsl.modeling.elements.spatial
Class GreatCircleBasedSpatialModel
- java.lang.Object
-
- jsl.modeling.elements.spatial.SpatialModel
-
- jsl.modeling.elements.spatial.GreatCircleBasedSpatialModel
-
- All Implemented Interfaces:
ObservableIfc
,GetNameIfc
,IdentityIfc
public class GreatCircleBasedSpatialModel extends SpatialModel
This class represents the distance between two coordinates using the Great Circle Distance. (http://en.wikipedia.org/wiki/Great_circle_distance) Distance is assumed to be in kilometers Coordinates are assumed to be given as: X1 - latitude, in degrees, [-90,90] X2 - longitude, in degrees [-180,180] X3 - not used By convention North is considered positive latitude By convention West is considered negative longitude
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
GreatCircleBasedSpatialModel.Direction
Defines the directions on a compass
-
Field Summary
Fields Modifier and Type Field Description protected static double
DEFAULT_EARTH_RADIUS
The default radius for the earth, @see (http://en.wikipedia.org/wiki/Great_circle_distance)protected double
myCircuityFactor
Can be set to adjust computed great circle distance to account for the circuity of the road/rail network, by default 1.0protected double
myEarthRadius
Holds teh radius of the earth for calculating great circle distancestatic double
RAIL
The ciruity addFactor for rail networks, see pg 559 of Balloustatic double
ROADS
The ciruity addFactor for road networks, see pg 559 of Ballou-
Fields inherited from class jsl.modeling.elements.spatial.SpatialModel
ADDED_ELEMENT, myDefaultPositionPrecision, myElements, REMOVED_ELEMENT, UPDATED_POSITION
-
-
Constructor Summary
Constructors Constructor Description GreatCircleBasedSpatialModel()
Creates a spatial model that uses the great circle distance as the basis for computing distance between two coordinates.GreatCircleBasedSpatialModel(java.lang.String name)
Creates a spatial model that uses the great circle distance as the basis for computing distance between two coordinates.GreatCircleBasedSpatialModel(java.lang.String name, double circuityFactor)
Creates a spatial model that uses the great circle distance as the basis for computing distance between two coordinates.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
comparePositions(CoordinateIfc coordinate1, CoordinateIfc coordinate2)
Returns true if the first coordinate is the same as second coordinate within the underlying spatial model.double
distance(CoordinateIfc fromCoordinate, CoordinateIfc toCoordinate)
Computes the distance between the two supplied coordinatesdouble
getCircuityFactor()
The network circuity addFactor for adjusting the distance.CoordinateIfc
getCoordinate(double lat, double lon, double x3)
Returns a valid coordinatestatic CoordinateIfc
getCoordinate(GreatCircleBasedSpatialModel.Direction latD, double latd, double latm, double lats, GreatCircleBasedSpatialModel.Direction lonD, double lond, double lonm, double lons)
Returns a valid coordinatestatic CoordinateIfc
getCoordinate(GreatCircleBasedSpatialModel.Direction latD, double latd, double latm, GreatCircleBasedSpatialModel.Direction lonD, double lond, double lonm)
Returns a valid coordinateCoordinateIfc
getDefaultCoordinate()
Returns a default set of coordinates to be used to initialize the location of spatial elements if necessary.static double
getDirectionSign(GreatCircleBasedSpatialModel.Direction d)
Gets the sign associated with the supplied directiondouble
getEarthRadius()
The earth's radius for great circle calculationstatic double
getLatitude(GreatCircleBasedSpatialModel.Direction direction, double degrees, double minutes)
Returns a latitude in degreesstatic double
getLatitude(GreatCircleBasedSpatialModel.Direction direction, double degrees, double minutes, double seconds)
Returns a latitude in degreesstatic double
getLongitude(GreatCircleBasedSpatialModel.Direction direction, double degrees, double minutes)
Returns a longitude in degreesstatic double
getLongitude(GreatCircleBasedSpatialModel.Direction direction, double degrees, double minutes, double seconds)
Returns a longitude in degreesboolean
isValid(CoordinateIfc coordinate)
Checks to see if the supplied coordinate is physically valid within the spatial model.static void
main(java.lang.String[] args)
protected void
setCircuityFactor(double circuityFactor)
void
setEarthRadius(double radius)
The earth's radius for great circle calculation-
Methods inherited from class jsl.modeling.elements.spatial.SpatialModel
addObserver, addSpatialElement, checkForSpatialElementRemoved, checkSpatialElementAdded, checkSpatialElementPositionChanged, comparePositions, contains, contains, countObservers, deleteObserver, deleteObservers, distance, getCoordinate, getDefaultPositionPrecision, getId, getModel, getName, getObserverState, getUpdatingSpatialElement, isValid, notifyObservers, removeSpatialElement, setDefaultPositionPrecision, setModel, setName, setObserverState, setUpdatingElement, updatePosition, updatePosition_
-
-
-
-
Field Detail
-
ROADS
public static final double ROADS
The ciruity addFactor for road networks, see pg 559 of Ballou- See Also:
- Constant Field Values
-
RAIL
public static final double RAIL
The ciruity addFactor for rail networks, see pg 559 of Ballou- See Also:
- Constant Field Values
-
DEFAULT_EARTH_RADIUS
protected static final double DEFAULT_EARTH_RADIUS
The default radius for the earth, @see (http://en.wikipedia.org/wiki/Great_circle_distance)- See Also:
- Constant Field Values
-
myEarthRadius
protected double myEarthRadius
Holds teh radius of the earth for calculating great circle distance
-
myCircuityFactor
protected double myCircuityFactor
Can be set to adjust computed great circle distance to account for the circuity of the road/rail network, by default 1.0
-
-
Constructor Detail
-
GreatCircleBasedSpatialModel
public GreatCircleBasedSpatialModel()
Creates a spatial model that uses the great circle distance as the basis for computing distance between two coordinates.
-
GreatCircleBasedSpatialModel
public GreatCircleBasedSpatialModel(java.lang.String name)
Creates a spatial model that uses the great circle distance as the basis for computing distance between two coordinates.- Parameters:
name
- , An optional name for the spatial model
-
GreatCircleBasedSpatialModel
public GreatCircleBasedSpatialModel(java.lang.String name, double circuityFactor)
Creates a spatial model that uses the great circle distance as the basis for computing distance between two coordinates.- Parameters:
name
- , An optional name for the spatial modelcircuityFactor
- Can be used to adjust distance for network effects
-
-
Method Detail
-
getCoordinate
public CoordinateIfc getCoordinate(double lat, double lon, double x3)
Returns a valid coordinate- Specified by:
getCoordinate
in classSpatialModel
- Parameters:
lat
- must be between -90 and 90 degreeslon
- must be between -180 and 180 degreesx3
- not used- Returns:
-
getDefaultCoordinate
public CoordinateIfc getDefaultCoordinate()
Description copied from class:SpatialModel
Returns a default set of coordinates to be used to initialize the location of spatial elements if necessary.- Specified by:
getDefaultCoordinate
in classSpatialModel
- Returns:
-
getCoordinate
public static final CoordinateIfc getCoordinate(GreatCircleBasedSpatialModel.Direction latD, double latd, double latm, GreatCircleBasedSpatialModel.Direction lonD, double lond, double lonm)
Returns a valid coordinate- Parameters:
latD
- direction associated with the latitudelatd
- degrees latitudelatm
- minutes latitudelonD
- longitude directionlond
- longitude degreeslonm
- longitude minutes- Returns:
-
getCoordinate
public static CoordinateIfc getCoordinate(GreatCircleBasedSpatialModel.Direction latD, double latd, double latm, double lats, GreatCircleBasedSpatialModel.Direction lonD, double lond, double lonm, double lons)
Returns a valid coordinate- Parameters:
latD
- latitude directionlatd
- latitude degreeslatm
- latitude minuteslats
- latitude secondslonD
- longitude directionlond
- longitude degreeslonm
- longitude minuteslons
- longitude seconds- Returns:
-
getLatitude
public static final double getLatitude(GreatCircleBasedSpatialModel.Direction direction, double degrees, double minutes)
Returns a latitude in degrees- Parameters:
direction
-degrees
-minutes
-- Returns:
-
getLatitude
public static double getLatitude(GreatCircleBasedSpatialModel.Direction direction, double degrees, double minutes, double seconds)
Returns a latitude in degrees- Parameters:
direction
-degrees
-minutes
-seconds
-- Returns:
-
getLongitude
public static final double getLongitude(GreatCircleBasedSpatialModel.Direction direction, double degrees, double minutes)
Returns a longitude in degrees- Parameters:
direction
-degrees
-minutes
-- Returns:
-
getLongitude
public static double getLongitude(GreatCircleBasedSpatialModel.Direction direction, double degrees, double minutes, double seconds)
Returns a longitude in degrees- Parameters:
direction
-degrees
-minutes
-seconds
-- Returns:
-
getDirectionSign
public static final double getDirectionSign(GreatCircleBasedSpatialModel.Direction d)
Gets the sign associated with the supplied direction- Parameters:
d
-- Returns:
-
isValid
public boolean isValid(CoordinateIfc coordinate)
Description copied from class:SpatialModel
Checks to see if the supplied coordinate is physically valid within the spatial model. This depends on the underlying spatial representation. This method should check whether the coordinate can be represented spatially within this spatial model. If so, this method should return true.- Specified by:
isValid
in classSpatialModel
- Returns:
-
distance
public double distance(CoordinateIfc fromCoordinate, CoordinateIfc toCoordinate)
Description copied from class:SpatialModel
Computes the distance between the two supplied coordinates- Specified by:
distance
in classSpatialModel
- Returns:
-
comparePositions
public boolean comparePositions(CoordinateIfc coordinate1, CoordinateIfc coordinate2)
Description copied from class:SpatialModel
Returns true if the first coordinate is the same as second coordinate within the underlying spatial model. This is not object reference equality, but rather whether or not the positions within the underlying spatial model can be considered spatially (equivalent). Requirement: The coordinates must be valid within the spatial model. If they are not valid within same spatial model, then this method should return false.- Specified by:
comparePositions
in classSpatialModel
- Returns:
-
getEarthRadius
public final double getEarthRadius()
The earth's radius for great circle calculation- Returns:
- Returns the earth's Radius.
-
setEarthRadius
public final void setEarthRadius(double radius)
The earth's radius for great circle calculation- Parameters:
radius
- The radius for the earth to set.
-
getCircuityFactor
public final double getCircuityFactor()
The network circuity addFactor for adjusting the distance.- Returns:
- Returns the circuityFactor.
-
setCircuityFactor
protected final void setCircuityFactor(double circuityFactor)
- Parameters:
circuityFactor
- The circuityFactor to set.
-
main
public static void main(java.lang.String[] args)
-
-