org.geotools.renderer.geom
Class Polygon

java.lang.Object
  extended byorg.geotools.renderer.geom.Geometry
      extended byorg.geotools.renderer.geom.Polyline
          extended byorg.geotools.renderer.geom.Polygon
All Implemented Interfaces:
java.lang.Cloneable, org.opengis.util.Cloneable, java.io.Serializable, java.awt.Shape

public class Polygon
extends Polyline

A polygon bounded by one exterior ring (the "shell") and zero or more interior rings (the "holes"). Shell and holes are stored as Polyline objects.

Version:
$Id: Polygon.java 17672 2006-01-19 00:25:55Z desruisseaux $
Author:
Martin Desruisseaux
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.geotools.renderer.geom.Geometry
DEFAULT_COORDINATE_SYSTEM
 
Constructor Summary
Polygon(Polyline shell)
          Construct a polygon from the specified polyline.
Polygon(java.awt.geom.Rectangle2D rectangle, CoordinateSystem coordinateSystem)
          Construct a polygon from the specified rectangle.
 
Method Summary
 void addHole(Polyline hole)
          Add a hole to this polygon.
 Geometry clip(Clipper clipper)
          Returns a polygon approximately equal to this polygon clipped to the specified bounds.
 java.lang.Object clone()
          Return a clone of this geometry.
 float compress(CompressionLevel level)
          Compress this polygon.
 boolean contains(double x, double y)
          Tests if the specified coordinates are inside the boundary of this polygon.
 boolean contains(java.awt.Shape shape)
          Test if the interior of this polygon entirely contains the given shape.
 boolean equals(java.lang.Object object)
          Compare the specified object with this polygon for equality.
 java.lang.String getName(java.util.Locale locale)
          Returns the localized name for this polygon.
 java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform transform)
          Returns a path iterator for this polyline.
 int getPointCount()
          Return the number of points in this polygon.
 Statistics getResolution()
          Returns the polygon's resolution.
 int hashCode()
          Returns a hash code for this polygon.
 boolean intersects(java.awt.Shape shape)
          Tests if the interior of this polygon intersects the interior of a specified shape.
 void reverse()
          Reverse point order in this polygon.
 void setCoordinateSystem(CoordinateSystem coordinateSystem)
          Set the polygon's coordinate system.
 void setName(java.lang.String name)
          Set a default name for this polygon.
 void setRenderingResolution(float resolution)
          Hints this polygon that the specified resolution is sufficient for rendering.
 void setResolution(double resolution)
          Sets the polygon's resolution.
 
Methods inherited from class org.geotools.renderer.geom.Polyline
append, append, appendBorder, close, contains, contains, getBounds2D, getCachedPointCount, getCoordinateSystem, getFirstPoint, getFirstPoints, getLastPoint, getLastPoints, getPoints, getRenderingResolution, intersects, isClosed, isEmpty, prependBorder, print, print, print, readObject, subpoly, toArray
 
Methods inherited from class org.geotools.renderer.geom.Geometry
contains, getBounds, getID, getPathIterator, getStyle, getUserObject, intersects, setID, setStyle, setUserObject, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Polygon

public Polygon(Polyline shell)
Construct a polygon from the specified polyline.

Parameters:
shell - The exterior ring.

Polygon

public Polygon(java.awt.geom.Rectangle2D rectangle,
               CoordinateSystem coordinateSystem)
Construct a polygon from the specified rectangle. The polygon will be empty if the rectangle was empty or contains at least one NaN value.

Parameters:
rectangle - Rectangle to copy in the new Polygon.
coordinateSystem - The rectangle's coordinate system, or null if unknown.
Method Detail

getName

public java.lang.String getName(java.util.Locale locale)
Returns the localized name for this polygon. The default implementation returns the last name set by setName(java.lang.String).

Overrides:
getName in class Geometry
Parameters:
locale - The desired locale. If no name is available for this locale, a default locale will be used.
Returns:
The polygon's name, localized if possible.

setName

public void setName(java.lang.String name)
Set a default name for this polygon. For example, a polygon may have the name of a lake or an island. This name may be null if this polygon is unnamed.


setCoordinateSystem

public void setCoordinateSystem(CoordinateSystem coordinateSystem)
                         throws org.opengis.referencing.operation.TransformException,
                                UnmodifiableGeometryException
Set the polygon's coordinate system. Calling this method is equivalents to reproject all polygon's points from the old coordinate system to the new one.

Overrides:
setCoordinateSystem in class Polyline
Parameters:
coordinateSystem - The new coordinate system. A null value reset the default coordinate system (usually the one that best fits internal data).
Throws:
org.opengis.referencing.operation.TransformException - If a transformation failed. In case of failure, the state of this object will stay unchanged, as if this method has never been invoked.
UnmodifiableGeometryException - if modifying this geometry would corrupt a container. To avoid this exception, clone this geometry before to modify it.

addHole

public void addHole(Polyline hole)
             throws org.opengis.referencing.operation.TransformException,
                    UnmodifiableGeometryException
