## com.bbn.openmap.omGraphics
Class OMPoly

    java.lang.Object
      com.bbn.openmap.omGraphics.geom.BasicGeometry
          com.bbn.openmap.omGraphics.OMGraphic
              com.bbn.openmap.omGraphics.OMAbstractLine
                  com.bbn.openmap.omGraphics.OMPoly

All Implemented Interfaces:
  java.lang.Cloneable, OMGeometry, OMGraphicConstants, java.io.Serializable

Direct Known Subclasses:
  EsriPolygon, EsriPolyline, LabeledOMPoly, OMDistance, OMSpline

public class OMPoly
extends OMAbstractLine
implements java.io.Serializable

Graphic object that represents a polygon or polyline (multi-line-segment-object).

The differentiator between polygons and polylines is the fill color. If the fillPaint is equal to OMColor.clear, then the poly will be considered a polyline. There are methods to override this in the OMPoly class, but they do play around with the fillPaint, depending on the order in which the methods are called. If you know it's a polyline, call setIsPolygon(false) if you think that the fillPaint could be set to anything other than the default, OMColor.clear.

All of the OMGraphics are moving to having their internal representation as java.awt.Shape objects. Unfortunately, this has the side effect of slowing OMPolys down, because the way that the projection classes handle transformations cause more objects to be allocated and more loops to be run through. So, by default, the OMPoly does NOT use Shape objects internally, to keep layers that throw down many, many polys running quickly. If you want to do some spatial analysis on an OMPoly, call setDoShapes(true) on it, then generate(Projection), and then call getShapes() to get the java.awt.Shape objects for the poly. You can then run the different Shape spatial analysis methods on the Shape objects.

### NOTES:

- See the RESTRICTIONS on Lat/Lon polygons/polylines. Not following the guidelines listed may result in ambiguous/undefined shapes! Similar assumptions apply to the other vector graphics that we define: circles, ellipses, rects, lines.
- LatLon OMPolys store latlon coordinates internally in radian format for efficiency in projecting. Subclasses should follow this model.
- Holes in the poly are not supported.

### TODO:

- Polar filled-polygon correction for Cylindrical projections (like OMCircle).

See Also:
  `OMCircle`, `OMRect`, `OMLine`, Serialized Form

Field Summary
`protected int` `coordMode` For RENDERTYPE_OFFSET, type of offset.
`static int` `COORDMODE_ORIGIN` Translation offsets.
`static int` `COORDMODE_PREVIOUS` Delta offsets.
`protected boolean` `doShapes` Flag for telling the OMPoly to use the Shape objects to represent itself internally.
`protected boolean` `geometryClosed`
`protected boolean` `isPolygon` Poly is a polygon or a polyline.
`protected float` `lat` For RENDERTYPE_OFFSET, the latitude of the starting point of the poly.
`protected float` `lon` For RENDERTYPE_OFFSET, the longitude of the starting point of the poly.
`protected float[]` `rawllpts` raw float lats and lons stored internally in radians.
`protected int` `units` Radians or decimal degrees.
`protected int[]` `xs` The x array of ints, representing pixels, used for x/y or offset polys.
`protected int[]` `ys` The y array of ints, representing pixels, used for x/y or offset polys.

Fields inherited from class com.bbn.openmap.omGraphics.OMAbstractLine
`nsegs, xpoints, ypoints`

Fields inherited from class com.bbn.openmap.omGraphics.OMGraphic
`declutterType, displayPaint, edgeMatchesFill, fillPaint, hasLabel, linePaint, matted, mattingPaint, renderType, selected, selectPaint, showEditablePalette, stroke, textureMask`

Fields inherited from class com.bbn.openmap.omGraphics.geom.BasicGeometry
`APP_OBJECT_KEY, appObject, ATT_MAP_KEY, lineType, needToRegenerate, shape, visible`

Fields inherited from interface com.bbn.openmap.omGraphics.OMGraphicConstants

