org.opengts.util
Class GeoPolygon

java.lang.Object
  extended by org.opengts.util.GeoPolygon
All Implemented Interfaces:
java.lang.Cloneable

public class GeoPolygon
extends java.lang.Object
implements java.lang.Cloneable

A container for a polygon composed of GeoPoints


Constructor Summary
GeoPolygon(double[][] gp)
          Point constructor
GeoPolygon(float[][] gp)
          Point constructor
GeoPolygon(GeoPoint... gp)
          Point constructor
GeoPolygon(GeoPointProvider... gpp)
          Point constructor
GeoPolygon(GeoPolygon other)
          Copy constructor
GeoPolygon(java.util.List<GeoPoint> gpList)
          Point constructor
GeoPolygon(java.lang.String name, double[][] gp)
          Name/point constructor
GeoPolygon(java.lang.String name, float[][] gp)
          Name/point constructor
GeoPolygon(java.lang.String name, GeoPoint... gp)
          Name/point constructor
GeoPolygon(java.lang.String name, java.util.List<GeoPoint> gpList)
          Name/point constructor
 
Method Summary
 void addGeoPoint(GeoPoint gp)
          Add point to polygon
 void addNegativeRing(GeoPolygon geoPoly)
          Adds an inner polygon which is defines an area which is not part of the outer polygon.
No validation is performed to ensure that the specified polygon is a propper inner polygon.
 void addNegativeRings(java.util.Collection<GeoPolygon> geoPolyList)
          Adds an inner polygon which is defines an area which is not part of the outer polygon.
No validation is performed to ensure that the specified polygon is a propper inner polygon.
 java.lang.Object clone()
          Shallow copy
 boolean closePolygon()
          Closes this GeoPolygon (making sure last point is equal to first point)
static GeoPoint[] closePolygon(GeoPoint[] gp)
          Closes the polygon represented by the list of points
 boolean containsPoint(GeoPoint gp)
          Returns true if the specified point is inside the polygon, same as isPointInside()
static boolean containsPoint(GeoPoint gp, GeoPoint... pp)
          Returns true if the specified point is inside the polygon formed by a specified list of points, same as isPointInside()
NOTE: The list of points MUST represent a closed polygon.
 GeoBounds getGeoBounds()
          Gets the GeoBounds of this GeoPolygon
 GeoPoint getGeoPoint(int gpi)
          Return the GeoPoint at the specified index
 GeoPoint[] getGeoPoints()
          Return the array of points that make up the polygon
static GeoPoint[] getGeoPoints(GeoPolygon geoPoly)
          Return the array of GeoPoints from the specified GeoPolygon
static GeozoneChecker getGeozoneChecker()
          Gets a GeozoneChecker implemtation
 java.lang.String getName()
          Gets the name of the polygon
 java.util.List<GeoPolygon> getNegativeRings()
          Gets the list of inner negative rings
 java.lang.String getPointCountString()
          Gets a String representation of the number of points this polygon contains.
 int getSize()
          Return the number of points in the polygon
 boolean hasNegativeRings()
          Returns true if this GeoPolygon has negative rings
 void insertGeoPoint(GeoPoint gp, int ndx)
          Insert point into polygon
 boolean isClockwise()
          Returns true if the points in this polygon are oriented clockwise.
static boolean isClockwise(GeoPoint... pp)
          Returns true if the points in this polygon are oriented clockwise.
 boolean isClosed()
          Returns true if this polygon is closed
static boolean isClosed(GeoPoint[] gp)
          Returns true if the specified points represent a closed polygon
 boolean isEmpty()
          Return true if this polygon is empty
 boolean isPointInside(GeoPoint gp)
          Returns true if the specified point is inside the polygon
static boolean isPointInside(GeoPoint gp, GeoPoint... pp)
          Returns true if the specified point is inside the polygon formed by a specified list of points
NOTE: The list of points MUST represent a closed polygon.
 boolean isValid()
          Return true if this polygon is valid