Add a hole to this polygon.

Parameters:
hole - The hole to add.
Throws:
org.opengis.referencing.operation.TransformException - if the hole uses an incompatible coordinate system.
java.lang.IllegalArgumentException - if the hole is not inside the exterior ring.
UnmodifiableGeometryException - if modifying this geometry would corrupt a container. To avoid this exception, clone this geometry before to modify it.
Task:
TODO: The check for hole inclusion should use 'contains(Shape)'. However, this is an expensive check in current version. We just check the bounding box for now. We should make a stricter check when Polyline.contains will be optimized. We should also make sure that the new hole doesn't intersect an existing hole.

reverse

public void reverse()
Reverse point order in this polygon.

Overrides:
reverse in class Polyline

getPointCount

public int getPointCount()
Return the number of points in this polygon. This number include the points in holes. It may not be the same than the number of points returned by Polyline.getPoints(), which contains the points in the exterior ring only.

Overrides:
getPointCount in class Polyline
See Also:
Polyline.isEmpty(), Polyline.getPoints(), Polyline.getFirstPoint(java.awt.geom.Point2D), Polyline.getFirstPoints(java.awt.geom.Point2D[]), Polyline.getLastPoint(java.awt.geom.Point2D), Polyline.getLastPoints(java.awt.geom.Point2D[]), Polyline.toArray(float)

contains

public boolean contains(double x,
                        double y)
Tests if the specified coordinates are inside the boundary of this polygon.

Specified by:
contains in interface java.awt.Shape
Overrides:
contains in class Polyline
Parameters:
x - the specified x coordinates in this polygon coordinate system.
y - the specified y coordinates in this polygon coordinate system.
Returns:
true if the specified coordinates are inside the polygon boundary and outside any hole; false otherwise.

contains

public boolean contains(java.awt.Shape shape)
Test if the interior of this polygon entirely contains the given shape. This method returns false if the given shape intersects a hole.

Overrides:
contains in class Polyline

intersects

public boolean intersects(java.awt.Shape shape)
Tests if the interior of this polygon intersects the interior of a specified shape. This method returns false if the given shape in entirely contained in a hole.

Overrides:
intersects in class Polyline

compress

public float compress(CompressionLevel level)
               throws org.opengis.referencing.operation.TransformException
Compress this polygon. The level argument specify the algorithm, which may be desctructive (i.e. data may loose precision).

Overrides:
compress in class Polyline
Parameters:
level - The compression level (or algorithm) to use. See the CompressionLevel javadoc for an explanation of available algorithms.
Returns:
A estimation of the compression rate. For example a value of 0.2 means that the new polyline use approximatively 20% less memory.
Throws:
org.opengis.referencing.operation.TransformException - If an error has come up during a cartographic projection.

getResolution

public Statistics getResolution()
Returns the polygon's resolution.

Overrides:
getResolution in class Polyline

setResolution

public void setResolution(double resolution)
                   throws org.opengis.referencing.operation.TransformException
Sets the polygon's resolution.

Overrides:
setResolution in class Polyline
Parameters:
resolution - Desired resolution, in the same units as Polyline.getResolution().
Throws:
org.opengis.referencing.operation.TransformException - If some coordinate transformations were needed and failed. There is no guarantee on polygon's state in case of failure.

setRenderingResolution

public void setRenderingResolution(float resolution)
Hints this polygon that the specified resolution is sufficient for rendering.

Overrides:
setRenderingResolution in class Polyline
Parameters:
resolution - The resolution to use at rendering time, in units of this polyline's coordinate system (linear or angular units).

getPathIterator

public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform transform)
Returns a path iterator for this polyline.

Specified by:
getPathIterator in interface java.awt.Shape
Overrides:
getPathIterator in class Polyline

clip

public Geometry clip(Clipper clipper)
Returns a polygon approximately equal to this polygon clipped to the specified bounds. The clip is only approximative in that the resulting polygon may extend outside the clip area. However, it is guaranteed that the resulting polygon contains at least all the interior of the clip area. If this method can't perform the clip, or if it believes that it isn't worth doing a clip, it returns this. If this polygon doesn't intersect the clip area, then this method returns null. Otherwise, a new polygon is created and returned. The new polyline will try to share as much internal data as possible with this in order to keep memory footprint low.

Overrides:
clip in class Polyline
Parameters:
clipper - The clip area.
Returns:
null if this polygon doesn't intersect the clip, this if no clip has been performed, or a new clipped polygon otherwise.

clone

public final java.lang.Object clone()
Return a clone of this geometry. The returned geometry will have a deep copy semantic. This method is final for implementation reason.

Specified by:
clone in interface org.opengis.util.Cloneable
Overrides:
clone in class Polyline

equals

public boolean equals(java.lang.Object object)
Compare the specified object with this polygon for equality.

Overrides:
equals in class Polyline

hashCode

public int hashCode()
Returns a hash code for this polygon.

Overrides:
hashCode in class Polyline


Copyright © GeoTools. All Rights Reserved.