`ADD_GRAPHIC_MASK, BASIC_STROKE, CHANGE_APPEARANCE, clear, DECIMAL_DEGREES, DECLUTTERTYPE_LINE, DECLUTTERTYPE_MOVE, DECLUTTERTYPE_NONE, DECLUTTERTYPE_SPACE, DEFAULT_ROTATIONANGLE, DELETE_GRAPHIC_MASK, DESELECT_GRAPHIC_MASK, DESELECTALL_GRAPHIC_MASK, GRAPHICTYPE_ARC, GRAPHICTYPE_BITMAP, GRAPHICTYPE_CIRCLE, GRAPHICTYPE_ELLIPSE, GRAPHICTYPE_GRAPHIC, GRAPHICTYPE_GRID, GRAPHICTYPE_LINE, GRAPHICTYPE_POINT, GRAPHICTYPE_POLY, GRAPHICTYPE_RASTER, GRAPHICTYPE_RECTANGLE, GRAPHICTYPE_TEXT, INFOLINE, LABEL, LINETYPE_GREATCIRCLE, LINETYPE_RHUMB, LINETYPE_STRAIGHT, LINETYPE_UNKNOWN, LOWER_GRAPHIC_MASK, LOWER_TO_BOTTOM_GRAPHIC_MASK, RADIANS, RAISE_GRAPHIC_MASK, RAISE_TO_TOP_GRAPHIC_MASK, REMOVABLE, RENDERTYPE_LATLON, RENDERTYPE_OFFSET, RENDERTYPE_UNKNOWN, RENDERTYPE_XY, SELECT_GRAPHIC_MASK, SORT_GRAPHICS_MASK, TOOLTIP, UPDATE_GRAPHIC_MASK`

Constructor Summary
`OMPoly()` Construct a default OMPoly.
`OMPoly(float[] llPoints, int units, int lType)` Create an OMPoly from a list of float lat/lon pairs.
`OMPoly(float[] llPoints, int units, int lType, int nsegs)` Create an OMPoly from a list of float lat/lon pairs.
`OMPoly(float latPoint, float lonPoint, int[] xypoints, int cMode)` Create an x/y OMPoly at an offset from lat/lon.
`OMPoly(float latPoint, float lonPoint, int[] xPoints, int[] yPoints, int cMode)` Create an x/y OMPoly at an offset from lat/lon.
`OMPoly(int[] xypoints)` Create an OMPoly from a list of xy pairs.
`OMPoly(int[] xPoints, int[] yPoints)` Create an x/y OMPoly.

Method Summary
`protected boolean` `checkPoints(int[][] xpoints2, int[][] ypoints2)` Return true if the xpoints and ypoints are not null and contain coordinates.
`protected void` `createShape()` Since OMPoly has the option to not create a Shape, this method is here to create it if it is asked for.
`float` `distance(int x, int y)` Return the shortest distance from the graphic to an XY-point.
`boolean` `generate(Projection proj)` Prepare the poly for rendering.
`int` `getCoordMode()` For RENDERTYPE_OFFSET, type of offset.
`boolean` `getDoShapes()`
`float` `getLat()` Get the latitude of the offset point, in decimal degrees.
`float[]` `getLatLonArray()` Return the rawllpts array.
`float` `getLon()` Get the longitude of the offset point, in decimal degrees.
`int` `getNumSegs()` Get the number of subsegments for each segment in the poly.
`float[]` `getRawllpts()` For XMLEncoder
`java.awt.geom.GeneralPath` `getShape()` Get the array of java.awt.Shape objects that represent the projected graphic.
`int` `getUnits()` For XMLEncoder
`int[]` `getXs()` Get the array of x points.
`int[]` `getYs()` Get the array of y points.
`protected boolean` `isGeometryClosed()` Is the geometry closed ?
`boolean` `isPolygon()` Check if this is a polygon or a polyline.
`void` `render(java.awt.Graphics g)` Paint the poly.
`void` `setCoordMode(int coordMode)` For RENDERTYPE_OFFSET, type of offset.
`void` `setDoShapes(boolean set)`
`void` `setFillPaint(java.awt.Paint paint)` Set the fill Paint of the poly.
`void` `setIsPolygon(boolean set)` Set the Polyline/Polygon setting, if you know better.
`void` `setLat(float lat)` Set the latitude of the offset point, in decimal degrees.
`void` `setLocation(float[] llPoints, int units)` Set an OMPoly from a list of float lat/lon pairs.
`void` `setLocation(float latPoint, float lonPoint, int units, int[] xypoints)` Set the location based on a latitude, longitude, and some xy points.
`void` `setLocation(float latPoint, float lonPoint, int units, int[] xPoints, int[] yPoints)` Set the location based on a latitude, longitude, and some xy points.
`void` `setLocation(int[] xypoints)` Set an OMPoly from a list of xy pixel pairs.
`void` `setLocation(int[] xPoints, int[] yPoints)` Set an OMPoly from a x/y coordinates.
`void` `setLon(float lon)` Set the longitude of the offset point, in decimal degrees.
`void` `setNumSegs(int nsegs)` Set the number of subsegments for each segment in the poly.
`void` `setXs(int[] x)` Set the array of x points.
`void` `setYs(int[] y)` Set the array of y points.
`boolean` `shouldRenderFill()` Return true of the fill color/paint should be rendered (not clear).

