Class PointList

java.lang.Object
com.graphhopper.util.PointList
All Implemented Interfaces:
PointAccess, Iterable<GHPoint3D>
Direct Known Subclasses:
ShallowImmutablePointList

public class PointList extends Object implements Iterable<GHPoint3D>, PointAccess
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 Details

    • EMPTY

      public static final PointList 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 interface PointAccess
      Returns:
      true if elevation data is stored and can be retrieved
    • getDimension

      public int getDimension()
      Specified by:
      getDimension in interface PointAccess
      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 interface PointAccess
    • 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 interface PointAccess
    • 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

      public void add(PointAccess nodeAccess, int index)
    • add

      public void add(GHPoint point)
    • add

      public void add(PointList points)
    • removeLastPoint

      public void removeLastPoint()
    • size

      public int size()
    • isEmpty

      public boolean isEmpty()
    • getLat

      public double getLat(int index)
      Specified by:
      getLat in interface PointAccess
      Returns:
      the latitude at the specified node index
    • getLon

      public double getLon(int index)
      Specified by:
      getLon in interface PointAccess
      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 interface PointAccess
    • setElevation

      public void setElevation(int index, double ele)
    • reverse

      public void reverse()
    • clear

      public void clear()
    • trimToSize

      public void trimToSize(int newSize)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • fromLineString

      public static PointList fromLineString(org.locationtech.jts.geom.LineString lineString)
    • toLineString

      public org.locationtech.jts.geom.LineString toLineString(boolean includeElevation)
    • getCachedLineString

      public org.locationtech.jts.geom.LineString getCachedLineString(boolean includeElevation)
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • equalsEps

      public static boolean equalsEps(double d1, double d2)
    • equalsEps

      public static boolean equalsEps(double d1, double d2, double epsilon)
    • clone

      public PointList clone(boolean reverse)
      Clones this PointList. If this PointList was immutable, the cloned will be mutable. If this PointList was a ShallowImmutablePointList, the cloned PointList will be a regular PointList.
    • copy

      public PointList copy(int from, int end)
      This method does a deep copy of this object for the specified range.
      Parameters:
      from - the copying of the old PointList starts at this index
      end - the copying of the old PointList ends at the index before (i.e. end is exclusive)
    • shallowCopy

      public PointList shallowCopy(int from, int end, boolean makeImmutable)
      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()
      Overrides:
      hashCode in class Object
    • parse2DJSON

      public void parse2DJSON(String str)
      Takes the string from a json array ala [lon1,lat1], [lon2,lat2], ... and fills the list from it.
    • get

      public GHPoint3D get(int index)
    • iterator

      public Iterator<GHPoint3D> iterator()
      Specified by:
      iterator in interface Iterable<GHPoint3D>
    • from

      public static PointList from(org.locationtech.jts.geom.LineString lineString)
    • isImmutable

      public boolean isImmutable()
    • makeImmutable

      public PointList 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.