static void main(java.lang.String[] argv)
          Main entry point for testing/debugging
static GeoPolygon parseGeoPolygon(java.lang.String polyStr)
           
 void setName(java.lang.String name)
          Sets the name of the polygon
 int size()
           
 java.lang.String toString()
          Returns a String representation of this class.
Currently, this simply includes the number of points this polygon contains.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GeoPolygon

public GeoPolygon(GeoPoint... gp)
Point constructor

Parameters:
gp - A list of GeoPoints

GeoPolygon

public GeoPolygon(GeoPointProvider... gpp)
Point constructor

Parameters:
gpp - A list of GeoPointProviders

GeoPolygon

public GeoPolygon(java.util.List<GeoPoint> gpList)
Point constructor

Parameters:
gpList - A list of GeoPoints

GeoPolygon

public GeoPolygon(float[][] gp)
Point constructor

Parameters:
gp - An array of lattitude/longitude pairs

GeoPolygon

public GeoPolygon(double[][] gp)
Point constructor

Parameters:
gp - An array of lattitude/longitude pairs

GeoPolygon

public GeoPolygon(java.lang.String name,
                  GeoPoint... gp)
Name/point constructor

Parameters:
name - The name of the polygon
gp - A list of GeoPoints

GeoPolygon

public GeoPolygon(java.lang.String name,
                  java.util.List<GeoPoint> gpList)
Name/point constructor

Parameters:
name - The name of the polygon
gpList - A list of GeoPoints

GeoPolygon

public GeoPolygon(java.lang.String name,
                  float[][] gp)
Name/point constructor

Parameters:
name - The name of the polygon
gp - An array of lattitude/longitude pairs

GeoPolygon

public GeoPolygon(java.lang.String name,
                  double[][] gp)
Name/point constructor

Parameters:
name - The name of the polygon
gp - An array of lattitude/longitude pairs

GeoPolygon

public GeoPolygon(GeoPolygon other)
Copy constructor

Method Detail

parseGeoPolygon

public static GeoPolygon parseGeoPolygon(java.lang.String polyStr)

getName

public java.lang.String getName()
Gets the name of the polygon

Returns:
The name of the polygon

setName

public void setName(java.lang.String name)
Sets the name of the polygon

Parameters:
name - The name of the polygon

isEmpty

public boolean isEmpty()
Return true if this polygon is empty

Returns:
True if the polygon is empty

isValid

public boolean isValid()
Return true if this polygon is valid

Returns:
True if the polygon is valid

getGeoPoints

public static GeoPoint[] getGeoPoints(GeoPolygon geoPoly)
Return the array of GeoPoints from the specified GeoPolygon

Parameters:
geoPoly - The GeoPolygon
Returns:
The list of contained GeoPoints

getGeoPoints

public GeoPoint[] getGeoPoints()
Return the array of points that make up the polygon

Returns:
The array of points that make up the polygon

getGeoPoint

public GeoPoint getGeoPoint(int gpi)
Return the GeoPoint at the specified index

Parameters:
gpi - The GeoPoint index
Returns:
The GeoPoint at the specified index

insertGeoPoint

public void insertGeoPoint(GeoPoint gp,
                           int ndx)
Insert point into polygon

Parameters:
gp - The point to insert into the polygon
ndx - The index to insert the point at

addGeoPoint

public void addGeoPoint(GeoPoint gp)
Add point to polygon

Parameters:
gp - The point to add to the polygon

isClosed

public static boolean isClosed(GeoPoint[] gp)
Returns true if the specified points represent a closed polygon

Parameters:
gp - The set of points representing a polygon
Returns:
True if the represented polygon is closed

isClosed

public boolean isClosed()
Returns true if this polygon is closed

Returns:
True if this polygon is closed

closePolygon

public static GeoPoint[] closePolygon(GeoPoint[] gp)
Closes the polygon represented by the list of points

Returns:
A closed polygon

