Class GeometryUtils

java.lang.Object
org.gvsig.fmap.geom.GeometryUtils

public class GeometryUtils extends Object
Author:
jjdelcerro
  • Field Details

    • ANGLE_TURN_CLOCKWISE

      public static final int ANGLE_TURN_CLOCKWISE
      A value that indicates an orientation of clockwise, or a right turn.
      See Also:
    • ANGLE_TURN_COUNTERCLOCKWISE

      public static final int ANGLE_TURN_COUNTERCLOCKWISE
      A value that indicates an orientation of counterclockwise, or a left turn.
      See Also:
    • ANGLE_TURN_NONE

      public static final int ANGLE_TURN_NONE
      A value that indicates an orientation of collinear, or no turn (straight).
      See Also:
  • Method Details

    • getGeometryType

      public static GeometryType getGeometryType(int geometryType, int geometrySubType)
    • isSubtype

      public static boolean isSubtype(int geomTypeParent, int geomTypeChild)
    • canAggregate

      public static boolean canAggregate(int geomTypeParent, int geomTypeChild)
    • createEnvelope

      public static Envelope createEnvelope(int subType)
    • createEnvelope

      public static Envelope createEnvelope(double minX, double minY, double maxX, double maxY, int subType)
    • createLine

      public static Line createLine(int subType)
    • createMultiLine

      public static MultiLine createMultiLine(int subType)
    • createPolygon

      public static Polygon createPolygon(int subType)
    • createMultiPolygon

      public static MultiPolygon createMultiPolygon(int subType)
    • createPoint

      public static Point createPoint(double x, double y)
    • createPoint

      public static Point createPoint(double x, double y, double z)
    • createPoint

      public static Point createPoint(double x, double y, double z, double m)
    • createPoint

      public static Point createPoint(Point center, double radius, double angle)
    • createFrom

      public static Geometry createFrom(Object data)
    • createFrom

      public static Geometry createFrom(String wkt, String srs)
    • createFrom

      public static Geometry createFrom(String wkt, org.gvsig.crs.projection.lib.Projection srs)
    • createFrom

      public static Geometry createFrom(String wkt)
    • convertTo

      public static Object convertTo(Geometry geom, String format)
    • toWKT

      public static String toWKT(Geometry geom)
    • toWKB

      public static byte[] toWKB(Geometry geom)
    • toEWKB

      public static byte[] toEWKB(Geometry geom)
    • intersects

      public static boolean intersects(Geometry geom1, Geometry geom2)
    • getGeometryTypeName

      public static String getGeometryTypeName(int type)
    • getGeometrySubtypeName

      public static String getGeometrySubtypeName(int subtype)
    • getGeometryType

      public static int getGeometryType(String typeName)
    • getGeometrySubtype

      public static int getGeometrySubtype(String subtype)
    • createCircle

      public static Circle createCircle(Point center, double radius, int subtype) throws CreateGeometryException
      Creates a circle as of center and radius.
      Parameters:
      center - of new circle
      radius - of new circle
      subtype - subtype of circle. See Geometry.SUBTYPES
      Returns:
      The circle created with center and radius
      Throws:
      CreateGeometryException
    • createCircle

      public static Circle createCircle(Point firstPoint, Point secondPoint, Point thirdPoint, int subtype) throws CreateGeometryException
      Creates a circle from three points.
      Parameters:
      firstPoint - of circle
      secondPoint - of circle
      thirdPoint - of circle
      subtype - subtype of circle. See Geometry.SUBTYPES
      Returns:
      The circle created from three points received as parameters.
      Throws:
      CreateGeometryException
    • createCircle

      public static Circle createCircle(Point firstPoint, Point secondPoint, Point thirdPoint, Point fourthPoint, Point fifthPoint, int subtype) throws CreateGeometryException
      Creates a circle from five points.The first two points are two points on a tangent to the circle.The next two are two points on another tangent to the circle.The last one is a point near the center of the circle.
      Parameters:
      firstPoint -
      secondPoint -
      thirdPoint -
      fourthPoint -
      fifthPoint -
      subtype - subtype of circle. See Geometry.SUBTYPES
      Returns:
      The circle created from three points received as parameters.
      Throws:
      CreateGeometryException
    • createCircle

      public static Circle createCircle(org.gvsig.euclidean.EuclideanLine2D line1, org.gvsig.euclidean.EuclideanLine2D line2, Point point, int subtype) throws CreateGeometryException
      Creates a circle from two tangents and one point.
      Parameters:
      line1 - A tangent line
      line2 - Another tangent line
      point - A point near the center of the circle.
      subtype - subtype of circle. See Geometry.SUBTYPES
      Returns:
      The circle created from two tangents and one point received as parameters.
      Throws:
      CreateGeometryException
    • createCircle

      public static Circle createCircle(Geometry geometry1, Geometry geometry2, double radius, Point firstPoint, Point secondPoint, int subtype) throws CreateGeometryException
      Creates a circle from two tangent geometries and the radius.
      Parameters:
      geometry1 - A tangent geometry
      geometry2 - Another tangent geometry
      radius - the radius of the cicle.
      firstPoint - a point near tangent point of geometry1
      secondPoint - a point near tangent point of geometry2
      subtype - subtype of circle. See Geometry.SUBTYPES
      Returns:
      The circle created from two tangent geometries and the radius received as parameters.
      Throws:
      CreateGeometryException
    • createArc

      public static Arc createArc(Point center, double radius, double startAngle, double angleExt, int subtype) throws CreateGeometryException
      Creates an arc as of center, radius, start angle and extension angle.
      Parameters:
      center - center of arc.
      radius - of arc.
      startAngle - of arc in radians
      angleExt - of arc in radians
      subtype - subtype of arc. See Geometry.SUBTYPES
      Returns:
      The arc created with center, radius, start angle and extension angle.
      Throws:
      CreateGeometryException
    • createArc

      public static Arc createArc(Point start, Point middle, Point end, int subtype) throws org.gvsig.tools.exception.BaseException
      Creates an arc as of three points.
      Parameters:
      start - point of arc
      middle - point of arc. It can be any point of arc.
      end - point of arc
      subtype - of arc. See Geometry.SUBTYPES
      Returns:
      The arc created that it start at start point, cross middle point and end at end point.
      Throws:
      org.gvsig.tools.exception.BaseException
    • createEllipse

      public static Arc createEllipse(Point firstPointAxisA, Point secondPointAxisA, double halfLengthAxisB, int subtype) throws CreateGeometryException
      Creates an ellipse from start and end point of A axis and half length of B axis.
      Parameters:
      firstPointAxisA - first point of A axis
      secondPointAxisA - second point of B axis
      halfLengthAxisB - half length of B axis
      subtype - of ellipse See Geometry.SUBTYPES
      Returns:
      The ellipse created
      Throws:
      CreateGeometryException
    • createFilledEllipse

      public static Ellipse createFilledEllipse(Point firstPointAxisA, Point secondPointAxisA, double halfLengthAxisB, int subtype) throws CreateGeometryException
      Creates a filled ellipse from start and end point of A axis and half length of B axis.
      Parameters:
      firstPointAxisA - first point of A axis
      secondPointAxisA - second point of B axis
      halfLengthAxisB - half length of B axis
      subtype - of ellipse See Geometry.SUBTYPES
      Returns:
      The ellipse created
      Throws:
      CreateGeometryException
    • getCenter

      public static Point getCenter(Point a, Point b, Point c, int subtype) throws CreateGeometryException
      Gets center point of three points.
      Parameters:
      a - Point one
      b - Point two
      c - Point three
      subtype - of point created. See Geometry.SUBTYPES
      Returns:
      Point center.
      Throws:
      CreateGeometryException
    • getMidPoint

      public static Point getMidPoint(Point a, Point b, int subtype) throws CreateGeometryException
      Gets midpoint of two points
      Parameters:
      a - Point one
      b - Point two
      subtype - of point created. See Geometry.SUBTYPES
      Returns:
      Mid point of points.
      Throws:
      CreateGeometryException
    • createLine

      public static Line createLine(double x1, double y1, double x2, double y2, int subtype) throws CreateGeometryException
      Creates line as of two point coordinates.
      Parameters:
      x1 - The X1 coordinate
      y1 - The y1 coordinate
      x2 - The X2 coordinate
      y2 - The y2 coordinate
      subtype - of line. See Geometry.SUBTYPES
      Returns:
      The Line created.
      Throws:
      CreateGeometryException
    • createLine

      public static Line createLine(Point p1, Point p2, int subtype) throws CreateGeometryException
      Creates line as of two point objects.
      Parameters:
      p1 - First point
      p2 - Second point
      subtype - of line. See Geometry.SUBTYPES
      Returns:
      The Line created.
      Throws:
      CreateGeometryException
    • createSpline

      public static Spline createSpline(List<Point> points, int subtype) throws CreateGeometryException
      Create Spline from point list
      Parameters:
      points -
      subtype -
      Returns:
      Throws:
      CreateGeometryException
    • calculateAngle

      public static double calculateAngle(Point vertex, Point p1, Point p2)
      Calculate the angle between points p1 and p2 with vertex at vertex point
      Parameters:
      vertex -
      p1 -
      p2 -
      Returns:
    • calculateAngle

      public static double calculateAngle(Point vertex, Point p)
      Find the angle in the counterclockwise direction between the horizontal line and point p relative to the vertex
      Parameters:
      vertex -
      p -
      Returns:
    • areThreePointsInLine

      public static boolean areThreePointsInLine(Point a, Point b, Point c)
    • formatCoordinate

      public static String formatCoordinate(String fmt, double coordinate)
      Returns a formatted string using the specified format string and coordinate values.Conversion options are:
      • %[flags][width][.precision]d The result is formatted as a integer number with the degress of the coordinate
      • %[flags][width][.precision]m The result is formatted as a integer number with the minutes of the coordinate
      • %[flags][width][.precision]s The result is formatted as a decimal number with the seconds of the coordinate.
      • %[flags][width][.precision]D The result is formatted as a decimal number with the degress
      • %- The result is formatted with the sign if it is negative
      • %+ The result is formatted with the sign
      Example:
      formatCoordinate("%-%d° %m' %s'' N", 39.89)"39° 53' 24.000'' N"
      formatCoordinate("%-%d° %m' %.0s'' N", 39.89)"39° 53' 24'' N"
      formatCoordinate("%+%d° %m' %.2s'' N (%4.4D)", 39.89)"+39° 53' 24.00'' N (39.8900)"
      formatCoordinate("%-%d° %m' N", 39.89) "39° 53' N"
      formatCoordinate("%-%d° %m' N", -39.89) "-39° 53' N"
      formatCoordinate("%-%d° %m' N (%4.4D)", 39.89) "39° 53' N (39.8900)"
      Parameters:
      fmt -
      coordinate -
      Returns:
    • formatCoordinate

      public static String formatCoordinate(String fmt, String NS, double coordinate)
    • formatAngle

      public static String formatAngle(String fmt, double angle)
    • parseCoordinate

      public static double parseCoordinate(String source)
    • getCoefDirection

      public static double getCoefDirection(Point center, Point point1, Point point2)
      Returns the coefficient that expresses the direction in which the angle with vertex at center a and from point1 to point2 is beaten coefDirection >= 0 then the direction is CCW else the direction is CW
      Parameters:
      center -
      point1 -
      point2 -
      Returns:
    • calculateLambdaPoint

      public static Point calculateLambdaPoint(Point p1, Point p2, double lambda) throws CreateGeometryException, GeometryOperationNotSupportedException, GeometryOperationException
      Calculates a point on the line that passes through two points whose distance to the first is proportional to the distance between them according to the lambda parameter
      Parameters:
      p1 -
      p2 -
      lambda -
      Returns:
      Throws:
      CreateGeometryException
      GeometryOperationNotSupportedException
      GeometryOperationException
    • overlaps

      public static boolean overlaps(Geometry polygon, Geometry polygon2, double theTolerance) throws GeometryOperationNotSupportedException, GeometryOperationException
      Returns true if two polygons overlap taking into account the given tolerance
      Parameters:
      polygon -
      polygon2 -
      theTolerance -
      Returns:
      Throws:
      GeometryOperationNotSupportedException
      GeometryOperationException
    • angleGetTurn

      public static int angleGetTurn(double ang1, double ang2)
      Returns whether an angle must turn clockwise or counterclockwise to overlap another angle.
      Parameters:
      ang1 - an angle (in radians)
      ang2 - an angle (in radians)
      Returns:
      whether a1 must turn ANGLE_TURN_CLOCKWISE, COUNTERCLOCKWISE or NONE to overlap a2.
    • angleDiff

      public static double angleDiff(double ang1, double ang2)
      Computes the unoriented smallest difference between two angles. The angles are assumed to be normalized to the range [-Pi, Pi]. The result will be in the range [0, Pi].
      Parameters:
      ang1 - the angle of one vector (in [-Pi, Pi] )
      ang2 - the angle of the other vector (in range [-Pi, Pi] )
      Returns:
      the angle (in radians) between the two vectors (in range [0, Pi] )
    • extractFrom

      public static final List<Geometry> extractFrom(String s, org.gvsig.crs.projection.lib.Projection proj)
    • extractFrom

      public static final List<Geometry> extractFrom(javax.json.JsonValue json, org.gvsig.crs.projection.lib.Projection proj)
    • toAggregate

      public static final Geometry toAggregate(List<Geometry> geoms, StringBuilder warnings)