Methods inherited from class com.bbn.openmap.omGraphics.OMAbstractLine
`addArrowHead, addArrowHead, addArrowHead, addArrowHead, createArrowHeads, getArrowDirectionType, getArrowHead, getArrowLocation, getWingLength, getWingTip, hasArrowHead, setArrowHead`

Methods inherited from class com.bbn.openmap.omGraphics.OMGraphic

`clone, deselect, getDeclutterType, getDescription, getDescription, getDisplayColor, getDisplayPaint, getEdgeMatchesFill, getFillColor, getFillPaint, getHasLabel, getLineColor, getLinePaint, getMattingPaint, getRenderType, getSelectColor, getSelectPaint, getShowEditablePalette, getStroke, getTextureMask, hasLineTypeChoice, initLabelingDuringGenerate, isClear, isMatted, isSelected, normalizeDistanceForLineWidth, regenerate, renderLabel, select, setDeclutterType, setEdgeMatchesFill, setFillColor, setGraphicsColor, setGraphicsForEdge, setGraphicsForFill, setHasLabel, setLabelLocation, setLabelLocation, setLabelLocation, setLineColor, setLinePaint, setMatted, setMattingPaint, setRenderType, setSelectColor, setSelected, setSelectPaint, setShape, setShowEditablePalette, setStroke, setTextureMask, shouldRenderEdge`

Methods inherited from class com.bbn.openmap.omGraphics.geom.BasicGeometry

`_distance, appendShapeEdge, appendShapeEdge, appendShapeEdge, appendShapeEdge, checkAttributeMap, checkAttributeMap, clearAttributes, contains, createAttributeMap, createBoxShape, createShape, createShape, describeShapeDetail, describeShapeDetail, distanceToEdge, draw, fill, getAppObject, getAppObject, getAttribute, getAttributeMap, getAttributes, getLineType, getNeedToRegenerate, isRenderable, isVisible, putAttribute, removeAttribute, replaceAppObjectWithAttributeMap, setAppObject, setAppObject, setAttributes, setLineType, setNeedToRegenerate, setVisible`

