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 classGreatCircleBasedSpatialModel.DirectionDefines the directions on a compass
-
Field Summary
Fields Modifier and Type Field Description protected static doubleDEFAULT_EARTH_RADIUSThe default radius for the earth, @see (http://en.wikipedia.org/wiki/Great_circle_distance)protected doublemyCircuityFactorCan be set to adjust computed great circle distance to account for the circuity of the road/rail network, by default 1.0protected doublemyEarthRadiusHolds teh radius of the earth for calculating great circle distancestatic doubleRAILThe ciruity addFactor for rail networks, see pg 559 of Balloustatic doubleROADSThe 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 booleancomparePositions(CoordinateIfc coordinate1, CoordinateIfc coordinate2)Returns true if the first coordinate is the same as second coordinate within the underlying spatial model.doubledistance(CoordinateIfc fromCoordinate, CoordinateIfc toCoordinate)Computes the distance between the two supplied coordinatesdoublegetCircuityFactor()The network circuity addFactor for adjusting the distance.CoordinateIfcgetCoordinate(double lat, double lon, double x3)Returns a valid coordinatestatic CoordinateIfcgetCoordinate(GreatCircleBasedSpatialModel.Direction latD, double latd, double latm, double lats, GreatCircleBasedSpatialModel.Direction lonD, double lond, double lonm, double lons)Returns a valid coordinatestatic CoordinateIfcgetCoordinate(GreatCircleBasedSpatialModel.Direction latD, double latd, double latm, GreatCircleBasedSpatialModel.Direction lonD, double lond, double lonm)Returns a valid coordinateCoordinateIfcgetDefaultCoordinate()Returns a default set of coordinates to be used to initialize the location of spatial elements if necessary.static doublegetDirectionSign(GreatCircleBasedSpatialModel.Direction d)Gets the sign associated with the supplied directiondoublegetEarthRadius()The earth's radius for great circle calculationstatic doublegetLatitude(GreatCircleBasedSpatialModel.Direction direction, double degrees, double minutes)Returns a latitude in degreesstatic doublegetLatitude(GreatCircleBasedSpatialModel.Direction direction, double degrees, double minutes, double seconds)Returns a latitude in degreesstatic doublegetLongitude(GreatCircleBasedSpatialModel.Direction direction, double degrees, double minutes)Returns a longitude in degreesstatic doublegetLongitude(GreatCircleBasedSpatialModel.Direction direction, double degrees, double minutes, double seconds)Returns a longitude in degreesbooleanisValid(CoordinateIfc coordinate)Checks to see if the supplied coordinate is physically valid within the spatial model.static voidmain(java.lang.String[] args)protected voidsetCircuityFactor(double circuityFactor)voidsetEarthRadius(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:
getCoordinatein 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:SpatialModelReturns a default set of coordinates to be used to initialize the location of spatial elements if necessary.- Specified by:
getDefaultCoordinatein 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:SpatialModelChecks 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:
isValidin classSpatialModel- Returns:
-
distance
public double distance(CoordinateIfc fromCoordinate, CoordinateIfc toCoordinate)
Description copied from class:SpatialModelComputes the distance between the two supplied coordinates- Specified by:
distancein classSpatialModel- Returns:
-
comparePositions
public boolean comparePositions(CoordinateIfc coordinate1, CoordinateIfc coordinate2)
Description copied from class:SpatialModelReturns 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:
comparePositionsin 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)
-
-