Class MapGraph
- java.lang.Object
-
- MapGraph
-
- All Implemented Interfaces:
AStarGraph<org.locationtech.spatial4j.shape.Point>
,Graph<org.locationtech.spatial4j.shape.Point>
public class MapGraph extends Object implements AStarGraph<org.locationtech.spatial4j.shape.Point>
AStarGraph
of places asPoint
vertices and streets edges weighted by physical distance.- See Also:
AStarGraph
,MapServer
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
MapGraph.Handler
Parses OSM XML files to construct a MapGraph.
-
Field Summary
Fields Modifier and Type Field Description private Autocomplete
autocomplete
private org.locationtech.spatial4j.context.SpatialContext
context
private Map<CharSequence,Integer>
importance
private Map<String,List<org.locationtech.spatial4j.shape.Point>>
locations
private Map<org.locationtech.spatial4j.shape.Point,List<Edge<org.locationtech.spatial4j.shape.Point>>>
neighbors
private String
osmPath
private String
placesPath
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addEdge(org.locationtech.spatial4j.shape.Point from, org.locationtech.spatial4j.shape.Point to)
Adds an edge to this graph if it doesn't already exist using distance as the weight.private Comparator<org.locationtech.spatial4j.shape.Point>
byEstimatedDistanceFrom(org.locationtech.spatial4j.shape.Point start)
Returns aComparator
by estimated distance from the given start point.org.locationtech.spatial4j.shape.Point
closest(org.locationtech.spatial4j.shape.Point target)
Returns the location closest to the given target location.double
estimatedDistance(org.locationtech.spatial4j.shape.Point start, org.locationtech.spatial4j.shape.Point end)
Returns an estimated distance from start to end.private static InputStream
fileStream(String path)
Returns an input stream from the contents of the file at the given path.List<org.locationtech.spatial4j.shape.Point>
getLocations(String locationName, org.locationtech.spatial4j.shape.Point center)
Return all locations that match a valid location name.List<CharSequence>
getLocationsByPrefix(String prefix)
Return the names of all locations that prefix-match the query string.List<Edge<org.locationtech.spatial4j.shape.Point>>
neighbors(org.locationtech.spatial4j.shape.Point point)
Returns a list of the outgoing edges from the given vertex.List<org.locationtech.spatial4j.shape.Point>
shortestPath(org.locationtech.spatial4j.shape.Point start, org.locationtech.spatial4j.shape.Point goal)
Returns a list of points representing the shortest path from the points closest to the start and goal.String
toString()
-
-
-
Field Detail
-
osmPath
private final String osmPath
-
placesPath
private final String placesPath
-
context
private final org.locationtech.spatial4j.context.SpatialContext context
-
neighbors
private final Map<org.locationtech.spatial4j.shape.Point,List<Edge<org.locationtech.spatial4j.shape.Point>>> neighbors
-
autocomplete
private final Autocomplete autocomplete
-
importance
private final Map<CharSequence,Integer> importance
-
-
Constructor Detail
-
MapGraph
public MapGraph(String osmPath, String placesPath, org.locationtech.spatial4j.context.SpatialContext context) throws ParserConfigurationException, SAXException, IOException
Constructs a new map graph from the path to an OSM GZ file and a places TSV.- Parameters:
osmPath
- The path to a gzipped OSM (XML) file.placesPath
- The path to a TSV file representing places and importance.- Throws:
ParserConfigurationException
- if a parser cannot be created.SAXException
- for SAX errors.IOException
- if a file is not found or if the file is not gzipped.
-
-
Method Detail
-
fileStream
private static InputStream fileStream(String path)
Returns an input stream from the contents of the file at the given path.- Parameters:
path
- a file path.- Returns:
- an input stream with the contents of the specified file.
-
closest
public org.locationtech.spatial4j.shape.Point closest(org.locationtech.spatial4j.shape.Point target)
Returns the location closest to the given target location.- Parameters:
target
- the target location.- Returns:
- the id of the location closest to the target.
-
getLocationsByPrefix
public List<CharSequence> getLocationsByPrefix(String prefix)
Return the names of all locations that prefix-match the query string.- Parameters:
prefix
- prefix string that could be any case with or without punctuation.- Returns:
- a list of full names of locations matching the prefix.
-
getLocations
public List<org.locationtech.spatial4j.shape.Point> getLocations(String locationName, org.locationtech.spatial4j.shape.Point center)
Return all locations that match a valid location name.- Parameters:
locationName
- a full name of a valid location.- Returns:
- a list of locations whose name matches the location name.
-
shortestPath
public List<org.locationtech.spatial4j.shape.Point> shortestPath(org.locationtech.spatial4j.shape.Point start, org.locationtech.spatial4j.shape.Point goal)
Returns a list of points representing the shortest path from the points closest to the start and goal.- Parameters:
start
- thePoint
to start the shortest path.goal
- thePoint
to end the shortest path.- Returns:
- a list of points representing the shortest path from the points closest to the start and goal.
-
neighbors
public List<Edge<org.locationtech.spatial4j.shape.Point>> neighbors(org.locationtech.spatial4j.shape.Point point)
Description copied from interface:Graph
Returns a list of the outgoing edges from the given vertex.
-
estimatedDistance
public double estimatedDistance(org.locationtech.spatial4j.shape.Point start, org.locationtech.spatial4j.shape.Point end)
Description copied from interface:AStarGraph
Returns an estimated distance from start to end.- Specified by:
estimatedDistance
in interfaceAStarGraph<org.locationtech.spatial4j.shape.Point>
- Parameters:
start
- the beginning vertex.end
- the destination vertex.- Returns:
- an estimated distance from start to end.
-
addEdge
private void addEdge(org.locationtech.spatial4j.shape.Point from, org.locationtech.spatial4j.shape.Point to)
Adds an edge to this graph if it doesn't already exist using distance as the weight.- Parameters:
from
- the originating point of the edge.to
- the terminating point of the edge.
-
byEstimatedDistanceFrom
private Comparator<org.locationtech.spatial4j.shape.Point> byEstimatedDistanceFrom(org.locationtech.spatial4j.shape.Point start)
Returns aComparator
by estimated distance from the given start point.- Parameters:
start
- the given start point for distance comparison.- Returns:
- a
Comparator
by estimated distance from the given start point.
-
-