public final class Geometry extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
Geometry.AreaAndPerimeter
Data class to hold two double values (area and perimeter of a polygon).
|
static class |
Geometry.PolygonIntersection
The result types for a
polygonIntersection(Area, Area) test |
Modifier | Constructor and Description |
---|---|
private |
Geometry() |
Modifier and Type | Method and Description |
---|---|
static java.util.Set<Node> |
addIntersections(java.util.List<Way> ways,
boolean test,
java.util.List<Command> cmds)
Will find all intersection and add nodes there for list of given ways.
|
static boolean |
angleIsClockwise(EastNorth commonNode,
EastNorth firstNode,
EastNorth secondNode)
This method tests if secondNode is clockwise to first node.
|
static <N extends INode> |
angleIsClockwise(N commonNode,
N firstNode,
N secondNode)
This method tests if secondNode is clockwise to first node.
|
static java.awt.geom.Path2D |
buildPath2DLatLon(java.util.List<? extends ILatLon> polygon,
java.awt.geom.Path2D path2d)
Builds a path from a list of nodes
|
static double |
closedWayArea(Way way)
Returns area of a closed way in square meters.
|
private static EastNorth |
closestPointTo(EastNorth p1,
EastNorth p2,
EastNorth point,
boolean segmentOnly) |
static EastNorth |
closestPointToLine(EastNorth lineP1,
EastNorth lineP2,
EastNorth point)
Calculates closest point to a line.
|
static EastNorth |
closestPointToSegment(EastNorth segmentP1,
EastNorth segmentP2,
EastNorth point)
Calculates closest point to a line segment.
|
static java.lang.Double |
computeArea(IPrimitive osm)
Computes the area of a closed way and multipolygon in square meters, or
null for other primitives |
static java.awt.geom.Area |
getArea(java.util.List<? extends INode> polygon)
Returns the Area of a polygon, from its list of nodes.
|
static Geometry.AreaAndPerimeter |
getAreaAndPerimeter(java.util.List<? extends ILatLon> nodes)
Calculate area and perimeter length of a polygon.
|
static Geometry.AreaAndPerimeter |
getAreaAndPerimeter(java.util.List<? extends ILatLon> nodes,
Projection projection)
Calculate area and perimeter length of a polygon in the given projection.
|
static java.awt.geom.Area |
getAreaLatLon(Relation multipolygon)
Returns the Area of a polygon, from the multipolygon relation.
|
static EastNorth |
getCenter(java.util.List<? extends INode> nodes)
Compute center of the circle closest to different nodes.
|
static EastNorth |
getCentroid(java.util.List<? extends INode> nodes)
Compute the centroid/barycenter of nodes
|
static EastNorth |
getCentroidEN(java.util.List<EastNorth> nodes)
Compute the centroid/barycenter of nodes
|
static double |
getCornerAngle(EastNorth p1,
EastNorth p2,
EastNorth p3)
Returns angle of a corner defined with 3 point coordinates.
|
static EastNorth |
getLineLineIntersection(EastNorth p1,
EastNorth p2,
EastNorth p3,
EastNorth p4)
Finds the intersection of two lines of infinite length.
|
private static BBox |
getNodesBounds(java.util.List<Node> nodes) |
static double |
getNormalizedAngleInDegrees(double angle)
Get angles in radians and return it's value in range [0, 180].
|
static double |
getSegmentAngle(EastNorth p1,
EastNorth p2)
Returns angle of a segment defined with 2 point coordinates.
|
static EastNorth |
getSegmentSegmentIntersection(EastNorth p1,
EastNorth p2,
EastNorth p3,
EastNorth p4)
Finds the intersection of two line segments.
|
static boolean |
isClockwise(java.util.List<? extends INode> nodes)
Determines whether path from nodes list is oriented clockwise.
|
static boolean |
isClockwise(Way w)
Determines whether a way is oriented clockwise.
|
static boolean |
isNodeInsideMultiPolygon(INode node,
Relation multiPolygon,
java.util.function.Predicate<Way> isOuterWayAMatch)
Tests if the
node is inside the multipolygon multiPolygon . |
static boolean |
isPolygonInsideMultiPolygon(java.util.List<? extends INode> nodes,
Relation multiPolygon,
java.util.function.Predicate<Way> isOuterWayAMatch)
Tests if the polygon formed by
nodes is inside the multipolygon multiPolygon . |
static <N extends INode> |
isToTheRightSideOfLine(N lineP1,
N lineP2,
N lineP3,
N testPoint)
Tests if given point is to the right side of path consisting of 3 points.
|
static double |
multipolygonArea(Relation multipolygon)
Returns area of a multipolygon in square meters.
|
static boolean |
nodeInsidePolygon(INode point,
java.util.List<? extends INode> polygonNodes)
Tests if point is inside a polygon.
|
static Geometry.PolygonIntersection |
polygonIntersection(java.awt.geom.Area a1,
java.awt.geom.Area a2)
Tests if two polygons intersect.
|
static Geometry.PolygonIntersection |
polygonIntersection(java.awt.geom.Area a1,
java.awt.geom.Area a2,
double eps)
Tests if two polygons intersect.
|
static Geometry.PolygonIntersection |
polygonIntersection(java.util.List<? extends INode> first,
java.util.List<? extends INode> second)
Tests if two polygons intersect.
|
static boolean |
segmentsParallel(EastNorth p1,
EastNorth p2,
EastNorth p3,
EastNorth p4)
Check if the segment p1 - p2 is parallel to p3 - p4
|
private Geometry()
public static java.util.Set<Node> addIntersections(java.util.List<Way> ways, boolean test, java.util.List<Command> cmds)
ways
- a list of ways to testtest
- if false, do not build list of Commands, just return nodescmds
- list of commands, typically empty when handed to this method.
Will be filled with commands that add intersection nodes to
the ways.private static BBox getNodesBounds(java.util.List<Node> nodes)
public static <N extends INode> boolean isToTheRightSideOfLine(N lineP1, N lineP2, N lineP3, N testPoint)
N
- type of nodelineP1
- first point in pathlineP2
- second point in pathlineP3
- third point in pathtestPoint
- point to testpublic static <N extends INode> boolean angleIsClockwise(N commonNode, N firstNode, N secondNode)
N
- type of nodecommonNode
- starting point for both vectorsfirstNode
- first vector end nodesecondNode
- second vector end nodepublic static EastNorth getSegmentSegmentIntersection(EastNorth p1, EastNorth p2, EastNorth p3, EastNorth p4)
p1
- the coordinates of the start point of the first specified line segmentp2
- the coordinates of the end point of the first specified line segmentp3
- the coordinates of the start point of the second specified line segmentp4
- the coordinates of the end point of the second specified line segmentpublic static EastNorth getLineLineIntersection(EastNorth p1, EastNorth p2, EastNorth p3, EastNorth p4)
p1
- first point on first linep2
- second point on first linep3
- first point on second linep4
- second point on second linejava.lang.IllegalArgumentException
- if a parameter is null or without valid coordinatespublic static boolean segmentsParallel(EastNorth p1, EastNorth p2, EastNorth p3, EastNorth p4)
p1
- First point for first segmentp2
- Second point for first segmentp3
- First point for second segmentp4
- Second point for second segmenttrue
if they are parallel or close to parallelprivate static EastNorth closestPointTo(EastNorth p1, EastNorth p2, EastNorth point, boolean segmentOnly)
public static EastNorth closestPointToSegment(EastNorth segmentP1, EastNorth segmentP2, EastNorth point)
segmentP1
- First point determining line segmentsegmentP2
- Second point determining line segmentpoint
- Point for which a closest point is searched on line segment [P1,P2]closestPointToLine(org.openstreetmap.josm.data.coor.EastNorth, org.openstreetmap.josm.data.coor.EastNorth, org.openstreetmap.josm.data.coor.EastNorth)
public static EastNorth closestPointToLine(EastNorth lineP1, EastNorth lineP2, EastNorth point)
lineP1
- First point determining linelineP2
- Second point determining linepoint
- Point for which a closest point is searched on line (P1,P2)closestPointToSegment(org.openstreetmap.josm.data.coor.EastNorth, org.openstreetmap.josm.data.coor.EastNorth, org.openstreetmap.josm.data.coor.EastNorth)
public static boolean angleIsClockwise(EastNorth commonNode, EastNorth firstNode, EastNorth secondNode)
commonNode
- starting point for both vectorsfirstNode
- first vector end nodesecondNode
- second vector end nodepublic static java.awt.geom.Area getArea(java.util.List<? extends INode> polygon)
polygon
- List of nodes forming polygonpublic static java.awt.geom.Path2D buildPath2DLatLon(java.util.List<? extends ILatLon> polygon, java.awt.geom.Path2D path2d)
polygon
- Nodes, forming a closed polygonpath2d
- path to add to; can be null, then a new path is createdpublic static java.awt.geom.Area getAreaLatLon(Relation multipolygon)
multipolygon
- the multipolygon relationpublic static Geometry.PolygonIntersection polygonIntersection(java.util.List<? extends INode> first, java.util.List<? extends INode> second)
first
- List of nodes forming first polygonsecond
- List of nodes forming second polygonpublic static Geometry.PolygonIntersection polygonIntersection(java.awt.geom.Area a1, java.awt.geom.Area a2)
a1
- Area of first polygona2
- Area of second polygonpublic static Geometry.PolygonIntersection polygonIntersection(java.awt.geom.Area a1, java.awt.geom.Area a2, double eps)
a1
- Area of first polygona2
- Area of second polygoneps
- an area threshold, everything below is considered an empty intersectionpublic static boolean nodeInsidePolygon(INode point, java.util.List<? extends INode> polygonNodes)
polygonNodes
- list of nodes from polygon path.point
- the point to testpublic static double closedWayArea(Way way)
way
- Way to measure, should be closed (first node is the same as last node)public static double multipolygonArea(Relation multipolygon)
multipolygon
- the multipolygon to measurepublic static java.lang.Double computeArea(IPrimitive osm)
null
for other primitivesosm
- the primitive to measurenull
public static boolean isClockwise(Way w)
2 * area = sum (X[n] * Y[n+1] - X[n+1] * Y[n])
.
If the area is negative the way is ordered in a clockwise direction.
See http://paulbourke.net/geometry/polyarea/w
- the way to be checked.java.lang.IllegalArgumentException
- if way is not closed (see Way.isClosed()
).public static boolean isClockwise(java.util.List<? extends INode> nodes)
nodes
- Nodes list to be checked.java.lang.IllegalArgumentException
- if way is not closed (see Way.isClosed()
).isClockwise(Way)
public static double getSegmentAngle(EastNorth p1, EastNorth p2)
p1
- first pointp2
- second pointpublic static double getCornerAngle(EastNorth p1, EastNorth p2, EastNorth p3)
p1
- first pointp2
- Common endpointp3
- third pointpublic static double getNormalizedAngleInDegrees(double angle)
angle
- the angle in radianspublic static EastNorth getCentroid(java.util.List<? extends INode> nodes)
nodes
- Nodes for which the centroid is wantedgetCenter(java.util.List<? extends org.openstreetmap.josm.data.osm.INode>)
public static EastNorth getCentroidEN(java.util.List<EastNorth> nodes)
nodes
- Coordinates for which the centroid is wantedpublic static EastNorth getCenter(java.util.List<? extends INode> nodes)
[ a1 b1 ] [ -c1 ] With A = [ ... ... ] and Y = [ ... ] [ an bn ] [ -cn ]An approximation of center of circle is (At.A)^-1.At.Y
nodes
- Nodes parts of the circle (at least 3)getCentroid(java.util.List<? extends org.openstreetmap.josm.data.osm.INode>)
public static boolean isNodeInsideMultiPolygon(INode node, Relation multiPolygon, java.util.function.Predicate<Way> isOuterWayAMatch)
node
is inside the multipolygon multiPolygon
. The nullable argument
isOuterWayAMatch
allows to decide if the immediate outer
way of the multipolygon is a match.node
- nodemultiPolygon
- multipolygonisOuterWayAMatch
- allows to decide if the immediate outer
way of the multipolygon is a matchtrue
if the node is inside the multipolygonpublic static boolean isPolygonInsideMultiPolygon(java.util.List<? extends INode> nodes, Relation multiPolygon, java.util.function.Predicate<Way> isOuterWayAMatch)
nodes
is inside the multipolygon multiPolygon
. The nullable argument
isOuterWayAMatch
allows to decide if the immediate outer
way of the multipolygon is a match.
If nodes
contains exactly one element, then it is checked whether that one node is inside the multipolygon.
nodes
- nodes forming the polygonmultiPolygon
- multipolygonisOuterWayAMatch
- allows to decide if the immediate outer
way of the multipolygon is a matchtrue
if the polygon formed by nodes is inside the multipolygonpublic static Geometry.AreaAndPerimeter getAreaAndPerimeter(java.util.List<? extends ILatLon> nodes)
nodes
- the list of nodes representing the polygonpublic static Geometry.AreaAndPerimeter getAreaAndPerimeter(java.util.List<? extends ILatLon> nodes, Projection projection)
nodes
- the list of nodes representing the polygonprojection
- the projection to use for the calculation, null
defaults to ProjectionRegistry.getProjection()