ps2
Class GeoFeature

java.lang.Object
  extended by ps2.GeoFeature

public class GeoFeature
extends Object

A GeoFeature represents a path from one location to another along a single geographic feature. GeoFeatures are immutable.

GeoFeature abstracts over a sequence of GeoSegments, all of which have the same name, thus providing a representation for nonlinear or nonatomic geographic features. As an example, a GeoFeature might represent the course of a winding river, or travel along a road through intersections but remaining on the same road.

GeoFeatures are immutable. New GeoFeatures can be constructed by adding a segment to the end of a GeoFeature. An added segment must be properly oriented; that is, its p1 field must correspond to the end of the original GeoFeature, and its p2 field corresponds to the end of the new GeoFeature, and the name of the GeoSegment being added must match the name of the existing GeoFeature.

Because a GeoFeature is not necessarily straight, its length -- the distance traveled by following the path from start to end -- is not necessarily the same as the distance along a straight line between its endpoints.

Specification Fields
Derived Fields:
length : real // total length of the geo feature, in miles

Constructor Summary
Constructor and Description
GeoFeature(GeoSegment gs)
          Constructs a new GeoFeature.
 
Method Summary
Modifier and Type Method and Description
 GeoFeature addSegment(GeoSegment gs)
          Creates a new GeoFeature that is equal to this GeoFeature with gs appended to its end.
 boolean equals(Object o)
          Compares the argument with this GeoFeature for equality.
 GeoPoint getEnd()
           
 double getEndHeading()
           
 List<GeoSegment> getGeoSegments()
          Returns a List of GeoSegment objects.
 double getLength()
           
 String getName()
           
 GeoPoint getStart()
           
 double getStartHeading()
           
 int hashCode()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GeoFeature

public GeoFeature(GeoSegment gs)
Constructs a new GeoFeature.

Requires:
gs != null
Effects:
Constructs a new GeoFeature, r, such that r.name = gs.name && r.startHeading = gs.heading && r.endHeading = gs.heading && r.start = gs.p1 && r.end = gs.p2
Method Detail

getName

public String getName()
Returns:
name of geographic feature

getStart

public GeoPoint getStart()
Returns:
location of the start of the feature

getEnd

public GeoPoint getEnd()
Returns:
location of the end of of the feature

getStartHeading

public double getStartHeading()
Returns:
direction (in standard heading) of travel at the start of the feature, in degrees. This is the heading of the first non-zero-length segment.

getEndHeading

public double getEndHeading()
Returns:
direction of travel at the end of the feature, in degrees. This is the heading of the last non-zero-length segment.

getLength

public double getLength()
Returns:
total length of the geo feature, in miles. NOTE: this is NOT as-the-crow-flies, but rather the total distance required to traverse the geo feature. These values are not necessarily equal.

addSegment

public GeoFeature addSegment(GeoSegment gs)
Creates a new GeoFeature that is equal to this GeoFeature with gs appended to its end.

Returns:
a new GeoFeature r such that r.end = gs.p2 && r.endHeading = gs.heading && r.length = this.length + gs.length
Requires:
gs != null && gs.p1 = this.end && gs.name = this.name

getGeoSegments

public List<GeoSegment> getGeoSegments()
Returns a List of GeoSegment objects. The concatenation of the GeoSegments, in order, is equivalent to this GeoFeature. All the GeoSegments should have the same name.

Returns:
a List of GeoSegments such that
      this.start        = a.get(0).p1
   && this.startHeading = a.get(0).heading
   && this.end          = a.get(a.size - 1).p2
   && this.endHeading   = a.get(a.size - 1).heading
   && this.length       =  sum (0 ≤ i < a.size) . a.get(i).length
   && for all integers i .
          (0 ≤ i < a.size - 1 ⇒ (a.get(i).name = a.get(i+1).name &&
                                              a.get(i).p2 = a.get(i+1).p1))
 
See Also:
GeoSegment

equals

public boolean equals(Object o)
Compares the argument with this GeoFeature for equality.

Overrides:
equals in class Object
Returns:
o != null && (o instanceof GeoFeature) && (o.geoSegments and this.geoSegments contain the same elements in the same order).

hashCode

public int hashCode()
Overrides:
hashCode in class Object
Returns:
a valid hashcode for this.

toString

public String toString()
Overrides:
toString in class Object
Returns:
a string representation of this.