Package org.gvsig.fmap.geom
Class GeometryUtils
java.lang.Object
org.gvsig.fmap.geom.GeometryUtils
- Author:
- jjdelcerro
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intA value that indicates an orientation of clockwise, or a right turn.static final intA value that indicates an orientation of counterclockwise, or a left turn.static final intA value that indicates an orientation of collinear, or no turn (straight). -
Method Summary
Modifier and TypeMethodDescriptionstatic doubleangleDiff(double ang1, double ang2) Computes the unoriented smallest difference between two angles.static intangleGetTurn(double ang1, double ang2) Returns whether an angle must turn clockwise or counterclockwise to overlap another angle.static booleanareThreePointsInLine(Point a, Point b, Point c) static doublecalculateAngle(Point vertex, Point p) Find the angle in the counterclockwise direction between the horizontal line and point p relative to the vertexstatic doublecalculateAngle(Point vertex, Point p1, Point p2) Calculate the angle between points p1 and p2 with vertex at vertex pointstatic PointcalculateLambdaPoint(Point p1, Point p2, double lambda) 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 parameterstatic booleancanAggregate(int geomTypeParent, int geomTypeChild) static Objectstatic ArcCreates an arc as of center, radius, start angle and extension angle.static ArcCreates an arc as of three points.static CirclecreateCircle(org.gvsig.euclidean.EuclideanLine2D line1, org.gvsig.euclidean.EuclideanLine2D line2, Point point, int subtype) Creates a circle from two tangents and one point.static CirclecreateCircle(Geometry geometry1, Geometry geometry2, double radius, Point firstPoint, Point secondPoint, int subtype) Creates a circle from two tangent geometries and the radius.static CirclecreateCircle(Point center, double radius, int subtype) Creates a circle as of center and radius.static CirclecreateCircle(Point firstPoint, Point secondPoint, Point thirdPoint, int subtype) Creates a circle from three points.static CirclecreateCircle(Point firstPoint, Point secondPoint, Point thirdPoint, Point fourthPoint, Point fifthPoint, int subtype) 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.static ArccreateEllipse(Point firstPointAxisA, Point secondPointAxisA, double halfLengthAxisB, int subtype) Creates an ellipse from start and end point of A axis and half length of B axis.static EnvelopecreateEnvelope(double minX, double minY, double maxX, double maxY, int subType) static EnvelopecreateEnvelope(int subType) static EllipsecreateFilledEllipse(Point firstPointAxisA, Point secondPointAxisA, double halfLengthAxisB, int subtype) Creates a filled ellipse from start and end point of A axis and half length of B axis.static GeometrycreateFrom(Object data) static GeometrycreateFrom(String wkt) static GeometrycreateFrom(String wkt, String srs) static GeometrycreateFrom(String wkt, org.gvsig.crs.projection.lib.Projection srs) static LinecreateLine(double x1, double y1, double x2, double y2, int subtype) Creates line as of two point coordinates.static LinecreateLine(int subType) static LinecreateLine(Point p1, Point p2, int subtype) Creates line as of two point objects.static MultiLinecreateMultiLine(int subType) static MultiPolygoncreateMultiPolygon(int subType) static PointcreatePoint(double x, double y) static PointcreatePoint(double x, double y, double z) static PointcreatePoint(double x, double y, double z, double m) static PointcreatePoint(Point center, double radius, double angle) static PolygoncreatePolygon(int subType) static SplinecreateSpline(List<Point> points, int subtype) Create Spline from point listextractFrom(String s, org.gvsig.crs.projection.lib.Projection proj) extractFrom(javax.json.JsonValue json, org.gvsig.crs.projection.lib.Projection proj) static StringformatAngle(String fmt, double angle) static StringformatCoordinate(String fmt, double coordinate) Returns a formatted string using the specified format string and coordinate values.Conversion options are:%[flags][width][.precision]dThe result is formatted as a integer number with the degress of the coordinate%[flags][width][.precision]mThe result is formatted as a integer number with the minutes of the coordinate%[flags][width][.precision]sThe result is formatted as a decimal number with the seconds of the coordinate.static StringformatCoordinate(String fmt, String NS, double coordinate) static PointGets center point of three points.static doublegetCoefDirection(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 CWstatic intgetGeometrySubtype(String subtype) static StringgetGeometrySubtypeName(int subtype) static GeometryTypegetGeometryType(int geometryType, int geometrySubType) static intgetGeometryType(String typeName) static StringgetGeometryTypeName(int type) static PointgetMidPoint(Point a, Point b, int subtype) Gets midpoint of two pointsstatic booleanintersects(Geometry geom1, Geometry geom2) static booleanisSubtype(int geomTypeParent, int geomTypeChild) static booleanReturns true if two polygons overlap taking into account the given tolerancestatic doubleparseCoordinate(String source) static final GeometrytoAggregate(List<Geometry> geoms, StringBuilder warnings) static byte[]static byte[]static String
-
Field Details
-
ANGLE_TURN_CLOCKWISE
public static final int ANGLE_TURN_CLOCKWISEA value that indicates an orientation of clockwise, or a right turn.- See Also:
-
ANGLE_TURN_COUNTERCLOCKWISE
public static final int ANGLE_TURN_COUNTERCLOCKWISEA value that indicates an orientation of counterclockwise, or a left turn.- See Also:
-
ANGLE_TURN_NONE
public static final int ANGLE_TURN_NONEA value that indicates an orientation of collinear, or no turn (straight).- See Also:
-
-
Method Details
-
getGeometryType
-
isSubtype
public static boolean isSubtype(int geomTypeParent, int geomTypeChild) -
canAggregate
public static boolean canAggregate(int geomTypeParent, int geomTypeChild) -
createEnvelope
-
createEnvelope
public static Envelope createEnvelope(double minX, double minY, double maxX, double maxY, int subType) -
createLine
-
createMultiLine
-
createPolygon
-
createMultiPolygon
-
createPoint
-
createPoint
-
createPoint
-
createPoint
-
createFrom
-
createFrom
-
createFrom
-
createFrom
-
convertTo
-
toWKT
-
toWKB
-
toEWKB
-
intersects
-
getGeometryTypeName
-
getGeometrySubtypeName
-
getGeometryType
-
getGeometrySubtype
-
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 circleradius- of new circlesubtype- subtype of circle. SeeGeometry.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 circlesecondPoint- of circlethirdPoint- of circlesubtype- subtype of circle. SeeGeometry.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. SeeGeometry.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 lineline2- Another tangent linepoint- A point near the center of the circle.subtype- subtype of circle. SeeGeometry.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 geometrygeometry2- Another tangent geometryradius- the radius of the cicle.firstPoint- a point near tangent point of geometry1secondPoint- a point near tangent point of geometry2subtype- subtype of circle. SeeGeometry.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 radiansangleExt- of arc in radianssubtype- subtype of arc. SeeGeometry.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 arcmiddle- point of arc. It can be any point of arc.end- point of arcsubtype- of arc. SeeGeometry.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 axissecondPointAxisA- second point of B axishalfLengthAxisB- half length of B axissubtype- of ellipse SeeGeometry.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 axissecondPointAxisA- second point of B axishalfLengthAxisB- half length of B axissubtype- of ellipse SeeGeometry.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 oneb- Point twoc- Point threesubtype- of point created. SeeGeometry.SUBTYPES- Returns:
- Point center.
- Throws:
CreateGeometryException
-
getMidPoint
Gets midpoint of two points- Parameters:
a- Point oneb- Point twosubtype- of point created. SeeGeometry.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 coordinatey1- The y1 coordinatex2- The X2 coordinatey2- The y2 coordinatesubtype- of line. SeeGeometry.SUBTYPES- Returns:
- The Line created.
- Throws:
CreateGeometryException
-
createLine
Creates line as of two point objects.- Parameters:
p1- First pointp2- Second pointsubtype- of line. SeeGeometry.SUBTYPES- Returns:
- The Line created.
- Throws:
CreateGeometryException
-
createSpline
Create Spline from point list- Parameters:
points-subtype-- Returns:
- Throws:
CreateGeometryException
-
calculateAngle
Calculate the angle between points p1 and p2 with vertex at vertex point- Parameters:
vertex-p1-p2-- Returns:
-
calculateAngle
Find the angle in the counterclockwise direction between the horizontal line and point p relative to the vertex- Parameters:
vertex-p-- Returns:
-
areThreePointsInLine
-
formatCoordinate
Returns a formatted string using the specified format string and coordinate values.Conversion options are:%[flags][width][.precision]dThe result is formatted as a integer number with the degress of the coordinate%[flags][width][.precision]mThe result is formatted as a integer number with the minutes of the coordinate%[flags][width][.precision]sThe result is formatted as a decimal number with the seconds of the coordinate.%[flags][width][.precision]DThe 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
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
-
formatAngle
-
parseCoordinate
-
getCoefDirection
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:
CreateGeometryExceptionGeometryOperationNotSupportedExceptionGeometryOperationException
-
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:
GeometryOperationNotSupportedExceptionGeometryOperationException
-
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
-
extractFrom
-
toAggregate
-