# OpenLayers.Format.GeoJSON

Read and write GeoJSON. Create a new parser with the OpenLayers.Format.GeoJSON constructor.

#### Inherits from

- OpenLayers.Format.JSON

Summary

OpenLayers.Format.GeoJSON | Read and write GeoJSON.
Properties |
ignoreExtraDims | {Boolean} Ignore dimensions higher than 2 when reading geometry coordinates.
Constructor |
OpenLayers.Format.GeoJSON | Create a new parser for GeoJSON.
Functions |
read | Deserialize a GeoJSON string.
isValidType | Check if a GeoJSON object is a valid representative of the given type.
parseFeature | Convert a feature object from GeoJSON into an OpenLayers.Feature.Vector.
parseGeometry | Convert a geometry object from GeoJSON into an OpenLayers.Geometry.
Properties |
parseCoords | Object with properties corresponding to the GeoJSON geometry types.
Functions |
parseCoords.point | Convert a coordinate array from GeoJSON into an OpenLayers.Geometry.
parseCoords.multipoint | Convert a coordinate array from GeoJSON into an OpenLayers.Geometry.
parseCoords.linestring | Convert a coordinate array from GeoJSON into an OpenLayers.Geometry.
parseCoords.multilinestring | Convert a coordinate array from GeoJSON into an OpenLayers.Geometry.
parseCoords.polygon | Convert a coordinate array from GeoJSON into an OpenLayers.Geometry.
parseCoords.multipolygon | Convert a coordinate array from GeoJSON into an OpenLayers.Geometry.
parseCoords.box | Convert a coordinate array from GeoJSON into an OpenLayers.Geometry.
write | Serialize a feature, geometry, array of features into a GeoJSON string.
createCRSObject | Create the CRS object for an object.
Properties |
extract | Object with properties corresponding to the GeoJSON types.
Functions |
extract.feature | Return a partial GeoJSON object representing a single feature.
extract.geometry | Return a GeoJSON object representing a single geometry.
extract.point | Return an array of coordinates from a point.
extract.multipoint | Return an array of point coordinates from a multipoint.
extract.linestring | Return an array of coordinate arrays from a linestring.
extract.multilinestring | Return an array of linestring arrays from a linestring.
extract.polygon | Return an array of linear ring arrays from a polygon.
extract.multipolygon | Return an array of polygon arrays from a multipolygon.
extract.collection | Return an array of geometries from a geometry collection.

### Properties

### ignoreExtraDims

{Boolean} Ignore dimensions higher than 2 when reading geometry coordinates.

### Constructor

### OpenLayers.Format.GeoJSON

Create a new parser for GeoJSON.

#### Parameters

options | {Object} An optional object whose properties will be set on this instance.

### Functions

### read

> read: function( | json,
> | type,
> | filter | )

Deserialize a GeoJSON string.

#### Parameters

json | {String} A GeoJSON string
type | {String} Optional string that determines the structure of the output. Supported values are “Geometry”, “Feature”, and “FeatureCollection”. If absent or null, a default of “FeatureCollection” is assumed.
filter | {Function} A function which will be called for every key and value at every level of the final result. Each value will be replaced by the result of the filter function. This can be used to reform generic objects into instances of classes, or to transform date strings into Date objects.

#### Returns

{Object} The return depends on the value of the type argument. If type is “FeatureCollection” (the default), the return will be an array of OpenLayers.Feature.Vector. If type is “Geometry”, the input json must represent a single geometry, and the return will be an OpenLayers.Geometry. If type is “Feature”, the input json must represent a single feature, and the return will be an OpenLayers.Feature.Vector.

### isValidType

> isValidType: function( | obj,
> | type | )

Check if a GeoJSON object is a valid representative of the given type.

#### Returns

{Boolean} The object is valid GeoJSON object of the given type.

### parseFeature

> parseFeature: function( | obj | )

Convert a feature object from GeoJSON into an OpenLayers.Feature.Vector.

#### Parameters

obj | {Object} An object created from a GeoJSON object

#### Returns

{OpenLayers.Feature.Vector} A feature.

### parseGeometry

> parseGeometry: function( | obj | )

Convert a geometry object from GeoJSON into an OpenLayers.Geometry.

#### Parameters

obj | {Object} An object created from a GeoJSON object

#### Returns

{OpenLayers.Geometry} A geometry.

### Properties

### parseCoords

Object with properties corresponding to the GeoJSON geometry types. Property values are functions that do the actual parsing.

### Functions

### parseCoords.point

Convert a coordinate array from GeoJSON into an OpenLayers.Geometry.

#### Parameters

array | {Object} The coordinates array from the GeoJSON fragment.

#### Returns

{OpenLayers.Geometry} A geometry.

### parseCoords.multipoint

Convert a coordinate array from GeoJSON into an OpenLayers.Geometry.

#### Parameters

array {Object} The coordinates array from the GeoJSON fragment.

#### Returns

{OpenLayers.Geometry} A geometry.

### parseCoords.linestring