closePolygon

public boolean closePolygon()
Closes this GeoPolygon (making sure last point is equal to first point)

Returns:
True if able to close GeoPolygon, false otherwise

getGeoBounds

public GeoBounds getGeoBounds()
Gets the GeoBounds of this GeoPolygon

Returns:
The GeoBounds

getSize

public int getSize()
Return the number of points in the polygon

Returns:
The number of points in the polygon

size

public int size()
See Also:
getSize()

containsPoint

public boolean containsPoint(GeoPoint gp)
Returns true if the specified point is inside the polygon, same as isPointInside()

Parameters:
gp - The point to check if is inside the polygon
Returns:
True if the specified point is inside the polygon
See Also:
isPointInside(GeoPoint gp)

isPointInside

public boolean isPointInside(GeoPoint gp)
Returns true if the specified point is inside the polygon

Parameters:
gp - The point to check if is inside the polygon
Returns:
True if the specified point is inside the polygon

containsPoint

public static boolean containsPoint(GeoPoint gp,
                                    GeoPoint... pp)
Returns true if the specified point is inside the polygon formed by a specified list of points, same as isPointInside()
NOTE: The list of points MUST represent a closed polygon.

Parameters:
gp - The point to check if is inside the polygon
Returns:
True if the specified point is inside the polygon
See Also:
isPointInside(GeoPoint gp, GeoPoint... pp)

isPointInside

public static boolean isPointInside(GeoPoint gp,
                                    GeoPoint... pp)
Returns true if the specified point is inside the polygon formed by a specified list of points
NOTE: The list of points MUST represent a closed polygon.

Parameters:
gp - The point to check if is inside the polygon
Returns:
True if the specified point is inside the polygon

isClockwise

public boolean isClockwise()
Returns true if the points in this polygon are oriented clockwise. Undeterminate if polygon is invalid

Returns:
True if the polygon is oriented clockwise

isClockwise

public static boolean isClockwise(GeoPoint... pp)
Returns true if the points in this polygon are oriented clockwise. Indeterminate if polygon is invalid

Parameters:
pp - The GeoPoints comprising the polygon
Returns:
True if the polygon is oriented clockwise, false otherwise

clone

public java.lang.Object clone()
Shallow copy

Overrides:
clone in class java.lang.Object

getPointCountString

public java.lang.String getPointCountString()
Gets a String representation of the number of points this polygon contains. Negative polygons counts are listed within parenthesis. IE. 234(5,10,6)

Returns:
A String representation of the number of points this polygon contains.

toString

public java.lang.String toString()
Returns a String representation of this class.
Currently, this simply includes the number of points this polygon contains. Negative polygons counts are listed within parenthesis. IE. 234(5,10,6)

Overrides:
toString in class java.lang.Object
Returns:
A String representation of this class.

addNegativeRings

public void addNegativeRings(java.util.Collection<GeoPolygon> geoPolyList)
Adds an inner polygon which is defines an area which is not part of the outer polygon.
No validation is performed to ensure that the specified polygon is a propper inner polygon.

Parameters:
geoPolyList - The inner negative rings

addNegativeRing

public void addNegativeRing(GeoPolygon geoPoly)
Adds an inner polygon which is defines an area which is not part of the outer polygon.
No validation is performed to ensure that the specified polygon is a propper inner polygon.

Parameters:
geoPoly - The inner negative ring

getNegativeRings

public java.util.List<GeoPolygon> getNegativeRings()
Gets the list of inner negative rings

Returns:
The list of inner negative rings

hasNegativeRings

public boolean hasNegativeRings()
Returns true if this GeoPolygon has negative rings


getGeozoneChecker

public static GeozoneChecker getGeozoneChecker()
Gets a GeozoneChecker implemtation

Returns:
A GeozoneChecker implementation

main

public static void main(java.lang.String[] argv)
Main entry point for testing/debugging

Parameters:
argv - Comand-line arguments