com.mapinfo.midev.geometry

## Class GeometryFactory

- java.lang.Object
- - com.mapinfo.midev.geometry.GeometryFactory

    public final class GeometryFactory
    extends Object

A factory class to create a variety of geometry types through a convenient API. Simple geometries can be created directly with this factory. More complex geometries such as curves and polygons, make use of builders to facilitate their construction.

### Examples

#### Point

    IPoint point = GeometryFactory.forCoordSys(CoordSysConstants.longLatWGS84).
            newPoint(12.34, -23.45);

#### Multi-Point

    IMultiPoint points = GeometryFactory.forCoordSys(CoordSysConstants.longLatWGS84).
            newMultiPoint(pos(12.34, -23.45), pos(0, 0), pos(123.4, 1.2));

#### Curve

    ICurve curve = GeometryFactory.forCoordSys(CoordSysConstants.longLatWGS84).
            newCurve().withLineString(pos(1, 1), pos(2, 1), pos(3, 4), pos(5, 5)).
            build();

#### Polygon

    IPolygon polygon = GeometryFactory.forCoordSys(CoordSysConstants.longLatWGS84).
            newPolygon().
                withOuterRing().
                    withLineString(pos(1, 1), pos(2, 1), pos(2, 2), pos(1, 2), pos(1, 1)).
                    build().
                withInnerRing().
                    withLineString(pos(1.1, 1.1), pos(1.9, 1.1), pos(1.9, 1.9), pos(1.1, 1.9), pos(1.1, 1.1)).
                    build().
                build();

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`static GeometryFactory` `forCoordSys(CoordSys coordSys)` Creates a new geometry factory for the given coordinate system.
`static GeometryFactory` `forCoordSysCode(Code code)` Creates a new geometry factory for the coordinate system identified by the given coordinate system code.
`static GeometryFactory` `forSpatialInfo(SpatialInfo spatialInfo)` Creates a new geometry factory for the given spatial info object.
`static GeometryFactory` `forSrsName(String srsName)` Creates a new geometry factory for the coordinate system identified by the given spatial reference system (SRS) name.
`CurveBuilder` `newCurve()` Creates a new builder to facilitate the construction of a new curve.
`ILineString` `newLineString(DirectPosition[] positions)` Creates a line string from the given array of direct positions.
`ILineString` `newLineString(IDirectPositionList positions)` Creates a line string from a given direct position list.
`ILineString` `newLineString(Iterable positions)` Creates a line string from an iterable data structure of direct positions.
`MultiCurveBuilder` `newMultiCurve()` Creates a new builder to facilitate the construction of a new multi-curve.
`MultiPointBuilder` `newMultiPoint()` Creates a new multi-point builder, which can be used to add points in multiple separate method calls.
`IMultiPoint` `newMultiPoint(DirectPosition[] positions)` Creates a multi-point from an array of direct positions.
`IMultiPoint` `newMultiPoint(IDirectPositionList positions)` Creates a multi-point from a direct position list.
`IMultiPoint` `newMultiPoint(Iterable positions)` Creates a multi-point from an iterable data structure of direct positions.
`MultiPolygonBuilder` `newMultiPolygon()` Creates a new builder to facilitate the construction of a new multi-polygon.
`IPoint` `newPoint(DirectPosition directPosition)` Creates a new point using a direct position object.
`IPoint` `newPoint(double x, double y)` Creates a new point for the given x and y coordinates.
`IPoint` `newPoint(String x, String y)` Creates a new point for the given x and y coordinates.
`IPolygonBuilder` `newPolygon()` Creates a new builder to facilitate the construction of a new polygon.
`static DirectPosition` `pos(double x, double y)` Creates a new direct position from the given x and y coordinate values.
`static DirectPosition` `pos(String x, String y)` Creates a new direct position from the given x and y coordinate values.
`static IDirectPositionList` `posList(DirectPosition[] positions)` Creates a new direct position list from the given array of direct positions.

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Method Detail

#### forSrsName

    public static GeometryFactory forSrsName(String srsName)

Creates a new geometry factory for the coordinate system identified by the given spatial reference system (SRS) name.

Parameters:
  `srsName` - a string value identifying a coordinate system.
Returns:
  a new geometry factory to create geometries in the coordinate system for the given SRS name.
Throws:
  `UnknownSRSNameException` - if the given srsName is unknown.

#### forCoordSysCode

    public static GeometryFactory forCoordSysCode(Code code)

Creates a new geometry factory for the coordinate system identified by the given coordinate system code.

Parameters:
  `code` - a code object identifying a coordinate system.
Returns:
  a new geometry factory to create geometries in the coordinate system for the given code.
Throws:
  `UnknownCodeException` - if the given code is unknown.

#### forCoordSys

    public static GeometryFactory forCoordSys(CoordSys coordSys)

Creates a new geometry factory for the given coordinate system.

Parameters:
  `coordSys` - the coordinate system to create a new geometry factory instance for
Returns:
  a new geometry factory to create geometries in the given coordinate system.