Methods inherited from class java.lang.Object
`equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Methods inherited from interface com.bbn.openmap.omGraphics.OMGeometry
`clearAttributes, contains, draw, fill, getAppObject, getAttribute, getAttributes, getLineType, getNeedToRegenerate, isRenderable, isVisible, putAttribute, removeAttribute, setAppObject, setAttributes, setLineType, setNeedToRegenerate, setVisible`

Field Detail

### COORDMODE_ORIGIN

    public static final int COORDMODE_ORIGIN

  Translation offsets. For RENDERTYPE_OFFSET, the xy points are relative to the position of fixed latlon point.

  See Also:
    Constant Field Values

### COORDMODE_PREVIOUS

    public static final int COORDMODE_PREVIOUS

  Delta offsets. For RENDERTYPE_OFFSET, each xy point in the array is relative to the previous point, and the first point is relative to the fixed latlon point.

  See Also:
    Constant Field Values

### units

    protected int units

  Radians or decimal degrees. After construction and conversion, this should always be radians.

### lat

    protected float lat

  For RENDERTYPE_OFFSET, the latitude of the starting point of the poly. Stored as radians!

### lon

    protected float lon

  For RENDERTYPE_OFFSET, the longitude of the starting point of the poly. Stored as radians!

### coordMode

    protected int coordMode

  For RENDERTYPE_OFFSET, type of offset.

  See Also:
    `COORDMODE_ORIGIN`, `COORDMODE_PREVIOUS`

### xs

    protected int[] xs

  The x array of ints, representing pixels, used for x/y or offset polys.

### ys

    protected int[] ys

  The y array of ints, representing pixels, used for x/y or offset polys.

### isPolygon

    protected boolean isPolygon

  Poly is a polygon or a polyline. This is true if the fillColor is not clear, false if it is.

### rawllpts

    protected float[] rawllpts

  raw float lats and lons stored internally in radians.

### doShapes

    protected boolean doShapes

  Flag for telling the OMPoly to use the Shape objects to represent itself internally. See intro for more info.

### geometryClosed

    protected boolean geometryClosed

Constructor Detail

### OMPoly

    public OMPoly()

  Construct a default OMPoly.

### OMPoly

    public OMPoly(float[] llPoints,
                  int units,
                  int lType)

  Create an OMPoly from a list of float lat/lon pairs.

  NOTES:

  - llPoints array is converted into radians IN PLACE for more efficient handling internally if it's not already in radians! For even better performance, you should send us an array already in radians format!
  - If you want the poly to be connected (as a polygon), you need to ensure that the first and last coordinate pairs are the same.

Parameters:
  `llPoints` - array of lat/lon points, arranged lat, lon, lat, lon, etc.
  `units` - radians or decimal degrees. Use OMGraphic.RADIANS or OMGraphic.DECIMAL_DEGREES
  `lType` - line type, from a list defined in OMGraphic.

### OMPoly

    public OMPoly(float[] llPoints,
                  int units,
                  int lType,
                  int nsegs)

  Create an OMPoly from a list of float lat/lon pairs.

  NOTES:

  - llPoints array is converted into radians IN PLACE for more efficient handling internally if it's not already in radians! For even better performance, you should send us an array already in radians format!
  - If you want the poly to be connected (as a polygon), you need to ensure that the first and last coordinate pairs are the same.

Parameters:
  `llPoints` - array of lat/lon points, arranged lat, lon, lat, lon, etc.
  `units` - radians or decimal degrees. Use OMGraphic.RADIANS or OMGraphic.DECIMAL_DEGREES
  `lType` - line type, from a list defined in OMGraphic.
  `nsegs` - number of segment points (only for LINETYPE_GREATCIRCLE or LINETYPE_RHUMB line types, and if < 1, this value is generated internally)

### OMPoly

    public OMPoly(int[] xypoints)

  Create an OMPoly from a list of xy pairs. If you want the poly to be connected, you need to ensure that the first and last coordinate pairs are the same.

Parameters:
  `xypoints` - array of x/y points, arranged x, y, x, y, etc.

### OMPoly

    public OMPoly(int[] xPoints,
                  int[] yPoints)

  Create an x/y OMPoly. If you want the poly to be connected, you need to ensure that the first and last coordinate pairs are the same.

Parameters:
  `xPoints` - int[] of x coordinates
  `yPoints` - int[] of y coordinates

### OMPoly

    public OMPoly(float latPoint,
                  float lonPoint,
                  int[] xypoints,
                  int cMode)

  Create an x/y OMPoly at an offset from lat/lon. If you want the poly to be connected, you need to ensure that the first and last coordinate pairs are the same.

Parameters:
  `latPoint` - latitude in decimal degrees
  `lonPoint` - longitude in decimal degrees
  `xypoints` - int[] of x,y pairs
  `cMode` - offset coordinate mode

### OMPoly

    public OMPoly(float latPoint,
                  float lonPoint,
                  int[] xPoints,
                  int[] yPoints,
                  int cMode)

  Create an x/y OMPoly at an offset from lat/lon. If you want the poly to be connected, you need to ensure that the first and last coordinate pairs are the same.

Parameters:
  `latPoint` - latitude in decimal degrees
  `lonPoint` - longitude in decimal degrees
  `xPoints` - int[] of x coordinates
  `yPoints` - int[] of y coordinates
  `cMode` - offset coordinate mode

Method Detail

### setLocation

    public void setLocation(float[] llPoints,
                            int units)

  Set an OMPoly from a list of float lat/lon pairs.

  NOTES:

  - llPoints array is converted into radians IN PLACE for more efficient handling internally if it's not already in radians! If you don't want the array to be changed, send in a copy.
  - If you want the poly to be connected (as a polygon), you need to ensure that the first and last coordinate pairs are the same.
  This is for RENDERTYPE_LATLON polys.

  Parameters:
    `llPoints` - array of lat/lon points, arranged lat, lon, lat, lon, etc.
    `units` - radians or decimal degrees. Use OMGraphic.RADIANS or OMGraphic.DECIMAL_DEGREES

### setLocation

    public void setLocation(int[] xypoints)

  Set an OMPoly from a list of xy pixel pairs. If you want the poly to be connected, you need to ensure that the first and last coordinate pairs are the same. This is for RENDERTYPE_XY polys.

  Parameters:
    `xypoints` - array of x/y points, arranged x, y, x, y, etc.

### setLocation

    public void setLocation(int[] xPoints,
                            int[] yPoints)

  Set an OMPoly from a x/y coordinates. If you want the poly to be connected, you need to ensure that the first and last coordinate pairs are the same. This is for RENDERTYPE_XY polys.

  Parameters:
    `xPoints` - int[] of x coordinates
    `yPoints` - int[] of y coordinates

### setLocation

    public void setLocation(float latPoint,
                            float lonPoint,
                            int units,
                            int[] xypoints)

  Set the location based on a latitude, longitude, and some xy points. The coordinate mode and the polygon setting are the same as in the constructor used. This is for RENDERTYPE_OFFSET polys.

  Parameters:
    `latPoint` - latitude in decimal degrees
    `lonPoint` - longitude in decimal degrees
    `units` - radians or decimal degrees. Use OMGraphic.RADIANS or OMGraphic.DECIMAL_DEGREES
    `xypoints` - array of x/y points, arranged x, y, x, y, etc.

### setLocation

    public void setLocation(float latPoint,
                            float lonPoint,
                            int units,
                            int[] xPoints,
                            int[] yPoints)

  Set the location based on a latitude, longitude, and some xy points. The coordinate mode and the polygon setting are the same as in the constructor used. This is for RENDERTYPE_OFFSET polys.

  Parameters:
    `latPoint` - latitude in decimal degrees
    `lonPoint` - longitude in decimal degrees
    `units` - radians or decimal degrees. Use OMGraphic.RADIANS or OMGraphic.DECIMAL_DEGREES
    `xPoints` - int[] of x coordinates
    `yPoints` - int[] of y coordinates

### getLatLonArray

    public float[] getLatLonArray()

  Return the rawllpts array. NOTE: this is an unsafe method to access the rawllpts array. Use with caution. These are RADIANS!

  Returns:
    float[] rawllpts of lat, lon, lat, lon

### setLat

    public void setLat(float lat)

  Set the latitude of the offset point, in decimal degrees. For RENDERTYPE_OFFSET Polygons.

### getLat

    public float getLat()

  Get the latitude of the offset point, in decimal degrees. For RENDERTYPE_OFFSET Polygons.

### setLon

    public void setLon(float lon)

  Set the longitude of the offset point, in decimal degrees. For RENDERTYPE_OFFSET Polygons.

### getLon

    public float getLon()

  Get the longitude of the offset point, in decimal degrees. For RENDERTYPE_OFFSET Polygons.

### setXs

    public void setXs(int[] x)

  Set the array of x points. For RENDERTYPE_OFFSET, RENDERTYPE_XY polys.

### getXs

    public int[] getXs()

  Get the array of x points. For RENDERTYPE_OFFSET, RENDERTYPE_XY polys.

### setYs

    public void setYs(int[] y)

  Set the array of y points. For RENDERTYPE_OFFSET, RENDERTYPE_XY polys.

### getYs

    public int[] getYs()

  Get the array of y points. For RENDERTYPE_OFFSET, RENDERTYPE_XY polys.

### setFillPaint

    public void setFillPaint(java.awt.Paint paint)

  Set the fill Paint of the poly. If the color value is non-clear, then the poly is a polygon (connected and filled), otherwise it's a polyline (non-filled).

  Overrides:
    `setFillPaint` in class `OMGraphic`
  Parameters:
    `paint` - value Color

### isPolygon

    public boolean isPolygon()

  Check if this is a polygon or a polyline. A polygon is a multi-segment line that has a non-clear fill color. A polyline is a multi-segment line that has no fill color.

  Returns:
    true if polygon false if polyline

### setIsPolygon

    public void setIsPolygon(boolean set)

  Set the Polyline/Polygon setting, if you know better. If the fillPaint is set after this method is called, then the fillPaint isPolygon rules apply. If the fillPaint is opaque, then it is assumed to be a Polygon and isPolygon will be set to true. If this is set to be false, the fillPaint will be set to clear.

### setNumSegs

    public void setNumSegs(int nsegs)

  Set the number of subsegments for each segment in the poly. (This is only for LINETYPE_GREATCIRCLE or LINETYPE_RHUMB line types, and if < 1, this value is generated internally).

  Parameters:
    `nsegs` - number of segment points

### getNumSegs

    public int getNumSegs()

  Get the number of subsegments for each segment in the poly. (This is only for LINETYPE_GREATCIRCLE or LINETYPE_RHUMB line types).

  Returns:
    int number of segment points

### setCoordMode

    public void setCoordMode(int coordMode)

  For RENDERTYPE_OFFSET, type of offset.

  See Also:
    `COORDMODE_ORIGIN`, `COORDMODE_PREVIOUS`

### getCoordMode

    public int getCoordMode()

  For RENDERTYPE_OFFSET, type of offset.

  See Also:
    `COORDMODE_ORIGIN`, `COORDMODE_PREVIOUS`

### setDoShapes

    public void setDoShapes(boolean set)

### getDoShapes

    public boolean getDoShapes()

### generate

    public boolean generate(Projection proj)

  Prepare the poly for rendering.

  Specified by:
    `generate` in interface `OMGeometry`
  Specified by:
    `generate` in class `OMGraphic`
  Parameters:
    `proj` - Projection
  Returns:
    true if generate was successful
  See Also:
    `OMGraphic.regenerate(com.bbn.openmap.proj.Projection)`

### checkPoints

    protected boolean checkPoints(int[][] xpoints2,
                                  int[][] ypoints2)

  Return true if the xpoints and ypoints are not null and contain coordinates.

  Parameters:
    `xpoints2` -
    `ypoints2` -

### shouldRenderFill

    public boolean shouldRenderFill()

  Return true of the fill color/paint should be rendered (not clear).

  Overrides:
    `shouldRenderFill` in class `OMGraphic`

### render

    public void render(java.awt.Graphics g)

  Paint the poly. This works if generate() has been successful.

  Overrides:
    `render` in class `OMGraphic`
  Parameters:
    `g` - java.awt.Graphics to paint the poly onto.

### distance

    public float distance(int x,
                          int y)

  Return the shortest distance from the graphic to an XY-point. This works if generate() has been successful.

  Specified by:
    `distance` in interface `OMGeometry`
  Overrides:
    `distance` in class `OMGraphic`
  Parameters:
    `x` - horizontal pixel location.
    `y` - vertical pixel location.
  Returns:
    the distance of the object to the location given.

### getShape

    public java.awt.geom.GeneralPath getShape()

  Get the array of java.awt.Shape objects that represent the projected graphic. The array will contain more than one Shape object of the object wraps around the earth and needs to show up in more than one place on the map.

  The java.awt.Shape object gives you the ability to do a little spatial analysis on the graphics.

  Specified by:
    `getShape` in interface `OMGeometry`
  Overrides:
    `getShape` in class `BasicGeometry`
  Returns:
    java.awt.geom.GeneralPath (Shape), or null if the graphic needs to be generated with the current map projection, or null if the OMGeometry hasn't been updated to use Shape objects for its internal representation.

### createShape

    protected void createShape()

  Since OMPoly has the option to not create a Shape, this method is here to create it if it is asked for. The OMPoly needs to be generated.

### isGeometryClosed

    protected boolean isGeometryClosed()

  Is the geometry closed ?

  Returns:
    boolean

### getRawllpts

    public float[] getRawllpts()

  For XMLEncoder

### getUnits

    public int getUnits()

  For XMLEncoder

Copyright (C) BBNT Solutions LLC; See http://openmap.bbn.com/ for details