Class GeometryUtil

java.lang.Object
com.kheops.jmap.spatial.GeometryUtil

public class GeometryUtil extends Object
This class utility provides static methods to perform geometry operations defined in the Open Geospatial Consortium Simple feature model.
  • Field Details

    • MAX_DIST_TRESHOLD

      public static final double MAX_DIST_TRESHOLD
      precision used for Point-Point equality
      See Also:
    • DEG_TO_RAD

      public static final double DEG_TO_RAD
      Constant which defines the ratio used to convert degrees into radians,
      See Also:
    • RAD_TO_DEG

      public static final double RAD_TO_DEG
      Constant which defines the ratio used to convert radians into degrees,
      See Also:
    • EARTH_RADIUS

      public static final double EARTH_RADIUS
      Constant which defines the earth radius in meters for the WGS84 datum used for Longitude/Latitude projection.
      See Also:
    • TWO_PI

      public static final double TWO_PI
      Constant which defines the value for (2 * PI).
      See Also:
    • DEGREE

      public static final int DEGREE
      Constant for the degree unit.
      See Also:
    • RADIAN

      public static final int RADIAN
      Constant for the radian unit.
      See Also:
    • CLOCKWISE

      public static final int CLOCKWISE
      Constant for the clockwise direction.
      See Also:
    • COUNTERCLOCKWISE

      public static final int COUNTERCLOCKWISE
      Constant for the counterclockwise direction.
      See Also:
  • Constructor Details

    • GeometryUtil

      public GeometryUtil()
  • Method Details

    • contains

      public static boolean contains(Point a, Point b)
      Tests if the first point contains the second point.
      Parameters:
      a - point 1.
      b - point 2.
      Returns:
      true if a contains b, false otherwise.
    • contains

      public static boolean contains(Point a, Point b, PrecisionModel precisionModel)
      Tests if the first point contains the second point.
      Parameters:
      a - point 1.
      b - point 2.
      precisionModel - the precision model to use.
      Returns:
      true if a contains b, false otherwise.
    • contains

      public static boolean contains(Line line, Point c, PrecisionModel precisionModel)
      Tests if a line contains a point.
      Parameters:
      line - line.
      c - point.
      precisionModel - the precision model to use.
      Returns:
      true if line contains c, false otherwise.
    • contains

      public static boolean contains(Point a, Point b, Point c)
      Tests if a line defined by 2 points a and b contains point c.
      Parameters:
      a - line start point.
      b - line end point.
      c - point.
      Returns:
      true if line a-b contains c, false otherwise.
    • contains

      public static boolean contains(Point a, Point b, Point c, PrecisionModel precisionModel)
      Tests if a line defined by 2 points a and b contains point c.
      Parameters:
      a - line start point.
      b - line end point.
      c - point.
      Returns:
      true if line a-b contains c, false otherwise.
    • contains

      public static boolean contains(LineString lineString, Point c)
      Tests if a linestring contains a point.
      Parameters:
      lineString - the linestring.
      c - point.
      Returns:
      true if line contains c, false otherwise.
    • contains

      public static boolean contains(LineString lineString, Point coord, PrecisionModel precisionModel)
      Tests if a linestring contains a point.
      Parameters:
      lineString - the linestring.
      coord - the point to test.
      precisionModel - the precision model to use.
      Returns:
      true if line contains coord, false otherwise.
    • contains

      public static boolean contains(Point coord, LineString lineString, PrecisionModel precisionModel)
    • contains

      public static boolean contains(LineString l1, LineString l2)
      Tests if the first linestring contains the second linestring.
      Parameters:
      l1 - the first linestring.
      l2 - the second linestring.
      Returns:
      true if the second linestring is included in the first linestring, false otherwise.
    • contains

      public static boolean contains(LineString l1, LineString l2, PrecisionModel precisionModel)
      Tests if the first linestring contains the second linestring.
      Parameters:
      l1 - the first linestring.
      l2 - the second linestring.
      Returns:
      true if the second linestring is included in the first linestring, false otherwise.
    • contains

      public static boolean contains(Polygon poly, LineString lineString, PrecisionModel precisionModel)
      Parameters:
      poly - polygon
      lineString - line string
      Returns:
      true if poly contains lineString, false otherwise
    • contains

      public static boolean contains(Polygon poly, Ellipse ellipse, PrecisionModel precisionModel)
    • contains

      public static boolean contains(Polygon poly, Rectangle rect, PrecisionModel precisionModel)
    • contains

      public static boolean contains(Polygon poly, Point c, PrecisionModel precisionModel)
      Tests whether the specified point in contained by the specified polygon. To be contained, the point must be in the interior of the polygon.
      Parameters:
      poly - the polygon to use.
      c - the point to test.
      precisionModel - the precision model to use.
      Returns:
      true if the specified point is contained by the polygon.
    • contains

      public static boolean contains(Ellipse ellipse, Point coord, PrecisionModel precisionModel)
    • contains

      public static boolean contains(Ellipse ellipse, LineString line, PrecisionModel precisionModel)
    • contains

      public static boolean contains(Ellipse ellipse, Polygon poly, PrecisionModel precisionModel)
    • contains

      public static boolean contains(Ellipse ellipse1, Ellipse ellipse2, PrecisionModel precisionModel)
      Tests if the first ellipse contains the second ellipse.
      Parameters:
      ellipse1 - the first ellipse.
      ellipse2 - the second ellipse.
      Returns:
      true if the second ellipse is included in the first ellipse, false otherwise.
    • contains

      public static boolean contains(Rectangle r1, Rectangle r2, PrecisionModel precisionModel)
      Tests if the first rectangle contains the second rectangle.
      Parameters:
      r1 - the first rectangle.
      r2 - the second rectangle.
      Returns:
      true if the second rectangle is included in the first rectangle, false otherwise.
    • contains

      public static boolean contains(Rectangle rect, Point coord, PrecisionModel precisionModel)
    • contains

      public static boolean contains(Ellipse ellipse, Rectangle rect, PrecisionModel precisionModel)
    • contains

      public static boolean contains(Ellipse ellipse, double x, double y, PrecisionModel precisionModel)
    • intersects

      public static boolean intersects(Polygon poly, Point c, PrecisionModel precisionModel)
    • contains

      public static boolean contains(Point c, Polygon poly)
      Checks if a Point contains a Polygon : false
      Returns:
      false
    • contains

      public static boolean contains(Point c, Polygon poly, PrecisionModel precisionModel)
    • contains

      public static boolean contains(Polygon poly1, Polygon poly2)
    • contains

      public static boolean contains(Polygon poly1, Polygon poly2, PrecisionModel precisionModel)
    • contains

      public static boolean contains(Point[] coords, Point coord)
      Verifies if a polygon contains the specified coordinates within it's closed region.
      Parameters:
      coords - the array of coordinates representing the polygon's edge.
      coord - the point for which we want to find out if it is contained in the polygon.
      Returns:
      true if the coord is within the polygon's closed region, false otherwise
    • contains

      public static boolean contains(Point[] coords, Point coord, PrecisionModel precisionModel)
      Verifies if a polygon contains the specified coordinates within it's closed region.
      Parameters:
      coords - the array of coordinates representing the polygon's edge.
      coord - the point for which we want to find out if it is contained in the polygon.
      Returns:
      true if the coord is within the polygon's closed region, false otherwise
    • spatiallyEquals

      public static boolean spatiallyEquals(Geometry geometry1, Geometry geometry2)
    • spatiallyEquals

      public static boolean spatiallyEquals(Geometry geometry1, Geometry geometry2, PrecisionModel precisionModel)
    • disjoint

      public static boolean disjoint(Geometry geometry1, Geometry geometry2)
      test "disjoint" relationship as defined in OpenGIS : Simple Features Specification For SQL available at www.opengis.org defined as !intersects(geometry1,geometry2) the worst case is guaranteed n*log(n) time cost
      Returns:
      true if geometry1 is disjoint of geometry2
    • disjoint

      public static boolean disjoint(Geometry geometry1, Geometry geometry2, PrecisionModel precisionModel)
      test "disjoint" relationship as defined in OpenGIS : Simple Features Specification For SQL available at www.opengis.org defined as !intersects(geometry1,geometry2) the worst case is guaranteed n*log(n) time cost
      Returns:
      true if geometry1 is disjoint of geometry2
    • intersects

      public static boolean intersects(Point a, Point b, PrecisionModel precisionModel)
    • intersects

      public static boolean intersects(Point a, LineString l, PrecisionModel precisionModel)
    • intersects

      public static boolean intersects(LineString l, Point a, PrecisionModel precisionModel)
    • intersects

      public static boolean intersects(Rectangle r1, Rectangle r2, PrecisionModel precisionModel)
    • intersects

      public static boolean intersects(Point a, Polygon poly, PrecisionModel precisionModel)
    • intersects

      public static boolean intersects(LineString l1, LineString l2, PrecisionModel precisionModel)
      Tests if 2 LineStrings intersect
    • intersects

      public static boolean intersects(LineString l, Polygon poly, PrecisionModel precisionModel)
      Tests if a LineString intersects a Polygon
    • intersects

      public static boolean intersects(Polygon poly, LineString l, PrecisionModel precisionModel)
      Tests if a polygon intersects a linestring.
    • intersects

      public static boolean intersects(Polygon poly1, Polygon poly2, PrecisionModel precisionModel)
      Tests if 2 Polygons intersect
    • intersects

      public static boolean intersects(Geometry geometry1, Geometry geometry2)
      test "intersects" relationship as defined in OpenGIS : Simple Features Specification For SQL available at www.opengis.org the worst case is guaranteed n*log(n) time cost
      Returns:
      true if geometry1 intersects geometry2
    • intersects

      public static boolean intersects(Geometry geometry1, Geometry geometry2, PrecisionModel precisionModel)
      test "intersects" relationship as defined in OpenGIS : Simple Features Specification For SQL available at www.opengis.org the worst case is guaranteed n*log(n) time cost
      Returns:
      true if geometry1 intersects geometry2
    • intersects

      public static boolean intersects(Point a, Point b, Point c, Point d, Point intersectPt)
    • intersects

      public static boolean intersects(Point a, Point b, Point c, Point d, PrecisionModel precisionModel, Point intersectPt)
      This method tests for an intersection between the line segments defined by a-b and c-d. If the lines intersect at a signe point (segments cross), the intersection point is set in output parameter pt. If the lines overlap, only one point of the overlapping part is returned.
      Parameters:
      a - first point of first segment
      b - second point of first segment
      c - first point of second segment
      d - second point of second segment
      precisionModel - the precision model to use.
      intersectPt - intersection point (output parameter)
      Returns:
      true if line segments intersect or overlap
    • intersects

      public static boolean intersects(Point center, double radius, Geometry geometry)
    • intersects

      public static boolean intersects(Point center, double radius, Geometry geometry, PrecisionModel precisionModel)
    • intersects

      public static boolean intersects(Point center, double radius, LinearRing[] rings)
      This method checks if a circle intersects a polygon
      Parameters:
      center - the K2DCoord instance that represents the center of the circle
      radius - the radius of the corresponding circle
      Returns:
      the boolean value result.
    • intersects

      public static boolean intersects(Point center, double radius, LinearRing[] rings, PrecisionModel precisionModel)
      This method checks if a circle intersects a polygon
      Parameters:
      center - the K2DCoord instance that represents the center of the circle
      radius - the radius of the corresponding circle
      Returns:
      the boolean value result.
    • intersects

      public static boolean intersects(Point center, double radius, LineString line)
      Tests if specified circle area touches at any point the specifies polyline.
      Parameters:
      center - the center coordinate of the circle
      radius - the radius of the circle
      line - the polyline for which we want to test the intersection
      Returns:
      true if the circle and polyline intersect, false otherwise
    • intersects

      public static boolean intersects(Point center, double radius, LineString line, PrecisionModel precisionModel)
      Tests if specified circle area touches at any point the specifies polyline.
      Parameters:
      center - the center coordinate of the circle
      radius - the radius of the circle
      line - the polyline for which we want to test the intersection
      Returns:
      true if the circle and polyline intersect, false otherwise
    • intersects

      public static boolean intersects(Point center, double radius, Rectangle rect)
      This method check if a circle intersects a rectangle.
      Parameters:
      center - the center of the circle
      radius - the radius of the circle
      rect - the corresponding rectangle
      Returns:
      true if the circle and rectangle intersect, false otherwise
    • intersects

      public static boolean intersects(Point center, double radius, Rectangle rect, PrecisionModel precisionModel)
      This method check if a circle intersects a rectangle.
      Parameters:
      center - the center of the circle
      radius - the radius of the circle
      rect - the corresponding rectangle
      Returns:
      true if the circle and rectangle intersect, false otherwise
    • touches

      public static boolean touches(Geometry geometry1, Geometry geometry2)
      test "touches" relationship as defined in OpenGIS : Simple Features Specification For SQL available at www.opengis.org
      Returns:
      true if geometry1 touches geometry2
    • touches

      public static boolean touches(Geometry geometry1, Geometry geometry2, PrecisionModel precisionModel)
      test "touches" relationship as defined in OpenGIS : Simple Features Specification For SQL available at www.opengis.org
      Returns:
      true if geometry1 touches geometry2
    • crosses

      public static boolean crosses(Geometry geometry1, Geometry geometry2)
      test "crosses" relationship as defined in OpenGIS : Simple Features Specification For SQL available at www.opengis.org uses relate() method
      Returns:
      true if geometry1 crosses geometry2
    • crosses

      public static boolean crosses(Geometry geometry1, Geometry geometry2, PrecisionModel precisionModel)
      test "crosses" relationship as defined in OpenGIS : Simple Features Specification For SQL available at www.opengis.org uses relate() method
      Returns:
      true if geometry1 crosses geometry2
    • within

      public static boolean within(Geometry geometry1, Geometry geometry2)
      test "within" relationship as defined in OpenGIS : Simple Features Specification For SQL available at www.opengis.org uses contains() method
      Returns:
      true if geometry1 is within geometry2
    • within

      public static boolean within(Geometry geometry1, Geometry geometry2, PrecisionModel precisionModel)
      test "within" relationship as defined in OpenGIS : Simple Features Specification For SQL available at www.opengis.org uses contains() method
      Returns:
      true if geometry1 is within geometry2
    • contains

      public static boolean contains(Geometry geometry1, Geometry geometry2)
      test "contains" relationship as defined in OpenGIS : Simple Features Specification For SQL available at www.opengis.org
      Returns:
      true if geometry1 contains geometry2
    • contains

      public static boolean contains(Geometry geometry1, Geometry geometry2, PrecisionModel precisionModel)
      test "contains" relationship as defined in OpenGIS : Simple Features Specification For SQL available at www.opengis.org
      Returns:
      true if geometry1 contains geometry2
    • intersects

      public static boolean intersects(Ellipse ellipse1, Ellipse ellipse2, PrecisionModel precisionModel)
    • intersects

      public static boolean intersects(Ellipse ellipse, Polygon polygon, PrecisionModel precisionModel)
    • intersects

      public static boolean intersects(Ellipse ellipse, LineString lineString, PrecisionModel precisionModel)
    • intersects

      public static boolean intersects(Ellipse ellipse, Point point, PrecisionModel precisionModel)
    • intersects

      public static boolean intersects(Ellipse ellipse, Rectangle rect, PrecisionModel precisionModel)
    • overlaps

      public static boolean overlaps(Geometry geometry1, Geometry geometry2)
      Tests "overlaps" relationship as defined in OpenGIS : Simple Features Specification For SQL available at www.opengis.org uses relate() method
      Returns:
      true if geometry1 overlaps geometry2
    • overlaps

      public static boolean overlaps(Geometry geometry1, Geometry geometry2, PrecisionModel precisionModel)
      Tests "overlaps" relationship as defined in OpenGIS : Simple Features Specification For SQL available at www.opengis.org uses relate() method
      Returns:
      true if geometry1 overlaps geometry2
    • relate

      public static boolean relate(Geometry geometry1, Geometry geometry2, char[] matrix)
      Tests relationship between two given geometries defined by the matrix DE-9IM The syntax used is described in the document : OpenGIS : Simple Features Specification For SQL available at www.opengis.org Computes the intersection matrix elements only when it is needed, according to the parameter matrix
      Returns:
      true if the intersection matrix defined by g1 and g2 fits the param matrix
    • relate

      public static boolean relate(Geometry geometry1, Geometry geometry2, char[] matrix, PrecisionModel precisionModel)
      Tests relationship between two given geometries defined by the matrix DE-9IM The syntax used is described in the document : OpenGIS : Simple Features Specification For SQL available at www.opengis.org Computes the intersection matrix elements only when it is needed, according to the parameter matrix
      Returns:
      true if the intersection matrix defined by g1 and g2 fits the param matrix
    • buffer

      public static Geometry buffer(Geometry geometry, double distance, double angleStepUser)
      Computes the set of points whose distance to geometry is less than distance.
      if the geometry is a collection, it computes the buffer of each element and merge the results
      Parameters:
      angleStepUser - : the step in radian to approximate circles ; if 0 then default value is Pi*3/180 (ie 3 deg)
    • buffer

      public static Geometry buffer(Geometry geometry, double distance, double angleStepUser, PrecisionModel precisionModel)
      Computes the set of points whose distance to geometry is less than distance.
      if the geometry is a collection, it computes the buffer of each element and merge the results
      Parameters:
      angleStepUser - : the step in radian to approximate circles ; if 0 then default value is Pi*3/180 (ie 3 deg)
    • buffer

      public static Geometry buffer(Geometry geometry, Projection mapProjection, double distance, double angleStepUser, PrecisionModel precisionModel)
      Computes the set of points whose distance to geometry is less than distance.
      if the geometry is a collection, it computes the buffer of each element and merge the results
      Parameters:
      angleStepUser - : the step in radian to approximate circles ; if 0 then default value is Pi*3/180 (ie 3 deg)
    • convexHull

      public static Geometry convexHull(Geometry geometry, boolean oneForCollection)
      Computes the convexHull of a geometry
      Parameters:
      oneForCollection - : if geometry is a collection : if true, then one polygon is returned, else one for each element
    • convexHull

      public static Geometry convexHull(Geometry geometry, boolean oneForCollection, PrecisionModel precisionModel)
      Computes the convexHull of a geometry
      Parameters:
      oneForCollection - : if geometry is a collection : if true, then one polygon is returned, else one for each element
    • intersection

      public static Geometry intersection(Geometry geometry1, Geometry geometry2)
      Compute the intersection between two Geometries basically just calls the correct method according to argument class
    • intersection

      public static Geometry intersection(Geometry geometry1, Geometry geometry2, PrecisionModel precisionModel)
      Compute the intersection between two Geometries basically just calls the correct method according to argument class
    • union

      public static Geometry union(Geometry geometry1, Geometry geometry2)
      Compute the union between two Geometries basically just calls the correct method according to argument class
    • union

      public static Geometry union(Geometry geometry1, Geometry geometry2, PrecisionModel precisionModel)
      Compute the union between two Geometries basically just calls the correct method according to argument class
    • unionMultiple

      public static Geometry unionMultiple(Geometry[] geometries)
      Fast method to merge many geometries
      It executes a binary union.
    • unionMultiple

      public static Geometry unionMultiple(Geometry[] geometries, PrecisionModel precisionModel)
      Fast method to merge many geometries
      It executes a binary union.
    • intersectionMultiple

      public static Geometry intersectionMultiple(Geometry[] geometries)
      Fast method to intersect many geometries
      It executes a binary intersection
    • intersectionMultiple

      public static Geometry intersectionMultiple(Geometry[] geometries, PrecisionModel precisionModel)
      Fast method to intersect many geometries
      It executes a binary intersection
    • difference

      public static Geometry difference(Geometry geometry1, Geometry geometry2)
      Compute the difference between two Geometries basically just calls the correct method according to argument class
    • difference

      public static Geometry difference(Geometry geometry1, Geometry geometry2, PrecisionModel precisionModel)
      Compute the difference between two Geometries basically just calls the correct method according to argument class
    • diffSym

      public static Geometry diffSym(Geometry geometry1, Geometry geometry2)
      Compute the symmetric difference between two Geometries basically just calls the correct method according to argument class
    • diffSym

      public static Geometry diffSym(Geometry geometry1, Geometry geometry2, PrecisionModel precisionModel)
      Compute the symmetric difference between two Geometries basically just calls the correct method according to argument class
    • ringDirection

      public static int ringDirection(LinearRing l)
      The orientation of a linearRing. 1 is clockwise, -1 anti-clockwise
    • inverseRingDirection

      public static LinearRing inverseRingDirection(LinearRing l)
      Change the orientation of a linearRing.
      Parameters:
      l -
      Returns:
      LinearRing in opposite direction.
    • createCircle

      public static Ellipse createCircle(Point p1, Point p2, Point p3)
      Creates a new circle with the specified coordinates. The specified coordinates must be disjoint and must be located on the circumference of the circle.
      Parameters:
      p1 - the first coordinate.
      p2 - the second coordinate.
      p3 - the third coordinate.
      Returns:
      the newly created circular ellipse.
    • ellipseToPolyline

      public static Point.Double[] ellipseToPolyline(double Cx, double Cy, double a, double b, double angle, double startAngle, double endAngle, int geometryType)
      This function converts an ellipse or arc to a line or polygon. By default the resulting point[] coordinates are counter clockwise.
      Parameters:
      Cx - the center point's X coordinate.
      Cy - the center point's Y coordinate.
      a - the bigger axis
      b - the smaller axis
      angle - the inclination angle in degrees, clockwise
      startAngle - the starting angle of the sweep in degrees. Starts on right x axis, counterclockwise
      endAngle - the ending angle of the sweep in degrees. Starts on right x axis, counterclockwise
      geometryType - the geometry type
      Returns:
      A set of points which defines a curve or a surface
      See Also:
    • ellipseToPolyline

      public static Point.Double[] ellipseToPolyline(double Cx, double Cy, double a, double b, double angle, double startAngle, double endAngle, int geometryType, boolean ccw)
      This function converts an ellipse or arc to a line or polygon.
      Parameters:
      Cx - the center point's X coordinate.
      Cy - the center point's Y coordinate.
      a - the bigger axis
      b - the smaller axis
      angle - the inclination angle in degrees, clockwise
      startAngle - the starting angle of the sweep in degrees. Starts on right x axis, counterclockwise
      endAngle - the ending angle of the sweep in degrees. Starts on right x axis, counterclockwise
      geometryType - the geometry type
      ccw - true if resulting point[] direction is counterclockwise, false if clockwise
      Returns:
      A set of points which defines a curve or a surface
      See Also:
    • getAngleAtPoint

      public static double getAngleAtPoint(LineTypeGeometry geometry, Point WCCoord, Point intersectPt)
      Returns the positive angle in degrees (0-360) of the line or polyline at the intersection of a segment of the polyline and a vertical or horizontal line passing through the specified coordinate. If the lines don't intersect, -1 is returned. If there is more than one intersection, the closest one to WCCoord is used and placed in output parameter intersectPt.
      Parameters:
      WCCoord - the coordinate where to find the angle
      intersectPt - optional output parameter that will contain the closest intersection point if any
      Returns:
      the positive angle in degrees or -1 if line segments don't intersect
    • getAngle

      public static double getAngle(double x1, double y1, double x2, double y2)
      Returns the angle in degrees at the point x1,y1 for a line going from x1,y1 to x2,y2
      Parameters:
      x1 - x coordinate of Point1
      y1 - y coordinate of Point1
      x2 - x coordinate of Point2
      y2 - y coordinate of Point2
      Returns:
      angle at first x,y coordinates
    • findInterpolatedPoint

      public static double findInterpolatedPoint(LineTypeGeometry lineGeometry, double percent, Point resultPoint)
      This method find the point being at a certain percentage of the path between the starting point and the final point
      Parameters:
      percent - the value of the percentage expressed as a float between 0 and 1
      resultPoint - the K2DCoord instance that will serve to store the result
      Returns:
      the angle between the horizontal line and the line segment containing the result point
    • distance

      public static double distance(Geometry geometry1, Geometry geometry2)
    • distance

      public static double distance(Geometry geometry1, Geometry geometry2, PrecisionModel precisionModel)
    • distance

      public static double distance(Point p0, Point p1, PrecisionModel precisionModel)
      This method calculates the distance between 2 coordinates.
      Parameters:
      p0 - the first coordinate
      p1 - the second coordinate
      Returns:
      the distance between the two coordinates
    • distance

      public static double distance(Point p0, Point p1)
      This method calculates the distance between 2 coordinates.
      Parameters:
      p0 - the first coordinate
      p1 - the second coordinate
      Returns:
      the distance between the two coordinates
    • distance

      public static double distance(double x0, double y0, double x1, double y1)
      This method calculates the distance between 2 coordinates.
      Parameters:
      x0 - the first coordinate X value.
      y0 - the first coordinate Y value.
      x1 - the second coordinate X value.
      y1 - the second coordinate Y value.
      Returns:
      the distance between the two coordinates
    • distance

      public static double distance(Point p, Point a, Point b)
    • distance

      public static double distance(Point p, Point a, Point b, PrecisionModel precisionModel)
      Calculates the distance from a point to a segment defined as [ab]
    • distance

      public static double distance(Point a, Point b, Point c, Point d)
    • distance

      public static double distance(Point a, Point b, Point c, Point d, PrecisionModel precisionModel)
      Calculates the distance between 2 segments [ab] and [cd]
    • distance

      public static double distance(Point p, LineString l, PrecisionModel precisionModel)
      Calculates the distance from a point to LineString
      brute force, computes distance to each segment possible optimization : computes the square distance of each segment (without doing sqrt)
    • distance

      public static double distance(LineString l, Point p, PrecisionModel precisionModel)
    • distance

      public static double distance(Point p, Polygon poly, PrecisionModel precisionModel)
      Calculates the distance from a point to polygon
    • distance

      public static double distance(Point p, Ellipse ellipse, PrecisionModel precisionModel)
    • distance

      public static double distance(Polygon poly, Point p, PrecisionModel precisionModel)
    • distance

      public static double distance(Polygon poly1, Polygon poly2, PrecisionModel precisionModel)
      Calculates the distance between 2 polygons
    • distance

      public static double distance(Polygon poly, Rectangle rect, PrecisionModel precisionModel)
    • distance

      public static double distance(Rectangle rect, Ellipse ellipse, PrecisionModel precisionModel)
    • distance

      public static double distance(Polygon poly, Ellipse ellipse, PrecisionModel precisionModel)
    • distance

      public static double distance(LineString l1, LineString l2, PrecisionModel precisionModel)
      Calculates the distance between 2 LineStrings
    • distance

      public static double distance(LineString ls, Polygon poly, PrecisionModel precisionModel)
      Calculates the distance between a LineString and a Polygon
    • distance

      public static double distance(LineString ls, Ellipse ellipse, PrecisionModel precisionModel)
    • distance

      public static double distance(Ellipse ellipse1, Ellipse ellipse2, PrecisionModel precisionModel)
    • distance

      public static double distance(Polygon poly, LineString ls, PrecisionModel precisionModel)
    • sphericalDistance

      public static double sphericalDistance(Point c1, Point c2)
    • sphericalDistance

      public static double sphericalDistance(double long1, double lati1, double long2, double lati2)
      This method calculates the distance in meters between 2 points in longitude and latitude.
      Parameters:
      long1 - the first coordinate longitude in degrees
      lati1 - the first coordinate latitude in degrees
      long2 - the second coordinate longitude in degrees
      lati2 - the second coordinate latitude in degrees
      Returns:
      the distance between two points in meters
    • computeDistance

      public static double computeDistance(Point coord1, Point coord2, Projection mapProjection, JMapUnit mapUnit, Projection measurementProjection, JMapUnit distanceUnit)
      Computes the distance between the two specified coordinates. If the map projection is defined but the measurement projection is not cartesian, the computed distance will use the Vincenty formula. Otherwise, specified coordinates will be projected, if possible, to the measurement projection to compute the cartesian distance.
      Parameters:
      coord1 - the first coordinate.
      coord2 - the second coordinate.
      mapProjection - the projection of the coordinates.
      mapUnit - the current map unit.
      measurementProjection - the projection to use while computing the distance.
      distanceUnit - the value will be returned in that unit.
      Returns:
      the computed distance in the specified unit.
    • computeArea

      public static double computeArea(PolygonTypeGeometry surface, Projection mapProjection, JMapUnit mapUnit, Projection measurementProjection, JMapUnit distanceUnit)
    • distVincenty

      public static double distVincenty(Projection projection, double lon1, double lat1, double lon2, double lat2)
      Calculates geodesic distance (in m) between two points specified by latitude/longitude (in numeric degrees) using Vincenty inverse formula for ellipsoids
      Parameters:
      projection - map projection
      lon1 - the first coordinate longitude in degrees
      lat1 - the first coordinate latitude in degrees
      lon2 - the second coordinate longitude in degrees
      lat2 - the second coordinate latitude in degrees
      Returns:
      the distance between two points in meters
    • distVincenty

      public static double distVincenty(Projection projection, Point c1, Point c2)
    • intersects

      public static boolean intersects(Point startPoint1, Point endPoint1, Point startPoint2, Point endPoint2)
    • intersects

      public static boolean intersects(double x1, double y1, double x2, double y2, double xA, double yA, double xB, double yB)
      Tests if two line segments intersect.
      Parameters:
      x1 - abscissa of the first point of the first line segment
      y1 - ordinate of the first point of the first line segment
      x2 - abscissa of the second point of the first line segment
      y2 - ordinate of the second point of the first line segment
      xA - abscissa of the first point of the second line segment
      yA - ordinate of the first point of the second line segment
      xB - abscissa of the second point of the second line segment
      yB - ordinate of the second point of the second line segment
      Returns:
      true if the two line segments intersect
    • intersects

      public static boolean intersects(double x1, double y1, double x2, double y2, double xA, double yA, double xB, double yB, PrecisionModel precisionModel)
      Tests if two line segments intersect.
      Parameters:
      x1 - abscissa of the first point of the first line segment
      y1 - ordinate of the first point of the first line segment
      x2 - abscissa of the second point of the first line segment
      y2 - ordinate of the second point of the first line segment
      xA - abscissa of the first point of the second line segment
      yA - ordinate of the first point of the second line segment
      xB - abscissa of the second point of the second line segment
      yB - ordinate of the second point of the second line segment
      Returns:
      true if the two line segments intersect
    • findPerpendicularPoint

      public static Point findPerpendicularPoint(Point lsp1, Point lsp2, Point perpPoint)
      this method finds the perpendicular point on a line to a specified point
      Parameters:
      lsp1 - pt 1 of the line
      lsp2 - pt 2 of the line
      perpPoint - a pt where the perpendicular line would pass
      Returns:
      the intersection of the perpendicular line passing thru the point
    • findPerpendicularPoint

      public static Point findPerpendicularPoint(Point lsp1, Point lsp2, Point perpPoint, PrecisionModel precisionModel)
      this method finds the perpendicular point on a line to a specified point
      Parameters:
      lsp1 - pt 1 of the line
      lsp2 - pt 2 of the line
      perpPoint - a pt where the perpendicular line would pass
      Returns:
      the intersection of the perpendicular line passing thru the point
    • intersectsOutline

      public static boolean intersectsOutline(Ellipse ellipse, double xA, double yA, double xB, double yB)
    • intersectsOutline

      public static boolean intersectsOutline(Ellipse ellipse, double xA, double yA, double xB, double yB, PrecisionModel precisionModel)
    • intersectsArc

      public static boolean intersectsArc(Ellipse ellipse, double xA, double yA, double xB, double yB)
    • intersectsArc

      public static boolean intersectsArc(Ellipse ellipse, double xA, double yA, double xB, double yB, PrecisionModel precisionModel)
    • extractLargestPolygon

      public static Polygon extractLargestPolygon(GeometryCollection collection)
      Goes through the collection of geometries and finds the largest Polygon. Used when a spatial operation returns a collection of geometries such as MultiPolygon or Complex.
      Parameters:
      collection - of geometries
      Returns:
      the largest polygon in collection
    • buildArc

      public static LineString buildArc(Point startPoint, Point midPoint, Point endPoint, Point arcCenter)
      Builds a circular arc. There are three different methods available for defining the arc: 1) Arc start point, middle point of the Arc and end point. 2) Arc start point, center of the circle, end point. 3) Arc start point, center of the circle, angle. This function is compatible for the first and the second. If the center point is null than it builds an arc through 3 points, otherwise, an arc is built using the start, center and end point.
      Parameters:
      startPoint - The start point of an arc
      midPoint - The middle point of an arc
      endPoint - The end point of an arc
      arcCenter - The center of rotation of an arc
      Returns:
      An arc converted to segments of straight lines
    • getArcCenter

      public static Point getArcCenter(Point startPoint, Point midPoint, Point endPoint)
      Finds the center of a circular Arc. Arc is defined by the start, middle and end points. This method only works for circular arcs, it is NOT compatible with elliptical arcs.
      Parameters:
      startPoint - The start point of an arc
      midPoint - The mid-point of an arc
      endPoint - The end point of an arc
      Returns:
      The center of a circle the arc is part of
    • getArcCenter

      public static Point getArcCenter(Point pt1, Point pt2, Point pt3, PrecisionModel precisionModel)
      Finds the center of a circular Arc given three points. This method only works for circular arcs, it is NOT comptible with elliptical arcs.
      Parameters:
      pt1 - The 1st point of an arc (start)
      pt2 - The 2nd point of an arc
      pt3 - The 3rd point of an arc (end)
      Returns:
      The center of the circular arc
    • isPerpendicular

      public static boolean isPerpendicular(Point pt1, Point pt2, Point pt3, PrecisionModel precisionModel)
      Verify if the given points are perpendicular to x or y axis
      Parameters:
      pt1 - first point
      pt2 - second point
      pt3 - third point
      Returns:
      true if perpendicular false if not
    • getArcDirection

      public static int getArcDirection(Point startPoint, Point midPoint, Point endPoint)
      Calculates the direction of an arc (Clockwise and counter-clockwise) starting from the point of departure, passing through the middle point, and ending at the end point
      Parameters:
      startPoint - The start point of an arc
      midPoint - The middle point of an arc
      endPoint - The end point of an arc
      Returns:
      1 if arc in the clockwise direction, -1 if arc in the counter-clockwise direction, 0 if arc is a circle
    • getAngleAtArcVertex

      @Deprecated public static double getAngleAtArcVertex(Point arcVertex, Point center, double radius)
      Finds the angle using the law of sines and adjust the angle value to the direction of a point
      Parameters:
      arcVertex - The start or the end point of an arc
      center - The center of a circle the arc is part of
      radius - The radius of a circle the arc is part of
      Returns:
      The angle at start or end point of an arc
    • getPointDirection

      @Deprecated public static int getPointDirection(double pointX, double pointY, double centerX, double centerY)
      Deprecated.
      Finds the location of a point in relation with location of another point
      Parameters:
      pointX - The point X coordinate
      pointY - The point Y coordinate
      centerX - The second point X coordinate
      centerY - The second point Y coordinate
      Returns:
      integer value representing the location of a point
    • polygonToQuadrilateral

      public static Polygon polygonToQuadrilateral(Polygon poly)
      Generalizes a polygon so that it becomes a quadrilateral - a polygon with four sides or edges and four vertices or corners.
      Parameters:
      poly - The polygon to generalize
      Returns:
      quadrilateral polygon
    • makeValid

      public static Geometry makeValid(Geometry geometry)
      Check if the geometry is valid, if not valid try to correct it Return the corrected (or not) geometry
      Parameters:
      geometry - : the geometry to check
      Returns:
      the corrected geometry, else null if not valid and not correctable