#### forSpatialInfo

    public static GeometryFactory forSpatialInfo(SpatialInfo spatialInfo)

Creates a new geometry factory for the given spatial info object.

Parameters:
  `spatialInfo` - a spatial info object encapsulating the coordinate system to create a new geometry factory instance for
Returns:
  a new geometry factory to create geometries in the coordinate system of the given spatial info object.

#### newPoint

    public IPoint newPoint(double x,
                           double y)

Creates a new point for the given x and y coordinates.

Parameters:
  `x` - the x coordinate for the new point
  `y` - the y coordinate for the new point
Returns:
  A new point for the given coordinates.

#### newPoint

    public IPoint newPoint(String x,
                           String y)

Creates a new point for the given x and y coordinates.

Parameters:
  `x` - the x coordinate for the new point
  `y` - the y coordinate for the new point
Returns:
  A new point for the given coordinates.
Throws:
  `NumberFormatException` - if any of the coordinate values cannot be parsed into a double value
  `NullPointerException` - if any of the coordinate values is `null`.

#### newPoint

    public IPoint newPoint(DirectPosition directPosition)

Creates a new point using a direct position object.

Parameters:
  `directPosition` - the direct position to create a new point for.
Returns:
  A new point for the given direct position.

#### newMultiPoint

    public IMultiPoint newMultiPoint(DirectPosition[] positions)

Creates a multi-point from an array of direct positions.

Parameters:
  `positions` - an array of direct positions
Returns:
  A new multi-point containing a point for each direct position passed into this method.

#### newMultiPoint

    public IMultiPoint newMultiPoint(Iterable positions)

Creates a multi-point from an iterable data structure of direct positions.

Parameters:
  `positions` - an iterable data structure
Returns:
  A new multi-point containing a point for each direct position passed into this method.

#### newMultiPoint

    public IMultiPoint newMultiPoint(IDirectPositionList positions)

Creates a multi-point from a direct position list.

Parameters:
  `positions` - a direct position list containing the points to create a new multi-point from.
Returns:
  A new multi-point containing a point for each direct position passed into this method.

#### newMultiPoint

    public MultiPointBuilder newMultiPoint()

Creates a new multi-point builder, which can be used to add points in multiple separate method calls.

Returns:
  a new multi-point builder instance.

#### newLineString

    public ILineString newLineString(DirectPosition[] positions)

Creates a line string from the given array of direct positions. The positions will be interpreted as a contiguous string of straight lines from one position to the next in the order they appear in the provided parameter.

Parameters:
  `positions` - a non-empty array of direct positions.
Returns:
  A new line string constructed from the given direct positions.

#### newLineString

    public ILineString newLineString(Iterable positions)

Creates a line string from an iterable data structure of direct positions. The positions will be interpreted as a contiguous string of straight lines from one position to the next in the order they appear in the provided parameter.

Parameters:
  `positions` - an iterable data structure of direct positions.
Returns:
  A new line string constructed from the given direct positions.

#### newLineString

    public ILineString newLineString(IDirectPositionList positions)

Creates a line string from a given direct position list. The positions will be interpreted as a contiguous string of straight lines from one position to the next in the order they appear in the provided parameter.

Parameters:
  `positions` - a direct position list.
Returns:
  A new line string constructed from the given direct positions.

#### newCurve

    public CurveBuilder newCurve()

Creates a new builder to facilitate the construction of a new curve.

Returns:
  A new curve builder instance.

#### newMultiCurve

    public MultiCurveBuilder newMultiCurve()

Creates a new builder to facilitate the construction of a new multi-curve.

Returns:
  A new multi-curve builder instance.

#### newPolygon

    public IPolygonBuilder newPolygon()

Creates a new builder to facilitate the construction of a new polygon.

Returns:
  A new polygon builder instance.

#### newMultiPolygon

    public MultiPolygonBuilder newMultiPolygon()

Creates a new builder to facilitate the construction of a new multi-polygon.

Returns:
  A new multi-polygon builder instance.

#### pos

    public static DirectPosition pos(double x,
                                     double y)

Creates a new direct position from the given x and y coordinate values.

Parameters:
  `x` - the x coordinate for the new direct position
  `y` - the y coordinate for the new direct position
Returns:
  a new direct position with the given coordinate values

#### pos

    public static DirectPosition pos(String x,
                                     String y)

Creates a new direct position from the given x and y coordinate values.

Parameters:
  `x` - the x coordinate for the new direct position
  `y` - the y coordinate for the new direct position
Returns:
  a new direct position with the given coordinate values
Throws:
  `NumberFormatException` - if any of the coordinate values cannot be parsed into a double value.
  `NullPointerException` - if any of the coordinate values is `null`

#### posList

    public static IDirectPositionList posList(DirectPosition[] positions)

Creates a new direct position list from the given array of direct positions.

Parameters:
  `positions` - an array of direct positions.
Returns:
  a new direct position list containing all the direct positions from the given `positions` parameter.