com.moximedia.aims
Class AimsPolygon

java.lang.Object
  extended bycom.moximedia.aims.AimsPolygon
All Implemented Interfaces:
AimsShapeObject, java.lang.Cloneable, java.io.Serializable

public class AimsPolygon
extends java.lang.Object
implements AimsShapeObject, java.lang.Cloneable, java.io.Serializable

Implementation of an ArcIMS polygon.

See Also:
Serialized Form

Field Summary
 
Fields inherited from interface com.moximedia.aims.AimsShapeObject
SHAPE_TYPE_ENVELOPE, SHAPE_TYPE_MULTIPOINT, SHAPE_TYPE_POINT, SHAPE_TYPE_POLYGON, SHAPE_TYPE_POLYLINE
 
Constructor Summary
AimsPolygon()
          Creates a new polygon object with no arguments.
AimsPolygon(AimsPoints pts)
          Creates a new AimsPolygon object with an AimsPoints object.
AimsPolygon(AimsRing ring)
          Creates a new AimsPolygon object with an AimsRing object.
AimsPolygon(com.vividsolutions.jts.geom.MultiPolygon multipoly)
          Creates a new AimsPolygon using a JTS MultiPolygon.
AimsPolygon(com.vividsolutions.jts.geom.Polygon poly)
          Creates a new AimsPolygon using a JTS Polygon.
 
Method Summary
 void addHole(AimsHole hole)
          Adds a hole to the polygon
 AimsRing addRing()
          Adds a new ring to the polygon, and returns the ring object.
 void addRing(AimsRing ring)
          Adds a new ring to the polygon.
 boolean addVertexToClosestLineSegment(AimsPoint pt)
          Adds a vertex to the closest line segment.
protected  boolean addVertexToSegmentAtDistance(AimsPoint pt, double segmentDistance)
           
 AimsPolygon buffer(double distance)
          Returns a new polygon that is a buffered polygon of this one.
 java.lang.Object clone()
          Clones this object.
 boolean contains(AimsPoint pt)
          Tests to see if the polygon contains a point.
 boolean contains(AimsPolygon polygon)
           
 boolean contains(AimsRing ring)
          Tests to see if the polygon contains a ring.
 void densify(double distance)
          Densifies the points in the shape by a distance.
 AimsPolygon difference(AimsPolygon polygon)
          Returns a new polygon representing the difference between this polygon and another one.
 void fix()
          Fixes a polygon where rings are added that should be holes.
 void generalize(double distance)
          Generalizes the points in the shape by a distance.
 double getArea()
          Returns the polygon of the polygon, in square map units.
 AimsPoint getClosestVertex(AimsPoint pt)
          Gets the closest vertex in the AimsPolygon to the specified point.
 double getDistanceToClosestLineSegment(AimsPoint pt)
           
 AimsEnvelope getExtent()
          Returns the extent of the polygon, or null if the polygon has no points.
 AimsPoints getPoints()
          Gets the edge points of the polygon, including the internal holes.
 AimsRing getRing(int index)
          Returns the ring at the specified index.
 java.util.Vector getRings()
          Returns the rings of the polygon as a Vector.
 int getShapeType()
           
 boolean hasHoles()
          Reports whether the polygon has holes.
 AimsPolygon intersection(AimsPolygon polygon)
          Returns a new polygon representing the intersection of this polygon and another one.
 boolean intersects(AimsPolygon poly)
          Tests whether a polygon intersects this polygon.
 boolean isValid()
          Returns a boolean indicator of whether this shape is valid.
