# OpenLayers.Geometry

A Geometry is a description of a geographic object. Create an instance of this class with the OpenLayers.Geometry constructor. This is a base class, typical geometry types are described by subclasses of this class.

Note that if you use the OpenLayers.Geometry.fromWKT method, you must explicitly include the OpenLayers.Format.WKT in your build.

Summary

OpenLayers.Geometry | A Geometry is a description of a geographic object.
Properties |
id | {String} A unique identifier for this geometry.
parent | {OpenLayers.Geometry}This is set when a Geometry is added as component of another geometry
bounds | {OpenLayers.Bounds} The bounds of this geometry
Constructor |
OpenLayers.Geometry | Creates a geometry object.
Functions |
destroy | Destroy this geometry.
clone | Create a clone of this geometry.
setBounds | Set the bounds for this Geometry.
clearBounds | Nullify this components bounds and that of its parent as well.
extendBounds | Extend the existing bounds to include the new bounds.
getBounds | Get the bounds for this Geometry.
calculateBounds | Recalculate the bounds for the geometry.
distanceTo | Calculate the closest distance between two geometries (on the x-y plane).
getVertices | Return a list of all points in this geometry.
atPoint |
getLength | Calculate the length of this geometry.
getArea | Calculate the area of this geometry.
getCentroid | Calculate the centroid of this geometry.
toString | Returns a text representation of the geometry.
OpenLayers.Geometry.fromWKT | Generate a geometry given a Well-Known Text string.
OpenLayers.Geometry.segmentsIntersect | Determine whether two line segments intersect.
OpenLayers.Geometry.distanceToSegment |

### Properties

### id

{String} A unique identifier for this geometry.

### parent

{OpenLayers.Geometry}This is set when a Geometry is added as component of another geometry

### bounds

{OpenLayers.Bounds} The bounds of this geometry

### Constructor

### OpenLayers.Geometry

Creates a geometry object.

### Functions

### destroy

> destroy: function()

Destroy this geometry.

### clone

> clone: function()

Create a clone of this geometry. Does not set any non-standard properties of the cloned geometry.

#### Returns

{OpenLayers.Geometry} An exact clone of this geometry.

### setBounds

> setBounds: function( | bounds | )

Set the bounds for this Geometry.

#### Parameters

bounds | {OpenLayers.Bounds}

### clearBounds

> clearBounds: function()

Nullify this components bounds and that of its parent as well.

### extendBounds

> extendBounds: function( | newBounds | )

Extend the existing bounds to include the new bounds. If geometry’s bounds is not yet set, then set a new Bounds.

#### Parameters

newBounds | {OpenLayers.Bounds}

### getBounds

> getBounds: function()

Get the bounds for this Geometry. If bounds is not set, it is calculated again, this makes queries faster.

#### Returns

{OpenLayers.Bounds}

### calculateBounds

> calculateBounds: function()

Recalculate the bounds for the geometry.

### distanceTo

> distanceTo: function( | geometry,
> | options | )

Calculate the closest distance between two geometries (on the x-y plane).

#### Parameters

geometry | {OpenLayers.Geometry} The target geometry.
options | {Object} Optional properties for configuring the distance calculation.

Valid options depend on the specific geometry type.

#### Returns

{Number | Object} The distance between this geometry and the target. If details is true, the return will be an object with distance, x0, y0, x1, and x2 properties. The x0 and y0 properties represent the coordinates of the closest point on this geometry. The x1 and y1 properties represent the coordinates of the closest point on the target geometry.

### getVertices

> getVertices: function( | nodes | )

Return a list of all points in this geometry.

#### Parameters

nodes | {Boolean} For lines, only return vertices that are endpoints. If false, for lines, only vertices that are not endpoints will be returned. If not provided, all vertices will be returned.

#### Returns

{Array} A list of all vertices in the geometry.

### atPoint

> atPoint: function( | lonlat,
> | toleranceLon,
> | toleranceLat | )

Note | This is only an approximation based on the bounds of the geometry.

#### Parameters

lonlat | {<OpenLayers.LonLat>|Object} OpenLayers.LonLat or an object with a ‘lon’ and ‘lat’ properties.
toleranceLon | {float} Optional tolerance in Geometric Coords
toleranceLat | {float} Optional tolerance in Geographic Coords

#### Returns

{Boolean} Whether or not the geometry is at the specified location

### getLength

> getLength: function()

Calculate the length of this geometry. This method is defined in subclasses.

#### Returns

{Float} The length of the collection by summing its parts

### getArea

> getArea: function()

