Package com.graphhopper.util
Class PointList
java.lang.Object
com.graphhopper.util.PointList
- All Implemented Interfaces:
PointAccess
,Iterable<GHPoint3D>
- Direct Known Subclasses:
ShallowImmutablePointList
Slim list to store several points (without the need for a point object). Be aware that the PointList is closely
coupled with the
ShallowImmutablePointList
both are not designed for inheritance (but final is not possible if we keep it simple).- Author:
- Peter Karich
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(double lat, double lon) void
add
(double lat, double lon, double ele) void
add
(PointAccess nodeAccess, int index) void
void
void
clear()
clone
(boolean reverse) Clones this PointList.copy
(int from, int end) This method does a deep copy of this object for the specified range.void
ensureNode
(int nodeId) This method ensures that the node with the specified index exists i.e.boolean
static boolean
equalsEps
(double d1, double d2) static boolean
equalsEps
(double d1, double d2, double epsilon) static PointList
from
(org.locationtech.jts.geom.LineString lineString) static PointList
fromLineString
(org.locationtech.jts.geom.LineString lineString) get
(int index) org.locationtech.jts.geom.LineString
getCachedLineString
(boolean includeElevation) int
double
getEle
(int index) Returns the elevation of the specified nodeId.double
getLat
(int index) double
getLon
(int index) int
hashCode()
boolean
is3D()
boolean
isEmpty()
boolean
iterator()
Once immutable, there is no way to make this object mutable again.void
parse2DJSON
(String str) Takes the string from a json array ala [lon1,lat1], [lon2,lat2], ...void
void
reverse()
void
set
(int index, double lat, double lon, double ele) void
setElevation
(int index, double ele) void
setNode
(int nodeId, double lat, double lon, double ele) This method ensures that the node with the specified index exists and prepares access to it.shallowCopy
(int from, int end, boolean makeImmutable) Create a shallow copy of this Pointlist from from to end, excluding end.int
size()
org.locationtech.jts.geom.LineString
toLineString
(boolean includeElevation) toString()
void
trimToSize
(int newSize) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface com.graphhopper.util.PointAccess
setNode
-
Field Details
-
EMPTY
-
size
protected int size -
is3D
protected boolean is3D
-
-
Constructor Details
-
PointList
public PointList() -
PointList
public PointList(int cap, boolean is3D)
-
-
Method Details
-
is3D
public boolean is3D()- Specified by:
is3D
in interfacePointAccess
- Returns:
- true if elevation data is stored and can be retrieved
-
getDimension
public int getDimension()- Specified by:
getDimension
in interfacePointAccess
- Returns:
- 3 if elevation enabled. 2 otherwise
-
ensureNode
public void ensureNode(int nodeId) Description copied from interface:PointAccess
This method ensures that the node with the specified index exists i.e. allocates space for it.- Specified by:
ensureNode
in interfacePointAccess
-
setNode
public void setNode(int nodeId, double lat, double lon, double ele) Description copied from interface:PointAccess
This method ensures that the node with the specified index exists and prepares access to it. The index goes from 0 (inclusive) to graph.getNodes() (exclusive)This methods sets the latitude, longitude and elevation to the specified value.
- Specified by:
setNode
in interfacePointAccess
-
set
public void set(int index, double lat, double lon, double ele) -
add
public void add(double lat, double lon) -
add
public void add(double lat, double lon, double ele) -
add
-
add
-
add
-
removeLastPoint
public void removeLastPoint() -
size
public int size() -
isEmpty
public boolean isEmpty() -
getLat
public double getLat(int index) - Specified by:
getLat
in interfacePointAccess
- Returns:
- the latitude at the specified node index
-
getLon
public double getLon(int index) - Specified by:
getLon
in interfacePointAccess
- Returns:
- the longitude at the specified node index
-
getEle
public double getEle(int index) Description copied from interface:PointAccess
Returns the elevation of the specified nodeId.- Specified by:
getEle
in interfacePointAccess
-
setElevation
public void setElevation(int index, double ele) -
reverse
public void reverse() -
clear
public void clear() -
trimToSize
public void trimToSize(int newSize) -
toString
-
fromLineString
-
toLineString
public org.locationtech.jts.geom.LineString toLineString(boolean includeElevation) -
getCachedLineString
public org.locationtech.jts.geom.LineString getCachedLineString(boolean includeElevation) -
equals
-
equalsEps
public static boolean equalsEps(double d1, double d2) -
equalsEps
public static boolean equalsEps(double d1, double d2, double epsilon) -
clone
Clones this PointList. If this PointList was immutable, the cloned will be mutable. If this PointList was aShallowImmutablePointList
, the cloned PointList will be a regular PointList. -
copy
This method does a deep copy of this object for the specified range.- Parameters:
from
- the copying of the old PointList starts at this indexend
- the copying of the old PointList ends at the index before (i.e. end is exclusive)
-
shallowCopy
Create a shallow copy of this Pointlist from from to end, excluding end.- Parameters:
makeImmutable
- makes this PointList immutable. If you don't ensure the consistency it might happen that due to changes of this object, the shallow copy might contain incorrect or corrupt data.
-
hashCode
public int hashCode() -
parse2DJSON
Takes the string from a json array ala [lon1,lat1], [lon2,lat2], ... and fills the list from it. -
get
-
iterator
-
from
-
isImmutable
public boolean isImmutable() -
makeImmutable
Once immutable, there is no way to make this object mutable again. This is done to ensure the consistency of shallow copies. If you need to modify this object again, you have to create a deep copy of it.
-