public final class Way extends GenericTaggedNode<Way> implements java.lang.Comparable<Way>
GenericTaggedNode.ExtendedGTNAttr
Modifier and Type | Field and Description |
---|---|
long |
id
The OpenStreetMap assigned ID number for this Way.
|
static int |
MAX_VERTICES_IN_WAY
The maximum number of vertices that can be stored to disk in a Way (due to storage
field size).
|
int |
maxLat
The furthest North of any vertex of this Way.
|
int |
maxLon
The furthest East of any vertex of this Way.
|
int |
minLat
The furthest South of any vertex of this Way.
|
int |
minLon
The furthest West of any vertex of this Way.
|
int[] |
nodeLatLonList
Array of latitude/longitude pairs in millionths of degrees North/East.
|
int |
numLatLonPairs
Number of vertices in the Way.
|
static java.util.Comparator<Way> |
WAY_COMPARATOR
Comparator for sorting Ways, such that the sort code doesn't have to keep
casting Ways to the Comparable interface.
|
decodedtagArray, extraAmenities, FIXME, FIXME_OBJ, flags, flags2, FLAGS2_BOGUS, FLAGS2_BOGUS_OBJ, FLAGS2_FEE, FLAGS2_FEE_OBJ, FLAGS2_FLOOD_PRONE, FLAGS2_FLOOD_PRONE_OBJ, FLAGS2_HAS_POSTALADDR, FLAGS2_INTERMITTENT, FLAGS2_INTERMITTENT_OBJ, FLAGS2_IS_LIT, FLAGS2_IS_LIT_OBJ, FLAGS2_UNDERGROUND, FLAGS2_WHEELCHAIR_ACCESSIBLE, FLAGS2_WHEELCHAIR_ACCESSIBLE_OBJ, HAS_COLOR, HAS_ID, HAS_ID64, HAS_INTERNET_ACCESS, HAS_INTERNET_ACCESS_OBJ, HAS_TOLL, HAS_TOLL_OBJ, IS_AREA, IS_AREA_OBJ, IS_BRIDGE, IS_BRIDGE_OBJ, IS_BUILDING, IS_BUILDING_OBJ, IS_DISUSED, IS_DISUSED_OBJ, IS_HOLE, IS_INCOMPLETE, IS_ISLAND, IS_ISLAND_OBJ, IS_ONEWAY, IS_ONEWAY_BACKWARDS, IS_ONEWAY_BACKWARDS_OBJ, IS_ONEWAY_OBJ, IS_TUNNEL, IS_TUNNEL_OBJ, IS_WATER, MARINE, RENDERABLE_FLAGS, segmentNum
Constructor and Description |
---|
Way()
Create an empty Way object with the default preallocation for the node lat/lon list.
|
Way(int numElements)
Create an empty Way with the specified number of elements in the node lat/lon list.
|
Way(int numElements,
GenericTaggedNode<?> refWay)
Create an empty Way with the specified number of elements in the node lat/lon list.
|
Way(int numElements,
Way refWay)
Create an empty Way with the specified number of elements in the node lat/lon list.
|
Modifier and Type | Method and Description |
---|---|
void |
addLatLon(int lat,
int lon)
Add another vertex to the Way, updating the Way's bounding box.
|
boolean |
canDoDelta()
Report if this Way can be stored using 16-bit signed deltas for the vertices instead
of 32-bit absolute values.
|
void |
clearPolygon()
Release any storage used for a point-in-polygon checking polygon object.
|
int |
compareTo(Way o2)
Compares this object with the specified object for order.
|
static boolean |
doLineSegmentsIntersect(int ax1,
int ay1,
int ax2,
int ay2,
int bx1,
int by1,
int bx2,
int by2)
Check if two line segments intersect, according to the algorithm from
"Algorithms", Cormen, Leiserson & Rivest, 1992, pp.
|
Way |
dup()
Make a deep copy of this Way.
|
boolean |
equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one.
|
WayPoint |
findNearestPositionOnWay(double latitude,
double longitude,
float tolerance,
boolean doLaps)
Find the closest position on the Way relative to the specified coordinates.
|
double |
getAccruedTurn()
Calculate the net direction of turning of this Way.
|
int |
getCentroidLat()
Get the latitude of this Way's centroid.
|
int |
getCentroidLon()
Get the longitude of this Way's centroid.
|
java.lang.Number |
getId()
Return the ID of this OSM record as a sub-class of Number.
|
Way[] |
getTileWays(int minTileLat,
int minTileLon,
int maxTileLat,
int maxTileLon,
java.io.PrintStream out)
Find all the pieces of this Way that are contained inside the specified axis-aligned bounding box.
|
int |
hashCode()
Returns a hash code value for the object.
|
boolean |
intersects(int lLat,
int hLat,
int lLon,
int hLon)
Test if this Way intersects the specified axis-aligned bounding box.
|
boolean |
isClockWise()
Test if the Way is clockwise or counterclockwise.
|
static boolean |
isVertexListMatching(Way way1,
Way way2)
Compare the vertex arrays of 2 Ways to see if they are identical.
|
static boolean |
isVertexListReverseMatching(Way way1,
Way way2)
Compare the vertex arrays of 2 Ways to see if they are palindromes (equal in reverse).
|
static void |
main(java.lang.String[] args)
For unit testing of Way class only.
|
void |
prependLatLon(int lat,
int lon)
Add another vertex to the Way at the beginning, updating the Way's bounding box.
|
static Way |
read(java.io.DataInput is)
Instantiate a new Way read from
the input stream.
|
static Way |
read(NonshareableBufferedDataInputStream is)
Instantiate a new Way read from
the input stream.
|
void |
recalculateBounds()
Recompute the min/max bounds of the Way based on the current vertices.
|
int |
removeRedundantWayVertices(int dupThreshold)
Squeeze down the vertices in the Way to remove duplicate adjacent vertices, and vertices
in the middle of a straight line segment (as opposed to at the ending joints of a line
segment).
|
void |
reread(java.io.DataInput is)
Clear the contents of this Way object and load it with another Way's data read from
the input stream.
|
void |
reread(NonshareableBufferedDataInputStream is)
Clear the contents of this Way object and load it with another Way's data read from
the input stream.
|
void |
reverseWay()
Swap the order of the vertices in the Way (last to first and first to last).
|
java.util.ArrayList<Way> |
splitAreaWayIntoAcceptableSegments(java.io.PrintStream out,
java.lang.String useCase)
Split an oversize area Way into a collection of contiguous Ways that are each under the maximum vertex
count and don't accidentally put points outside the original Way inside any of the segments.
|
java.lang.String |
toString()
Returns a string representation of the object.
|
void |
write(java.io.DataOutput os)
Encode this Way into a file using the DataOutput storage formats.
|
void |
writeGPX(java.io.PrintStream ps)
Write this Way to the specified stream as the XML tags one element in GPX schema format.
|
protected void |
writeId(java.io.DataOutput dos)
Handle writing the ID field to the binary data stream (handles larger ID ranges in
varying subclasses).
|
addAmenityType, compareGTNAttributes, decodedTagArrayToString, ensureElementHasTagArray, hasDecodedTags, hasThisAmenity, putTag, readTags, readTags, removeRedundantAmenityTypes, replaceAmenityType, writeTags
public static final int MAX_VERTICES_IN_WAY
public long id
public int[] nodeLatLonList
public int numLatLonPairs
public int minLat
public int maxLat
public int minLon
public int maxLon
public static final java.util.Comparator<Way> WAY_COMPARATOR
public Way()
public Way(int numElements)
numElements
- size for node lat/lon array (must be twice the number of vertices to store)public Way(int numElements, Way refWay)
numElements
- size for node lat/lon array (must be twice the number of vertices to store)refWay
- Way whose non-vertex properties should be copiedpublic Way(int numElements, GenericTaggedNode<?> refWay)
numElements
- size for node lat/lon array (must be twice the number of vertices to store)refWay
- Way (or Relation) whose non-vertex properties should be copiedpublic final void addLatLon(int lat, int lon)
lat
- latitude in millionths of degrees Northlon
- longitude in millionths of degrees Eastpublic final void prependLatLon(int lat, int lon)
lat
- latitude in millionths of degrees Northlon
- longitude in millionths of degrees Eastpublic final Way[] getTileWays(int minTileLat, int minTileLon, int maxTileLat, int maxTileLon, java.io.PrintStream out)
minTileLat
- southernmost edge in millionths of degrees NorthminTileLon
- westernmost edge in millionths of degrees EastmaxTileLat
- northernmost edge in millionths of degrees NorthmaxTileLon
- easternmost edge in millionths of degrees Eastout
- PrintStream for logging any exceptional conditionspublic boolean isClockWise()
public double getAccruedTurn()
GenericTaggedNode.IS_AREA
Way) will indicate whether the Way is clockwise (positive net angle) or
counterclockwise (negative net angle).public void clearPolygon()
public void reverseWay()
public void write(java.io.DataOutput os) throws java.io.IOException, java.lang.IllegalArgumentException
os
- DataOutput to write the Way tojava.io.IOException
- if Way could not be writtenjava.lang.IllegalArgumentException
- if Way has too many vertices to fit in file encoding formatprotected void writeId(java.io.DataOutput dos) throws java.io.IOException
writeId
in class GenericTaggedNode<Way>
dos
- DataOutput to use to append the binary ID valuejava.io.IOException
- if write fails for any reasonpublic java.lang.Number getId()
getId
in class GenericTaggedNode<Way>
public static Way read(java.io.DataInput is) throws java.io.IOException
is
- DataInput to read the next Way fromjava.io.IOException
- if Way could not be successfully read from the DataInputpublic static Way read(NonshareableBufferedDataInputStream is) throws java.io.IOException
is
- NonshareableBufferedDataInputStream to read the next Way fromjava.io.IOException
- if Way could not be successfully read from the DataInputpublic final void reread(java.io.DataInput is) throws java.io.IOException
is
- DataInput to read the next Way fromjava.io.IOException
- if Way could not be successfully read from the DataInputpublic final void reread(NonshareableBufferedDataInputStream is) throws java.io.IOException
is
- NonshareableBufferedDataInputStream to read the next Way fromjava.io.IOException
- if Way could not be successfully read from the DataInputpublic final boolean intersects(int lLat, int hLat, int lLon, int hLon)
lLat
- minimum latitude in millionths of degrees NorthhLat
- maximum latitude in millionths of degrees NorthlLon
- minimum longitude in millionths of degrees EasthLon
- maximum longitude in millionths of degrees Eastpublic int removeRedundantWayVertices(int dupThreshold)
dupThreshold
- int max difference between coordinate values to be considered the samepublic void recalculateBounds()
public java.util.ArrayList<Way> splitAreaWayIntoAcceptableSegments(java.io.PrintStream out, java.lang.String useCase) throws java.lang.IllegalArgumentException
out
- PrintStream for logging errorsuseCase
- String identifying use case that had the logged errorjava.lang.IllegalArgumentException
- if Way for a polyline instead of a closed areapublic static boolean doLineSegmentsIntersect(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2)
ax1
- X coordinate of start of first segmentay1
- Y coordinate of start of first segmentax2
- X coordinate of end of first segmentay2
- Y coordinate of end of first segmentbx1
- X coordinate of start of second segmentby1
- Y coordinate of start of second segmentbx2
- X coordinate of end of second segmentby2
- Y coordinate of end of second segmentpublic java.lang.String toString()
toString
in class java.lang.Object
public WayPoint findNearestPositionOnWay(double latitude, double longitude, float tolerance, boolean doLaps)
latitude
- latitude in fractional degrees Northlongitude
- longitude in fractional degrees Easttolerance
- maximum perpendicular distance from the Way allowed for a match, in metersdoLaps
- boolean true if line segment between last vertex and first vertex should also
be checked, false if notpublic int compareTo(Way o2)
compareTo
in interface java.lang.Comparable<Way>
o2
- the object to be compared.java.lang.ClassCastException
- if the specified object's type prevents it
from being compared to this object.public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- the reference object with which to compare.true
if this object is the same as the obj
argument; false
otherwise.hashCode()
public int hashCode()
hashCode
in class java.lang.Object
equals(Object)
public static void main(java.lang.String[] args) throws java.io.IOException
args
- String array of parameters. [0] is path of way file to read, [1] is optional -quiet flag to suppress most printed outputjava.io.IOException
- if node file cannot be read for any reasonpublic static boolean isVertexListMatching(Way way1, Way way2)
way1
- first Way to compareway2
- second Way to comparepublic static boolean isVertexListReverseMatching(Way way1, Way way2)
way1
- first Way to compareway2
- second Way to comparepublic Way dup()
dup
in class GenericTaggedNode<Way>
public final boolean canDoDelta()
public int getCentroidLat()
public int getCentroidLon()
public void writeGPX(java.io.PrintStream ps)
writeGPX
in class GenericTaggedNode<Way>
ps
- PrintStream to write to