Package com.kheops.jmap.spatial
Class GeometryUtil
java.lang.Object
com.kheops.jmap.spatial.GeometryUtil
This class utility provides static methods to perform geometry operations
defined in the Open Geospatial
Consortium Simple feature model.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Constant for the clockwise direction.static final int
Constant for the counterclockwise direction.static final double
Constant which defines the ratio used to convert degrees into radians,static final int
Constant for the degree unit.static final double
Constant which defines the earth radius in meters for the WGS84 datum used for Longitude/Latitude projection.static final double
precision used for Point-Point equalitystatic final double
Constant which defines the ratio used to convert radians into degrees,static final int
Constant for the radian unit.static final double
Constant which defines the value for (2 * PI). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Geometry
Computes the set of points whose distance to geometry is less than distance.static Geometry
buffer
(Geometry geometry, double distance, double angleStepUser, PrecisionModel precisionModel) Computes the set of points whose distance to geometry is less than distance.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.static LineString
Builds a circular arc.static double
computeArea
(PolygonTypeGeometry surface, Projection mapProjection, JMapUnit mapUnit, Projection measurementProjection, JMapUnit distanceUnit) static double
computeDistance
(Point coord1, Point coord2, Projection mapProjection, JMapUnit mapUnit, Projection measurementProjection, JMapUnit distanceUnit) Computes the distance between the two specified coordinates.static boolean
contains
(Ellipse ellipse, double x, double y, PrecisionModel precisionModel) static boolean
contains
(Ellipse ellipse1, Ellipse ellipse2, PrecisionModel precisionModel) Tests if the first ellipse contains the second ellipse.static boolean
contains
(Ellipse ellipse, LineString line, PrecisionModel precisionModel) static boolean
contains
(Ellipse ellipse, Point coord, PrecisionModel precisionModel) static boolean
contains
(Ellipse ellipse, Polygon poly, PrecisionModel precisionModel) static boolean
contains
(Ellipse ellipse, Rectangle rect, PrecisionModel precisionModel) static boolean
test "contains" relationship as defined in OpenGIS : Simple Features Specification For SQL available at www.opengis.orgstatic boolean
contains
(Geometry geometry1, Geometry geometry2, PrecisionModel precisionModel) test "contains" relationship as defined in OpenGIS : Simple Features Specification For SQL available at www.opengis.orgstatic boolean
contains
(Line line, Point c, PrecisionModel precisionModel) Tests if a line contains a point.static boolean
contains
(LineString l1, LineString l2) Tests if the first linestring contains the second linestring.static boolean
contains
(LineString l1, LineString l2, PrecisionModel precisionModel) Tests if the first linestring contains the second linestring.static boolean
contains
(LineString lineString, Point c) Tests if a linestring contains a point.static boolean
contains
(LineString lineString, Point coord, PrecisionModel precisionModel) Tests if a linestring contains a point.static boolean
Verifies if a polygon contains the specified coordinates within it's closed region.static boolean
contains
(Point[] coords, Point coord, PrecisionModel precisionModel) Verifies if a polygon contains the specified coordinates within it's closed region.static boolean
contains
(Point coord, LineString lineString, PrecisionModel precisionModel) static boolean
Tests if the first point contains the second point.static boolean
Tests if a line defined by 2 points a and b contains point c.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.static boolean
contains
(Point a, Point b, PrecisionModel precisionModel) Tests if the first point contains the second point.static boolean
Checks if a Point contains a Polygon : falsestatic boolean
contains
(Point c, Polygon poly, PrecisionModel precisionModel) static boolean
contains
(Polygon poly, Ellipse ellipse, PrecisionModel precisionModel) static boolean
contains
(Polygon poly, LineString lineString, PrecisionModel precisionModel) static boolean
contains
(Polygon poly, Point c, PrecisionModel precisionModel) Tests whether the specified point in contained by the specified polygon.static boolean
static boolean
contains
(Polygon poly1, Polygon poly2, PrecisionModel precisionModel) static boolean
contains
(Polygon poly, Rectangle rect, PrecisionModel precisionModel) static boolean
contains
(Rectangle rect, Point coord, PrecisionModel precisionModel) static boolean
contains
(Rectangle r1, Rectangle r2, PrecisionModel precisionModel) Tests if the first rectangle contains the second rectangle.static Geometry
convexHull
(Geometry geometry, boolean oneForCollection) Computes the convexHull of a geometrystatic Geometry
convexHull
(Geometry geometry, boolean oneForCollection, PrecisionModel precisionModel) Computes the convexHull of a geometrystatic Ellipse
createCircle
(Point p1, Point p2, Point p3) Creates a new circle with the specified coordinates.static boolean
test "crosses" relationship as defined in OpenGIS : Simple Features Specification For SQL available at www.opengis.org uses relate() methodstatic 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() methodstatic Geometry
difference
(Geometry geometry1, Geometry geometry2) Compute the difference between two Geometries basically just calls the correct method according to argument classstatic Geometry
difference
(Geometry geometry1, Geometry geometry2, PrecisionModel precisionModel) Compute the difference between two Geometries basically just calls the correct method according to argument classstatic Geometry
Compute the symmetric difference between two Geometries basically just calls the correct method according to argument classstatic Geometry
diffSym
(Geometry geometry1, Geometry geometry2, PrecisionModel precisionModel) Compute the symmetric difference between two Geometries basically just calls the correct method according to argument classstatic boolean
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 coststatic 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 coststatic double
distance
(double x0, double y0, double x1, double y1) This method calculates the distance between 2 coordinates.static double
distance
(Ellipse ellipse1, Ellipse ellipse2, PrecisionModel precisionModel) static double
static double
distance
(Geometry geometry1, Geometry geometry2, PrecisionModel precisionModel) static double
distance
(LineString ls, Ellipse ellipse, PrecisionModel precisionModel) static double
distance
(LineString l1, LineString l2, PrecisionModel precisionModel) Calculates the distance between 2 LineStringsstatic double
distance
(LineString l, Point p, PrecisionModel precisionModel) static double
distance
(LineString ls, Polygon poly, PrecisionModel precisionModel) Calculates the distance between a LineString and a Polygonstatic double
distance
(Point p, Ellipse ellipse, PrecisionModel precisionModel) 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)static double
This method calculates the distance between 2 coordinates.static double
static double
static double
Calculates the distance between 2 segments [ab] and [cd]static double
distance
(Point p, Point a, Point b, PrecisionModel precisionModel) Calculates the distance from a point to a segment defined as [ab]static double
distance
(Point p0, Point p1, PrecisionModel precisionModel) This method calculates the distance between 2 coordinates.static double
distance
(Point p, Polygon poly, PrecisionModel precisionModel) Calculates the distance from a point to polygonstatic double
distance
(Polygon poly, Ellipse ellipse, PrecisionModel precisionModel) static double
distance
(Polygon poly, LineString ls, PrecisionModel precisionModel) static double
distance
(Polygon poly, Point p, PrecisionModel precisionModel) static double
distance
(Polygon poly1, Polygon poly2, PrecisionModel precisionModel) Calculates the distance between 2 polygonsstatic double
distance
(Polygon poly, Rectangle rect, PrecisionModel precisionModel) static double
distance
(Rectangle rect, Ellipse ellipse, PrecisionModel precisionModel) 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 ellipsoidsstatic double
distVincenty
(Projection projection, Point c1, Point c2) 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.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.static Polygon
extractLargestPolygon
(GeometryCollection collection) Goes through the collection of geometries and finds the largest Polygon.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 pointstatic Point
findPerpendicularPoint
(Point lsp1, Point lsp2, Point perpPoint) this method finds the perpendicular point on a line to a specified pointstatic Point
findPerpendicularPoint
(Point lsp1, Point lsp2, Point perpPoint, PrecisionModel precisionModel) this method finds the perpendicular point on a line to a specified pointstatic 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,y2static double
getAngleAtArcVertex
(Point arcVertex, Point center, double radius) Deprecated.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.static Point
getArcCenter
(Point startPoint, Point midPoint, Point endPoint) Finds the center of a circular Arc.static Point
getArcCenter
(Point pt1, Point pt2, Point pt3, PrecisionModel precisionModel) Finds the center of a circular Arc given three points.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 pointstatic int
getPointDirection
(double pointX, double pointY, double centerX, double centerY) Deprecated.static Geometry
intersection
(Geometry geometry1, Geometry geometry2) Compute the intersection between two Geometries basically just calls the correct method according to argument classstatic Geometry
intersection
(Geometry geometry1, Geometry geometry2, PrecisionModel precisionModel) Compute the intersection between two Geometries basically just calls the correct method according to argument classstatic Geometry
intersectionMultiple
(Geometry[] geometries) Fast method to intersect many geometries
It executes a binary intersectionstatic Geometry
intersectionMultiple
(Geometry[] geometries, PrecisionModel precisionModel) Fast method to intersect many geometries
It executes a binary intersectionstatic boolean
intersects
(double x1, double y1, double x2, double y2, double xA, double yA, double xB, double yB) Tests if two line segments intersect.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.static boolean
intersects
(Ellipse ellipse1, Ellipse ellipse2, PrecisionModel precisionModel) static boolean
intersects
(Ellipse ellipse, LineString lineString, PrecisionModel precisionModel) static boolean
intersects
(Ellipse ellipse, Point point, PrecisionModel precisionModel) static boolean
intersects
(Ellipse ellipse, Polygon polygon, PrecisionModel precisionModel) static boolean
intersects
(Ellipse ellipse, Rectangle rect, PrecisionModel precisionModel) 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 coststatic 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 coststatic boolean
intersects
(LineString l1, LineString l2, PrecisionModel precisionModel) Tests if 2 LineStrings intersectstatic boolean
intersects
(LineString l, Point a, PrecisionModel precisionModel) static boolean
intersects
(LineString l, Polygon poly, PrecisionModel precisionModel) Tests if a LineString intersects a Polygonstatic boolean
intersects
(Point center, double radius, Geometry geometry) static boolean
intersects
(Point center, double radius, Geometry geometry, PrecisionModel precisionModel) static boolean
intersects
(Point center, double radius, LinearRing[] rings) This method checks if a circle intersects a polygonstatic boolean
intersects
(Point center, double radius, LinearRing[] rings, PrecisionModel precisionModel) This method checks if a circle intersects a polygonstatic boolean
intersects
(Point center, double radius, LineString line) Tests if specified circle area touches at any point the specifies polyline.static boolean
intersects
(Point center, double radius, LineString line, PrecisionModel precisionModel) Tests if specified circle area touches at any point the specifies polyline.static boolean
intersects
(Point center, double radius, Rectangle rect) This method check if a circle intersects a rectangle.static boolean
intersects
(Point center, double radius, Rectangle rect, PrecisionModel precisionModel) This method check if a circle intersects a rectangle.static boolean
intersects
(Point a, LineString l, PrecisionModel precisionModel) static boolean
intersects
(Point startPoint1, Point endPoint1, Point startPoint2, Point endPoint2) static boolean
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.static boolean
intersects
(Point a, Point b, PrecisionModel precisionModel) static boolean
intersects
(Point a, Polygon poly, PrecisionModel precisionModel) static boolean
intersects
(Polygon poly, LineString l, PrecisionModel precisionModel) Tests if a polygon intersects a linestring.static boolean
intersects
(Polygon poly, Point c, PrecisionModel precisionModel) static boolean
intersects
(Polygon poly1, Polygon poly2, PrecisionModel precisionModel) Tests if 2 Polygons intersectstatic boolean
intersects
(Rectangle r1, Rectangle r2, PrecisionModel precisionModel) static boolean
intersectsArc
(Ellipse ellipse, double xA, double yA, double xB, double yB) static boolean
intersectsArc
(Ellipse ellipse, double xA, double yA, double xB, double yB, PrecisionModel precisionModel) static boolean
intersectsOutline
(Ellipse ellipse, double xA, double yA, double xB, double yB) static boolean
intersectsOutline
(Ellipse ellipse, double xA, double yA, double xB, double yB, PrecisionModel precisionModel) static LinearRing
Change the orientation of a linearRing.static boolean
isPerpendicular
(Point pt1, Point pt2, Point pt3, PrecisionModel precisionModel) Verify if the given points are perpendicular to x or y axisstatic Geometry
Check if the geometry is valid, if not valid try to correct it Return the corrected (or not) geometrystatic boolean
Tests "overlaps" relationship as defined in OpenGIS : Simple Features Specification For SQL available at www.opengis.org uses relate() methodstatic 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() methodstatic Polygon
Generalizes a polygon so that it becomes a quadrilateral - a polygon with four sides or edges and four vertices or corners.static boolean
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 matrixstatic 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 matrixstatic int
The orientation of a linearRing.static boolean
spatiallyEquals
(Geometry geometry1, Geometry geometry2) static boolean
spatiallyEquals
(Geometry geometry1, Geometry geometry2, PrecisionModel precisionModel) 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.static double
sphericalDistance
(Point c1, Point c2) static boolean
test "touches" relationship as defined in OpenGIS : Simple Features Specification For SQL available at www.opengis.orgstatic boolean
touches
(Geometry geometry1, Geometry geometry2, PrecisionModel precisionModel) test "touches" relationship as defined in OpenGIS : Simple Features Specification For SQL available at www.opengis.orgstatic Geometry
Compute the union between two Geometries basically just calls the correct method according to argument classstatic Geometry
union
(Geometry geometry1, Geometry geometry2, PrecisionModel precisionModel) Compute the union between two Geometries basically just calls the correct method according to argument classstatic Geometry
unionMultiple
(Geometry[] geometries) Fast method to merge many geometries
It executes a binary union.static Geometry
unionMultiple
(Geometry[] geometries, PrecisionModel precisionModel) Fast method to merge many geometries
It executes a binary union.static boolean
test "within" relationship as defined in OpenGIS : Simple Features Specification For SQL available at www.opengis.org uses contains() methodstatic 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
-
Field Details
-
MAX_DIST_TRESHOLD
public static final double MAX_DIST_TRESHOLDprecision used for Point-Point equality- See Also:
-
DEG_TO_RAD
public static final double DEG_TO_RADConstant which defines the ratio used to convert degrees into radians,- See Also:
-
RAD_TO_DEG
public static final double RAD_TO_DEGConstant which defines the ratio used to convert radians into degrees,- See Also:
-
EARTH_RADIUS
public static final double EARTH_RADIUSConstant 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_PIConstant which defines the value for (2 * PI).- See Also:
-
DEGREE
public static final int DEGREEConstant for the degree unit.- See Also:
-
RADIAN
public static final int RADIANConstant for the radian unit.- See Also:
-
CLOCKWISE
public static final int CLOCKWISEConstant for the clockwise direction.- See Also:
-
COUNTERCLOCKWISE
public static final int COUNTERCLOCKWISEConstant for the counterclockwise direction.- See Also:
-
-
Constructor Details
-
GeometryUtil
public GeometryUtil()
-
-
Method Details
-
contains
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
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
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
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
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
Tests if a linestring contains a point.- Parameters:
lineString
- the linestring.c
- point.- Returns:
- true if line contains c, false otherwise.
-
contains
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
-
contains
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
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
- Parameters:
poly
- polygonlineString
- line string- Returns:
- true if poly contains lineString, false otherwise
-
contains
-
contains
-
contains
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
-
contains
-
contains
-
contains
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
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
-
contains
-
contains
-
intersects
-
contains
Checks if a Point contains a Polygon : false- Returns:
- false
-
contains
-
contains
-
contains
-
contains
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
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
-
spatiallyEquals
public static boolean spatiallyEquals(Geometry geometry1, Geometry geometry2, PrecisionModel precisionModel) -
disjoint
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
-
intersects
-
intersects
-
intersects
-
intersects
-
intersects
Tests if 2 LineStrings intersect -
intersects
Tests if a LineString intersects a Polygon -
intersects
Tests if a polygon intersects a linestring. -
intersects
Tests if 2 Polygons intersect -
intersects
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
-
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 segmentb
- second point of first segmentc
- first point of second segmentd
- second point of second segmentprecisionModel
- the precision model to use.intersectPt
- intersection point (output parameter)- Returns:
- true if line segments intersect or overlap
-
intersects
-
intersects
public static boolean intersects(Point center, double radius, Geometry geometry, PrecisionModel precisionModel) -
intersects
This method checks if a circle intersects a polygon- Parameters:
center
- the K2DCoord instance that represents the center of the circleradius
- 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 circleradius
- the radius of the corresponding circle- Returns:
- the boolean value result.
-
intersects
Tests if specified circle area touches at any point the specifies polyline.- Parameters:
center
- the center coordinate of the circleradius
- the radius of the circleline
- 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 circleradius
- the radius of the circleline
- the polyline for which we want to test the intersection- Returns:
- true if the circle and polyline intersect, false otherwise
-
intersects
This method check if a circle intersects a rectangle.- Parameters:
center
- the center of the circleradius
- the radius of the circlerect
- 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 circleradius
- the radius of the circlerect
- the corresponding rectangle- Returns:
- true if the circle and rectangle intersect, false otherwise
-
touches
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
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
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
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
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
-
intersects
-
intersects
public static boolean intersects(Ellipse ellipse, LineString lineString, PrecisionModel precisionModel) -
intersects
-
intersects
-
overlaps
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
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
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
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
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
Compute the union between two Geometries basically just calls the correct method according to argument class -
union
Compute the union between two Geometries basically just calls the correct method according to argument class -
unionMultiple
Fast method to merge many geometries
It executes a binary union. -
unionMultiple
Fast method to merge many geometries
It executes a binary union. -
intersectionMultiple
Fast method to intersect many geometries
It executes a binary intersection -
intersectionMultiple
Fast method to intersect many geometries
It executes a binary intersection -
difference
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
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
The orientation of a linearRing. 1 is clockwise, -1 anti-clockwise -
inverseRingDirection
Change the orientation of a linearRing.- Parameters:
l
-- Returns:
- LinearRing in opposite direction.
-
createCircle
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 axisb
- the smaller axisangle
- the inclination angle in degrees, clockwisestartAngle
- the starting angle of the sweep in degrees. Starts on right x axis, counterclockwiseendAngle
- the ending angle of the sweep in degrees. Starts on right x axis, counterclockwisegeometryType
- 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 axisb
- the smaller axisangle
- the inclination angle in degrees, clockwisestartAngle
- the starting angle of the sweep in degrees. Starts on right x axis, counterclockwiseendAngle
- the ending angle of the sweep in degrees. Starts on right x axis, counterclockwisegeometryType
- the geometry typeccw
- 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
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 angleintersectPt
- 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 Point1y1
- y coordinate of Point1x2
- x coordinate of Point2y2
- 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 1resultPoint
- 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
-
distance
public static double distance(Geometry geometry1, Geometry geometry2, PrecisionModel precisionModel) -
distance
This method calculates the distance between 2 coordinates.- Parameters:
p0
- the first coordinatep1
- the second coordinate- Returns:
- the distance between the two coordinates
-
distance
This method calculates the distance between 2 coordinates.- Parameters:
p0
- the first coordinatep1
- 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
-
distance
Calculates the distance from a point to a segment defined as [ab] -
distance
-
distance
Calculates the distance between 2 segments [ab] and [cd] -
distance
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
-
distance
Calculates the distance from a point to polygon -
distance
-
distance
-
distance
Calculates the distance between 2 polygons -
distance
-
distance
-
distance
-
distance
Calculates the distance between 2 LineStrings -
distance
Calculates the distance between a LineString and a Polygon -
distance
-
distance
-
distance
-
sphericalDistance
-
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 degreeslati1
- the first coordinate latitude in degreeslong2
- the second coordinate longitude in degreeslati2
- 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 projectionlon1
- the first coordinate longitude in degreeslat1
- the first coordinate latitude in degreeslon2
- the second coordinate longitude in degreeslat2
- the second coordinate latitude in degrees- Returns:
- the distance between two points in meters
-
distVincenty
-
intersects
-
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 segmenty1
- ordinate of the first point of the first line segmentx2
- abscissa of the second point of the first line segmenty2
- ordinate of the second point of the first line segmentxA
- abscissa of the first point of the second line segmentyA
- ordinate of the first point of the second line segmentxB
- abscissa of the second point of the second line segmentyB
- 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 segmenty1
- ordinate of the first point of the first line segmentx2
- abscissa of the second point of the first line segmenty2
- ordinate of the second point of the first line segmentxA
- abscissa of the first point of the second line segmentyA
- ordinate of the first point of the second line segmentxB
- abscissa of the second point of the second line segmentyB
- ordinate of the second point of the second line segment- Returns:
- true if the two line segments intersect
-
findPerpendicularPoint
this method finds the perpendicular point on a line to a specified point- Parameters:
lsp1
- pt 1 of the linelsp2
- pt 2 of the lineperpPoint
- 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 linelsp2
- pt 2 of the lineperpPoint
- 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
-
intersectsArc
public static boolean intersectsArc(Ellipse ellipse, double xA, double yA, double xB, double yB, PrecisionModel precisionModel) -
extractLargestPolygon
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 arcmidPoint
- The middle point of an arcendPoint
- The end point of an arcarcCenter
- The center of rotation of an arc- Returns:
- An arc converted to segments of straight lines
-
getArcCenter
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 arcmidPoint
- The mid-point of an arcendPoint
- The end point of an arc- Returns:
- The center of a circle the arc is part of
-
getArcCenter
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 arcpt3
- 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 pointpt2
- second pointpt3
- third point- Returns:
- true if perpendicular false if not
-
getArcDirection
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 arcmidPoint
- The middle point of an arcendPoint
- 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.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 arccenter
- The center of a circle the arc is part ofradius
- 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 coordinatepointY
- The point Y coordinatecenterX
- The second point X coordinatecenterY
- The second point Y coordinate- Returns:
- integer value representing the location of a point
-
polygonToQuadrilateral
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
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
-
getAngle(double, double, double, double)