Convert a coordinate array from GeoJSON into an OpenLayers.Geometry.

#### Parameters

array | {Object} The coordinates array from the GeoJSON fragment.

#### Returns

{OpenLayers.Geometry} A geometry.

### parseCoords.multilinestring

Convert a coordinate array from GeoJSON into an OpenLayers.Geometry.

#### Parameters

array | {Object} The coordinates array from the GeoJSON fragment.

#### Returns

{OpenLayers.Geometry} A geometry.

### parseCoords.polygon

Convert a coordinate array from GeoJSON into an OpenLayers.Geometry.

#### Returns

{OpenLayers.Geometry} A geometry.

### parseCoords.multipolygon

Convert a coordinate array from GeoJSON into an OpenLayers.Geometry.

#### Parameters

array | {Object} The coordinates array from the GeoJSON fragment.

#### Returns

{OpenLayers.Geometry} A geometry.

### parseCoords.box

Convert a coordinate array from GeoJSON into an OpenLayers.Geometry.

#### Parameters

array | {Object} The coordinates array from the GeoJSON fragment.

#### Returns

{OpenLayers.Geometry} A geometry.

### write

> write: function( | obj,
> | pretty | )

Serialize a feature, geometry, array of features into a GeoJSON string.

#### Parameters

obj | {Object} An OpenLayers.Feature.Vector, OpenLayers.Geometry, or an array of features.
pretty | {Boolean} Structure the output with newlines and indentation. Default is false.

#### Returns

{String} The GeoJSON string representation of the input geometry, features, or array of features.

### createCRSObject

> createCRSObject: function( | object | )

Create the CRS object for an object.

#### Parameters

object | {OpenLayers.Feature.Vector}

#### Returns

{Object} An object which can be assigned to the crs property of a GeoJSON object.

### Properties

### extract

Object with properties corresponding to the GeoJSON types. Property values are functions that do the actual value extraction.

### Functions

### extract.feature

Return a partial GeoJSON object representing a single feature.

#### Parameters

feature | {OpenLayers.Feature.Vector}

#### Returns

{Object} An object representing the point.

### extract.geometry

Return a GeoJSON object representing a single geometry.

#### Parameters

geometry | {OpenLayers.Geometry}

#### Returns

{Object} An object representing the geometry.

### extract.point

Return an array of coordinates from a point.

#### Parameters

point | {OpenLayers.Geometry.Point}

#### Returns

{Array} An array of coordinates representing the point.

### extract.multipoint

Return an array of point coordinates from a multipoint.

#### Parameters

multipoint | {OpenLayers.Geometry.MultiPoint}

#### Returns

{Array} An array of point coordinate arrays representing the multipoint.

### extract.linestring

Return an array of coordinate arrays from a linestring.

#### Parameters

linestring | {OpenLayers.Geometry.LineString}

#### Returns

{Array} An array of coordinate arrays representing the linestring.

### extract.multilinestring

Return an array of linestring arrays from a linestring.

#### Parameters

linestring | {OpenLayers.Geometry.MultiLineString}

#### Returns

{Array} An array of linestring arrays representing the multilinestring.

### extract.polygon

Return an array of linear ring arrays from a polygon.

#### Parameters

polygon | {OpenLayers.Geometry.Polygon}

#### Returns

{Array} An array of linear ring arrays representing the polygon.

### extract.multipolygon

Return an array of polygon arrays from a multipolygon.

#### Parameters

multipolygon | {OpenLayers.Geometry.MultiPolygon}

#### Returns

{Array} An array of polygon arrays representing the multipolygon

### extract.collection

Return an array of geometries from a geometry collection.

#### Parameters

collection | {OpenLayers.Geometry.Collection}

#### Returns

{Array} An array of geometry objects representing the geometry collection.

> read: function( | json,
> | type,
> | filter | )

Deserialize a GeoJSON string.

> isValidType: function( | obj,
> | type | )

Check if a GeoJSON object is a valid representative of the given type.

> parseFeature: function( | obj | )

Convert a feature object from GeoJSON into an OpenLayers.Feature.Vector.
Vector features use the OpenLayers.Geometry classes as geometry description.

> parseGeometry: function( | obj | )

Convert a geometry object from GeoJSON into an OpenLayers.Geometry.
A Geometry is a description of a geographic object.

> write: function( | obj,
> | pretty | )

Serialize a feature, geometry, array of features into a GeoJSON string.

> createCRSObject: function( | object | )

Create the CRS object for an object.
Create a new parser for GeoJSON.
A parser to read/write JSON safely.
Point geometry class.
MultiPoint is a collection of Points.
A LineString is a Curve which, once two points have been added to it, can never be less than two points long.
A MultiLineString is a geometry with multiple OpenLayers.Geometry.LineString components.
Polygon is a collection of Geometry.LinearRings.
MultiPolygon is a geometry with multiple OpenLayers.Geometry.Polygon components.
A Collection is exactly what it sounds like: A collection of different Geometries.
Close