static AimsPolygon merge(AimsPolygon polygon1, AimsPolygon polygon2)
          Deprecated. This routine does not allow polygons with holes to be merged. Use union instead.
 boolean movePoint(AimsPoint ptFrom, AimsPoint ptTo)
          Moves a point of the polygon (interior or exterior).
 void offsetBy(AimsPoint offset)
          Offsets the points in the polygon by the x and y in a point.
 boolean removePoint(AimsPoint pt)
          Removes a point from the polygon (interior or exterior).
 void setPoints(AimsPoints pts)
          Sets the points of the polygon object.
 AimsPolygon symDifference(AimsPolygon polygon)
          Returns a new polygon representing the difference between this polygon and another one.
 java.lang.String toAxlString()
          Returns the AXL string to refresh this object.
 java.lang.String toAxlString(AimsEnvironment env)
          Returns the AXL string to refresh this object.
 java.lang.String toGmlString()
          Returns the GML text string representing this polygon.
 com.vividsolutions.jts.geom.Geometry toJtsGeometry()
          Returns this object as a JTS Geometry object (Polygon or MultiPolygon).
 java.lang.String toString()
          Returns a text representation of of this object.
 boolean touches(AimsPolygon polygon)
           
 AimsPolygon union(AimsPolygon polygon)
          Returns a new polygon representing the union of this polygon and another one.
 boolean within(AimsPolygon polygon)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AimsPolygon

public AimsPolygon()
Creates a new polygon object with no arguments.


AimsPolygon

public AimsPolygon(AimsPoints pts)
Creates a new AimsPolygon object with an AimsPoints object.


AimsPolygon

public AimsPolygon(AimsRing ring)
Creates a new AimsPolygon object with an AimsRing object.


AimsPolygon

public AimsPolygon(com.vividsolutions.jts.geom.Polygon poly)
Creates a new AimsPolygon using a JTS Polygon.

Parameters:
poly - The JTS Polygon.

AimsPolygon

public AimsPolygon(com.vividsolutions.jts.geom.MultiPolygon multipoly)
Creates a new AimsPolygon using a JTS MultiPolygon.

Parameters:
multipoly - The JTS MultiPolygon.
Method Detail

getShapeType

public int getShapeType()
Specified by:
getShapeType in interface AimsShapeObject

addRing

public AimsRing addRing()
Adds a new ring to the polygon, and returns the ring object.

Returns:
The ring added to the polygon.

addRing

public void addRing(AimsRing ring)
Adds a new ring to the polygon.

Parameters:
ring - The ring to add to the polygon.

getArea

public double getArea()
Returns the polygon of the polygon, in square map units.

Returns:
The area of the polygon, minus the area of any holes.

getRings

public java.util.Vector getRings()
Returns the rings of the polygon as a Vector.

Returns:
A Vector containing the rings.

getRing

public AimsRing getRing(int index)
Returns the ring at the specified index.

Returns:
The ring, or null if no ring exists at the specified index.

contains

public boolean contains(AimsPoint pt)
Tests to see if the polygon contains a point.

Returns:
True if the polygon contains the point, otherwise false.

contains

public boolean contains(AimsRing ring)
Tests to see if the polygon contains a ring.

Returns:
True if the polygon contains the ring, otherwise false.

intersects

public boolean intersects(AimsPolygon poly)
Tests whether a polygon intersects this polygon.

Parameters:
poly - Another polygon.
Returns:
True if the polygon intersects this one, otherwise false.

getClosestVertex

public AimsPoint getClosestVertex(AimsPoint pt)
Gets the closest vertex in the AimsPolygon to the specified point. This routine uses the ring and hole vertexes for comparison.

Parameters:
pt - The point to compare the vertexes to.
Returns:
The closest vertex to the specified point, or null if there are no points in the polygon.

densify

public void densify(double distance)
Densifies the points in the shape by a distance.

Parameters:
distance - The densify distance.

generalize

public void generalize(double distance)
Generalizes the points in the shape by a distance.

Parameters:
distance - The generalize distance.

offsetBy

public void offsetBy(AimsPoint offset)
Offsets the points in the polygon by the x and y in a point.

Parameters:
offset - An AimsPoint object containing the offset.

setPoints

public void setPoints(AimsPoints pts)
Sets the points of the polygon object.


getPoints

public AimsPoints getPoints()
Gets the edge points of the polygon, including the internal holes.

Returns:
The edge points of the polygon, including the internal holes.

removePoint

public boolean removePoint(AimsPoint pt)
Removes a point from the polygon (interior or exterior).

Parameters:
pt - The point to remove,
Returns:
True if the point is removed, otherwise false.

movePoint

public boolean movePoint(AimsPoint ptFrom,
                         AimsPoint ptTo)
Moves a point of the polygon (interior or exterior).

