Class LineString

java.lang.Object
com.kheops.jmap.spatial.DefaultGeometry
com.kheops.jmap.spatial.LineString
All Implemented Interfaces:
Curve, Geometry, LineTypeGeometry, Serializable, Cloneable
Direct Known Subclasses:
Line, LinearRing

public class LineString extends DefaultGeometry implements Curve, LineTypeGeometry
This class represents a line made of several points.
2 Points are allowed to be equal, but a lineString can't be made of a single Point (because of topology reasons)
See Also:
  • Field Details

    • bounds

      protected Rectangle bounds
      The Bounding box
    • coords

      protected Point[] coords
      the Points defining the LineString
  • Constructor Details

    • LineString

      public LineString()
    • LineString

      public LineString(Point[] coords)
      Constructs a LineString going to each points
      Parameters:
      coords -
    • LineString

      public LineString(double[] tab)
      Constructor easier to use for testing warning : coords.length must be even number, because points are entered as x,y
      Parameters:
      tab -
  • Method Details

    • boundary

      public Geometry boundary()
      Returns the boundary, ie the startPoint() and endPoint()
      Specified by:
      boundary in interface Geometry
      Returns:
      a line string which defines the boundary of the current geometry.
    • createBounds

      public void createBounds()
      creates the bounding box
      called in the constructor, not needed from outside
      Specified by:
      createBounds in interface Geometry
    • getCoords

      public Point[] getCoords()
    • setCoords

      public void setCoords(Point[] coords)
    • numPoints

      public int numPoints()
      Returns the number of Point in this LineString
      Returns:
    • pointN

      public Point pointN(int N)
      Returns the Nth Point of this LineString
      Parameters:
      N -
      Returns:
      the Nth Point of this LineString
    • getBounds

      public Rectangle getBounds()
      Description copied from interface: Geometry
      Returns the minimum bounding rectangle of this geometry.
      Specified by:
      getBounds in interface Geometry
      Returns:
      the bounding box of this geometry.
    • clone

      public LineString clone()
      Clones this geometry.
      Specified by:
      clone in interface Curve
      Specified by:
      clone in interface Geometry
      Specified by:
      clone in class DefaultGeometry
      Returns:
      a deep copy of the current geometry.
    • serialize

      public Point[] serialize()
      Describe this LineString with his Points Respects the order of the Points
      Specified by:
      serialize in interface Geometry
      Returns:
      a list of Point describing this LineString
    • length

      public double length()
      The length of the curve
      Specified by:
      length in interface Curve
      Specified by:
      length in interface Geometry
      Returns:
    • area

      public double area()
      Description copied from interface: Geometry
      Returns the geometry area. If the geometry is not a surface, then 0 shall be returned.
      Specified by:
      area in interface Geometry
      Returns:
      the geometry area.
    • startPoint

      public Point startPoint()
      The first point of the curve
      Specified by:
      startPoint in interface Curve
      Returns:
    • endPoint

      public Point endPoint()
      The last point of the curve
      Specified by:
      endPoint in interface Curve
      Returns:
    • isClosed

      public boolean isClosed()
      Tests if the curve is closed (endPoint equals startPoint)
      Specified by:
      isClosed in interface Curve
      Specified by:
      isClosed in interface LineTypeGeometry
      Returns:
    • isRing

      public boolean isRing()
      Tests if the curve is closed and simple (doesn't intersect itself)
      Specified by:
      isRing in interface Curve
      Returns:
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • spatiallyEquals

      public boolean spatiallyEquals(Geometry o, PrecisionModel precisionModel)
      Tests if this geometry is equal to the argument, on a topological point of view.
      Specified by:
      spatiallyEquals in interface Geometry
      Parameters:
      o - the geometry to be tested.
      precisionModel - the precision model to use while comparing geometries.
      Returns:
      whether both geometries are spatially equals.
    • spatiallyEquals

      public boolean spatiallyEquals(LineString lineString, PrecisionModel precisionModel)
    • toString

      public String toString()
      Description copied from interface: Geometry
      Returns information about the current geometry.
      Specified by:
      toString in interface Geometry
      Overrides:
      toString in class Object
      Returns:
      information about the current geometry.
    • lineIterator

      public LineGeometryIterator lineIterator()
      Specified by:
      lineIterator in interface LineTypeGeometry
    • translate

      public void translate(double dx, double dy)
      Translate this geometry with the specified values.
      Specified by:
      translate in interface Geometry
      Parameters:
      dx - translation on the X-axis.
      dy - translation on the Y-axis.
    • getGeometryId

      public short getGeometryId()
      Returns the geometry class id. This method is useful for geometry serialization.
      Specified by:
      getGeometryId in interface Geometry
      Returns:
      the geometry id.
    • getGeometryType

      public int getGeometryType()
      Returns the geometry type for this geometry.
      Specified by:
      getGeometryType in interface Geometry
      Returns:
      the geometry type.
      See Also:
    • transform

      public Geometry transform(Transformation tr)
      Creates a clone of the current geometry and returns the new instance transformed with the specified geometry transformation.
      The returned geometry can be of any geometry types after the transformation.
      Specified by:
      transform in interface Geometry
      Parameters:
      tr - the transformation to apply.
      Returns:
      the newly created and transformed geometry instance.
    • pointOnLine

      public Point pointOnLine(double interpolation)
      This method finds the point being at a certain percentage of the path between the starting point and the final point.
      Parameters:
      interpolation - the interpolation expressed as a percentage (between 0 and 1)
      Returns:
      the reulsting point
    • getCenteredPoint

      public Point getCenteredPoint()
      This method returns a point that is typically centered on the geometry. If the geometry is a point, the point is returned. If it is a line, a point on the curve interpolated at 50% is returned. If the geometry is a surface, the centroid is returned if it is inside the polygon, if not, a point inside the polygon (but likely not exactly in the center) will be returned. If the geometry is a collection, the method is called on the first part of the collection.
      Specified by:
      getCenteredPoint in interface Geometry
      Returns:
      a point likely at the center of the geometry
    • sizeOf

      public int sizeOf()
      Returns an approximation in bytes of the memory used by this geometry.
      Specified by:
      sizeOf in interface Geometry
      Returns:
      the memory used by this geometry.