Calculate the area of this geometry. This method is defined in subclasses.

#### Returns

{Float} The area of the collection by summing its parts

### getCentroid

> getCentroid: function()

Calculate the centroid of this geometry. This method is defined in subclasses.

#### Returns

{OpenLayers.Geometry.Point} The centroid of the collection

### toString

> toString: function()

Returns a text representation of the geometry. If the WKT format is included in a build, this will be the Well-Known Text representation.

#### Returns

{String} String representation of this geometry.

### OpenLayers.Geometry.fromWKT

> OpenLayers.Geometry.fromWKT = function( | wkt | )

Generate a geometry given a Well-Known Text string. For this method to work, you must include the OpenLayers.Format.WKT in your build explicitly.

#### Parameters

wkt | {String} A string representing the geometry in Well-Known Text.

#### Returns

{OpenLayers.Geometry} A geometry of the appropriate class.

### OpenLayers.Geometry.segmentsIntersect

> OpenLayers.Geometry.segmentsIntersect = function( | seg1,
> | seg2,
> | options | )

Determine whether two line segments intersect. Optionally calculates and returns the intersection point. This function is optimized for cases where seg1.x2 >= seg2.x1 || seg2.x2 >= seg1.x1. In those obvious cases where there is no intersection, the function should not be called.

#### Parameters

seg1 | {Object} Object representing a segment with properties x1, y1, x2, and y2. The start point is represented by x1 and y1. The end point is represented by x2 and y2. Start and end are ordered so that x1 < x2.
seg2 | {Object} Object representing a segment with properties x1, y1, x2, and y2. The start point is represented by x1 and y1. The end point is represented by x2 and y2. Start and end are ordered so that x1 < x2.
options | {Object} Optional properties for calculating the intersection.

#### Valid options

point | {Boolean} Return the intersection point. If false, the actual intersection point will not be calculated. If true and the segments intersect, the intersection point will be returned. If true and the segments do not intersect, false will be returned. If true and the segments are coincident, true will be returned.
tolerance | {Number} If a non-null value is provided, if the segments are within the tolerance distance, this will be considered an intersection. In addition, if the point option is true and the calculated intersection is within the tolerance distance of an end point, the endpoint will be returned instead of the calculated intersection. Further, if the intersection is within the tolerance of endpoints on both segments, or if two segment endpoints are within the tolerance distance of eachother (but no intersection is otherwise calculated), an endpoint on the first segment provided will be returned.

#### Returns

{Boolean | OpenLayers.Geometry.Point} The two segments intersect. If the point argument is true, the return will be the intersection point or false if none exists. If point is true and the segments are coincident, return will be true (and the instersection is equal to the shorter segment).

### OpenLayers.Geometry.distanceToSegment

> OpenLayers.Geometry.distanceToSegment = function( | point,
> | segment | )

#### Parameters

point | {Object} An object with x and y properties representing the point coordinates.
segment | {Object} An object with x1, y1, x2, and y2 properties representing endpoint coordinates.

#### Returns

{Object} An object with distance, x, and y properties. The distance will be the shortest distance between the input point and segment. The x and y properties represent the coordinates along the segment where the shortest distance meets the segment.

Creates a geometry object.
Instances of this class represent bounding boxes.

> destroy: function()

Destroy this geometry.

> clone: function()

Create a clone of this geometry.

> setBounds: function( | bounds | )

Set the bounds for this Geometry.

> clearBounds: function()

Nullify this components bounds and that of its parent as well.

> extendBounds: function( | newBounds | )

Extend the existing bounds to include the new bounds.

> getBounds: function()

Get the bounds for this Geometry.

> calculateBounds: function()

Recalculate the bounds for the geometry.

> distanceTo: function( | geometry,
> | options | )

Calculate the closest distance between two geometries (on the x-y plane).

> getVertices: function( | nodes | )

Return a list of all points in this geometry.

> atPoint: function( | lonlat,
> | toleranceLon,
> | toleranceLat | )

> getLength: function()

Calculate the length of this geometry.

> getArea: function()

Calculate the area of this geometry.

> getCentroid: function()

Calculate the centroid of this geometry.

> toString: function()

Returns a text representation of the geometry.

> OpenLayers.Geometry.fromWKT = function( | wkt | )

Generate a geometry given a Well-Known Text string.

> OpenLayers.Geometry.segmentsIntersect = function( | seg1,
> | seg2,
> | options | )

Determine whether two line segments intersect.

> OpenLayers.Geometry.distanceToSegment = function( | point,
> | segment | )

Point geometry class.
Close