Parameters:
ptFrom - The point to move.
ptTo - Where to move it.
Returns:
True if the point is moved, otherwise false.

getDistanceToClosestLineSegment

public double getDistanceToClosestLineSegment(AimsPoint pt)

addVertexToSegmentAtDistance

protected boolean addVertexToSegmentAtDistance(AimsPoint pt,
                                               double segmentDistance)

addVertexToClosestLineSegment

public boolean addVertexToClosestLineSegment(AimsPoint pt)
Adds a vertex to the closest line segment.

Parameters:
pt - The point to add to the line segment. A vertex will be added to the portion of the line segment closest to the point position.

getExtent

public AimsEnvelope getExtent()
Returns the extent of the polygon, or null if the polygon has no points.

Returns:
An AimsEnvelope containing the extent.

toString

public java.lang.String toString()
Returns a text representation of of this object.

Returns:
A string describing the object

toAxlString

public java.lang.String toAxlString()
Returns the AXL string to refresh this object. This method is not typically used by the application programmer.

Specified by:
toAxlString in interface AimsShapeObject
Returns:
The AXL string to refresh this object.

toAxlString

public java.lang.String toAxlString(AimsEnvironment env)
Returns the AXL string to refresh this object. This method is not typically used by the application programmer.

Specified by:
toAxlString in interface AimsShapeObject
Returns:
The AXL string to refresh this object.

toGmlString

public java.lang.String toGmlString()
Returns the GML text string representing this polygon.

Specified by:
toGmlString in interface AimsShapeObject
Returns:
The GML text string representing this polygon.

clone

public java.lang.Object clone()
Clones this object.

Specified by:
clone in interface AimsShapeObject
Returns:
The clone of this object as an Object. Must be cast back to the proper object type before use.

hasHoles

public boolean hasHoles()
Reports whether the polygon has holes.

Returns:
True if the polygon has holes, otherwise false.

merge

public static AimsPolygon merge(AimsPolygon polygon1,
                                AimsPolygon polygon2)
Deprecated. This routine does not allow polygons with holes to be merged. Use union instead.

Merges two polygons. Cannot merge polygons with holes.

Parameters:
polygon1 - The first polygon to merge.
polygon2 - The second polygon to merge.
Returns:
The merged polygon.

fix

public void fix()
Fixes a polygon where rings are added that should be holes.


addHole

public void addHole(AimsHole hole)
Adds a hole to the polygon

Parameters:
hole - The hole to add to the polygon.

toJtsGeometry

public com.vividsolutions.jts.geom.Geometry toJtsGeometry()
Returns this object as a JTS Geometry object (Polygon or MultiPolygon).

Returns:
This object as a JTS Geometry object (Polygon or MultiPolygon).

buffer

public AimsPolygon buffer(double distance)
Returns a new polygon that is a buffered polygon of this one.

Parameters:
distance - The buffer distance.
Returns:
A new polygon that is this polygon buffered by the specified distance.

difference

public AimsPolygon difference(AimsPolygon polygon)
Returns a new polygon representing the difference between this polygon and another one.

Parameters:
polygon - Another polygon to calculate the difference.
Returns:
The difference polygon.

intersection

public AimsPolygon intersection(AimsPolygon polygon)
Returns a new polygon representing the intersection of this polygon and another one.

Parameters:
polygon - Another polygon to intersect with this one.
Returns:
The intersection polygon.

symDifference

public AimsPolygon symDifference(AimsPolygon polygon)
Returns a new polygon representing the difference between this polygon and another one.

Parameters:
polygon - Another polygon to determine difference.
Returns:
The difference polygon.

union

public AimsPolygon union(AimsPolygon polygon)
Returns a new polygon representing the union of this polygon and another one.

Parameters:
polygon - Another polygon to union with this one.
Returns:
The unioned polygon.

contains

public boolean contains(AimsPolygon polygon)

touches

public boolean touches(AimsPolygon polygon)

within

public boolean within(AimsPolygon polygon)

isValid

public boolean isValid()
Returns a boolean indicator of whether this shape is valid.

Specified by:
isValid in interface AimsShapeObject
Returns:
True if the shape is valid, otherwise false.