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.MultiPolygonMembers |
static class |
Geometry.PolygonIntersection |
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 boolean |
angleIsClockwise(Node commonNode,
Node firstNode,
Node secondNode)
This method tests if secondNode is clockwise to first node.
|
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(OsmPrimitive 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<Node> polygon)
Returns the Area of a polygon, from its list of nodes.
|
static Geometry.AreaAndPerimeter |
getAreaAndPerimeter(java.util.List<Node> nodes)
Calculate area and perimeter length of a polygon.
|
static Geometry.AreaAndPerimeter |
getAreaAndPerimeter(java.util.List<Node> nodes,
Projection projection)
Calculate area and perimeter length of a polygon in the given projection.
|
static java.awt.geom.Area |
getAreaLatLon(java.util.List<Node> polygon)
Returns the Area of a polygon, from its list of nodes.
|
static EastNorth |
getCenter(java.util.List<Node> nodes)
Compute center of the circle closest to different nodes.
|
static EastNorth |
getCentroid(java.util.List<Node> 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 |
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<Node> 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(Node node,
Relation multiPolygon,
Predicate<Way> isOuterWayAMatch)
Tests if the
node is inside the multipolygon multiPolygon . |
static boolean |
isPolygonInsideMultiPolygon(java.util.List<Node> nodes,
Relation multiPolygon,
Predicate<Way> isOuterWayAMatch)
Tests if the polygon formed by
nodes is inside the multipolygon multiPolygon . |
static boolean |
isToTheRightSideOfLine(Node lineP1,
Node lineP2,
Node lineP3,
Node 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(Node point,
java.util.List<Node> 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<Node> first,
java.util.List<Node> second)
Tests if two polygons intersect.
|
static boolean |
segmentsParallel(EastNorth p1,
EastNorth p2,
EastNorth p3,
EastNorth 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 boolean isToTheRightSideOfLine(Node lineP1, Node lineP2, Node lineP3, Node testPoint)
lineP1
- first point in pathlineP2
- second point in pathlineP3
- third point in pathtestPoint
- point to testpublic static boolean angleIsClockwise(Node commonNode, Node firstNode, Node secondNode)
commonNode
- 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)
private 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<Node> polygon)
polygon
- List of nodes forming polygon (EastNorth coordinates)public static java.awt.geom.Area getAreaLatLon(java.util.List<Node> polygon)
polygon
- List of nodes forming polygon (LatLon coordinates)public static Geometry.PolygonIntersection polygonIntersection(java.util.List<Node> first, java.util.List<Node> 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(Node point, java.util.List<Node> 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(OsmPrimitive 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<Node> 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 EastNorth getCentroid(java.util.List<Node> nodes)
nodes
- Nodes for which the centroid is wantedgetCenter(java.util.List<org.openstreetmap.josm.data.osm.Node>)
public static EastNorth getCenter(java.util.List<Node> 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<org.openstreetmap.josm.data.osm.Node>)
public static boolean isNodeInsideMultiPolygon(Node node, Relation multiPolygon, 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<Node> nodes, Relation multiPolygon, 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<Node> nodes)
nodes
- the list of nodes representing the polygonpublic static Geometry.AreaAndPerimeter getAreaAndPerimeter(java.util.List<Node> nodes, Projection projection)
nodes
- the list of nodes representing the polygonprojection
- the projection to use for the calculation, null
defaults to Main.getProjection()