geography
Class Streetmap

java.lang.Object
  |
  +--geography.Streetmap

public class Streetmap
extends java.lang.Object

A street map. Supports address lookup and route planning. The map can be constructed from a .map file, or by adding StreetSegments one at a time.


Field Summary
protected  geography.AddressFinder af
          An object that can look up addresses on the map.
protected  graph.KeyedDigraph g
          A directed graph of the streets.
protected  graph.Weighter weighter
          For finding the weights of edges in g.
 
Constructor Summary
Streetmap()
          Constructs an empty streetmap (empty graph).
Streetmap(java.lang.String filename)
          Constructs a streetmap from a .map file.
 
Method Summary
 geography.AddressFinder addressFinder()
          Return an address finder for this street map.
protected  void addStreetSegment(geography.StreetSegment ss)
          Adds a new street segment to the map.
static double edgeDirection(graph.DirectedEdge e)
          Given an edge of g, returns the direction of the street segment it represents, as a number in degrees from -180 to 180.
static double edgeLength(graph.DirectedEdge e)
          Given an edge of g, returns the length in meters of the street segment it represents.
static void main(java.lang.String[] args)
          A simple interaction with the user.
 geography.Intersection readIntersection(java.io.BufferedReader br, java.lang.String prompt)
          Get an address from the user on the input stream underlying br, and return the corresponding intersection if we can find it.
 geography.Route shortestRoute(geography.Intersection isctStart, geography.Intersection isctEnd)
          Returns a shortest route between two intersections.
 geography.Route shortestRoute(geography.Point pStart, geography.Point pEnd)
          Returns a shortest route between two points.
 geography.Route shortestRoute(java.lang.String addrStart, java.lang.String addrEnd)
          Given two addresses, returns a shortest route between them.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

g

protected graph.KeyedDigraph g
A directed graph of the streets. Each vertex holds a Point, and is keyed by that Point so that we can look it up. Each edge holds a string that is the street's name.


af

protected geography.AddressFinder af
An object that can look up addresses on the map.


weighter

protected graph.Weighter weighter
For finding the weights of edges in g.

Constructor Detail

Streetmap

public Streetmap()
Constructs an empty streetmap (empty graph).


Streetmap

public Streetmap(java.lang.String filename)
          throws java.io.IOException,
                 DataFormatException
Constructs a streetmap from a .map file.

Method Detail

addStreetSegment

protected void addStreetSegment(geography.StreetSegment ss)
Adds a new street segment to the map.


addressFinder

public geography.AddressFinder addressFinder()
Return an address finder for this street map. (Surely a street map should support address lookup by the user, even outside the context of route planning.)


shortestRoute

public geography.Route shortestRoute(geography.Point pStart,
                                     geography.Point pEnd)
                              throws NoSuchVertexException
Returns a shortest route between two points.

Throws:
NoSuchVertexException - if the points are not both vertices of our map graph.

shortestRoute

public geography.Route shortestRoute(geography.Intersection isctStart,
                                     geography.Intersection isctEnd)
                              throws NoSuchVertexException
Returns a shortest route between two intersections. This is just a convenience method.

Throws:
NoSuchVertexException - if either intersection is null, or is not on our map graph.

shortestRoute

public geography.Route shortestRoute(java.lang.String addrStart,
                                     java.lang.String addrEnd)
                              throws DataFormatException,
                                     NoSuchVertexException
Given two addresses, returns a shortest route between them. Well, anyway, returns a shortest route between intersections near them.

Throws:
NoSuchVertexException - if either address cannot be found on this street map, even approximately (e.g., if the map is empty).
DataFormatException

edgeLength

public static double edgeLength(graph.DirectedEdge e)
Given an edge of g, returns the length in meters of the street segment it represents. At present, we just consider the distance between the segment's endpoints. Note that this will underestimate the length of curvy streets. (Data about street shape are actually available, but we're ignoring those data for this assignment.)


edgeDirection

public static double edgeDirection(graph.DirectedEdge e)
Given an edge of g, returns the direction of the street segment it represents, as a number in degrees from -180 to 180. See Point.directionTo(geography.Point).


readIntersection

public geography.Intersection readIntersection(java.io.BufferedReader br,
                                               java.lang.String prompt)
                                        throws java.io.IOException
Get an address from the user on the input stream underlying br, and return the corresponding intersection if we can find it. If we can't find it, prompt the user to try again. Returns null if the user's input is empty.

java.io.IOException

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException,
                        DataFormatException,
                        java.lang.ArrayIndexOutOfBoundsException
A simple interaction with the user. Prompts the user for two addresses, and prints the shortest route between them. There is a single command-line argument -- the name of the .map file to build the Streetmap from. This method could be improved by detecting error conditions (the exceptions listed below, as well as too many arguments) and exiting gracefully with an error message.

java.io.IOException
DataFormatException
java.lang.ArrayIndexOutOfBoundsException