Package ucar.nc2.dt.ugrid.geom
Class LatLonPolygon2D
- java.lang.Object
-
- ucar.nc2.dt.ugrid.geom.LatLonPolygon2D
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
LatLonPolygon2D.Double
public abstract class LatLonPolygon2D extends Object implements Serializable
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLatLonPolygon2D.Double
-
Field Summary
Fields Modifier and Type Field Description protected booleancrossesDateline
-
Constructor Summary
Constructors Constructor Description LatLonPolygon2D()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static doublecalculateLLArrayArea(double[] latLonValues)Calculates the area of a polygon bounding box for an array of doubles in the orientation of: LLy, LLx, URy, URxabstract booleancontains(double lat, double lon)Determines if the point represented by lat, lon is within this polygonbooleancontains(LatLonPoint2D point)Determines if the LatLonPoint2D is within this polygonbooleancontains(LatLonPolygon2D poly)Determines if the specified LatLonPolygon2D is COMPLETELY contained within this LatLonPolygon2Dbooleancontains(LatLonRectangle2D rect)Determines if the specified LatLonRectangle2D is COMPLETELY contained within this LatLonPolygon2DLatLonPolygon2Dcopy()Copies this LatLonPolygon2D to a new LatLonPolygon2DbooleancrossesDateline()doubledistance(LatLonPoint2D p)abstract doubledistanceSq(LatLonPoint2D p)abstract doublegetArea()abstract double[]getBoundingLatLonValues()Calculates the bounding box of thisLatLonPolygon2Dand returns the coordinates as adoublearray with a length of 4.abstract LatLonRectangle2DgetBouningLatLonRectangle2D()abstract LatLonPoint2DgetCentroid()Calculates the geometric center of this LatLonPolygon2Dabstract double[]getLatCoords()abstract double[]getLonCoords()abstract intgetVertexCount()abstract List<LatLonPoint2D>getVertices()Gets a list of LatLonPoint2D vertices in this polygonbooleanintersects(LatLonPoint2D point)abstract booleanintersects(LatLonPoint2D point, boolean crossesDateline)abstract booleanintersects(LatLonPoint2D p1, LatLonPoint2D p2, boolean crossesDateline)abstract booleanintersects(LatLonPolygon2D poly)static booleanlineIntersectsPoint(double e0x, double e0y, double e1x, double e1y, double p1x, double p1y)Checks if the point given by p1x, p1y is intersected by the line segment given by e0, e1static booleanlinesIntersect(double p0x, double p0y, double p1x, double p1y, double p2x, double p2y, double p3x, double p3y)Checks if the line segment drawn from p0 to p1 intersects the line drawn from p2 to p3.abstract voidlineTo(double lat, double lon)Adds the point specified by the provided lat and lon to the end of the polygonvoidlineTo(Point2D point)voidlineTo(LatLonPoint2D point)Adds the LatLonPoint2D to the end of the polygonStringtoString()Return a string representation of the polygon.
-
-
-
Method Detail
-
lineTo
public void lineTo(LatLonPoint2D point)
Adds the LatLonPoint2D to the end of the polygon- Parameters:
point-
-
lineTo
public void lineTo(Point2D point)
-
getArea
public abstract double getArea()
-
lineTo
public abstract void lineTo(double lat, double lon)Adds the point specified by the provided lat and lon to the end of the polygon- Parameters:
lat- the latitude of the point to addlon- the longitude of the point to add
-
getCentroid
public abstract LatLonPoint2D getCentroid()
Calculates the geometric center of this LatLonPolygon2D- Returns:
- the center point
-
contains
public boolean contains(LatLonPoint2D point)
Determines if the LatLonPoint2D is within this polygon- Parameters:
point- the point to test- Returns:
- true if the point is contained within this polygon; false otherwise
-
contains
public abstract boolean contains(double lat, double lon)Determines if the point represented by lat, lon is within this polygon- Parameters:
lat- the latitude (y) of the point to testlon- the longitude (x) of the point to test- Returns:
- true if the point is contained within this polygon; false otherwise
-
contains
public boolean contains(LatLonRectangle2D rect)
Determines if the specified LatLonRectangle2D is COMPLETELY contained within this LatLonPolygon2D- Parameters:
rect- the LatLonRectangle2D to check- Returns:
- true if the LatLonRectangle2D is COMPLETELY contained in this polygon; false otherwise
-
contains
public boolean contains(LatLonPolygon2D poly)
Determines if the specified LatLonPolygon2D is COMPLETELY contained within this LatLonPolygon2D- Parameters:
poly- the LatLonPolygon2D to check- Returns:
- true if the LatLonPolygon2D is COMPLETELY contained in this polygon; false otherwise
-
intersects
public abstract boolean intersects(LatLonPolygon2D poly)
-
intersects
public boolean intersects(LatLonPoint2D point)
-
intersects
public abstract boolean intersects(LatLonPoint2D point, boolean crossesDateline)
-
intersects
public abstract boolean intersects(LatLonPoint2D p1, LatLonPoint2D p2, boolean crossesDateline)
-
distanceSq
public abstract double distanceSq(LatLonPoint2D p)
-
distance
public double distance(LatLonPoint2D p)
-
getVertices
public abstract List<LatLonPoint2D> getVertices()
Gets a list of LatLonPoint2D vertices in this polygon- Returns:
- the vertices
-
getVertexCount
public abstract int getVertexCount()
-
getLonCoords
public abstract double[] getLonCoords()
-
getLatCoords
public abstract double[] getLatCoords()
-
getBouningLatLonRectangle2D
public abstract LatLonRectangle2D getBouningLatLonRectangle2D()
-
getBoundingLatLonValues
public abstract double[] getBoundingLatLonValues()
Calculates the bounding box of thisLatLonPolygon2Dand returns the coordinates as adoublearray with a length of 4. The coordinates are arranged in the order of western lon, southern lat, eastern lon, and northern lat.
In terms of points where LL = lower left and UR = upper right, this is equivalent to the arrangement ofdouble[] {lly, llx, ury, urx}.- Returns:
- a
doublearray with a length of 4 containing the lat/lon points of the bounding box of thisLatLonPolygon2D. If this object contains no verticesnullis returned.
-
crossesDateline
public boolean crossesDateline()
-
copy
public LatLonPolygon2D copy()
Copies this LatLonPolygon2D to a new LatLonPolygon2D- Returns:
- a copy of this polygon
-
toString
public String toString()
Return a string representation of the polygon.
-
calculateLLArrayArea
public static double calculateLLArrayArea(double[] latLonValues)
Calculates the area of a polygon bounding box for an array of doubles in the orientation of: LLy, LLx, URy, URx- Parameters:
latLonValues- an array of doubles in the orientation of: LLy, LLx, URy, URx- Returns:
- the area of the given bounding box
-
linesIntersect
public static boolean linesIntersect(double p0x, double p0y, double p1x, double p1y, double p2x, double p2y, double p3x, double p3y)Checks if the line segment drawn from p0 to p1 intersects the line drawn from p2 to p3. This is an optimized variation ofLine2D.linesIntersect(double, double, double, double, double, double, double, double)- Parameters:
p0x- the first points x valuep0y- the first points y valuep1x- the second points x valuep1y- the second point's y valuep2x- the third point's x valuep2y- the third point's y valuep3x- the fourth point's x valuep3y- the fourth point's y value- Returns:
trueif the lines created from the given points intersect, otherwisefalse
-
lineIntersectsPoint
public static boolean lineIntersectsPoint(double e0x, double e0y, double e1x, double e1y, double p1x, double p1y)Checks if the point given by p1x, p1y is intersected by the line segment given by e0, e1- Parameters:
e0x- the line segment's first endpoint's x valuee0y- the line segment's first endpoint's y valuee1x- the line segment's second endpoint's x valuee1y- the line segment's second endpoint's y valuep1x- the point's x valuep1y- the point's y value- Returns:
trueif the point is intersected by the given line segment, otherwisefalse
-
-