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 TypeMethodDescriptionvoidadd(double lat, double lon) voidadd(double lat, double lon, double ele) voidadd(PointAccess nodeAccess, int index) voidvoidvoidclear()clone(boolean reverse) Clones this PointList.copy(int from, int end) This method does a deep copy of this object for the specified range.voidensureNode(int nodeId) This method ensures that the node with the specified index exists i.e.booleanstatic booleanequalsEps(double d1, double d2) static booleanequalsEps(double d1, double d2, double epsilon) static PointListfrom(org.locationtech.jts.geom.LineString lineString) static PointListfromLineString(org.locationtech.jts.geom.LineString lineString) get(int index) org.locationtech.jts.geom.LineStringgetCachedLineString(boolean includeElevation) intdoublegetEle(int index) Returns the elevation of the specified nodeId.doublegetLat(int index) doublegetLon(int index) inthashCode()booleanis3D()booleanisEmpty()booleaniterator()Once immutable, there is no way to make this object mutable again.voidparse2DJSON(String str) Takes the string from a json array ala [lon1,lat1], [lon2,lat2], ...voidvoidreverse()voidset(int index, double lat, double lon, double ele) voidsetElevation(int index, double ele) voidsetNode(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.intsize()org.locationtech.jts.geom.LineStringtoLineString(boolean includeElevation) toString()voidtrimToSize(int newSize) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods 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:
is3Din interfacePointAccess- Returns:
- true if elevation data is stored and can be retrieved
-
getDimension
public int getDimension()- Specified by:
getDimensionin interfacePointAccess- Returns:
- 3 if elevation enabled. 2 otherwise
-
ensureNode
public void ensureNode(int nodeId) Description copied from interface:PointAccessThis method ensures that the node with the specified index exists i.e. allocates space for it.- Specified by:
ensureNodein interfacePointAccess
-
setNode
public void setNode(int nodeId, double lat, double lon, double ele) Description copied from interface:PointAccessThis 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:
setNodein 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:
getLatin interfacePointAccess- Returns:
- the latitude at the specified node index
-
getLon
public double getLon(int index) - Specified by:
getLonin interfacePointAccess- Returns:
- the longitude at the specified node index
-
getEle
public double getEle(int index) Description copied from interface:PointAccessReturns the elevation of the specified nodeId.- Specified by:
getElein 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.
-