.. _api-zoo-format-geojson:

ZOO.Format.GeoJSON
==================

Read and write GeoJSON.

Inherits from

- :ref:`ZOO.Format.JSON <api-zoo-format-json>`

Properties	
----------

.. list-table::
   :widths: 20 50
   :header-rows: 1

   * - NAME
     - DESCRIPTION
   * - :ref:`ZOO.Format.GeoJSON <ZOO.Format.GeoJSON>`
     - Create a new parser for GeoJSON.
   * - :ref:`read <read>`
     - Deserialize a GeoJSON string.
   * - :ref:`isValidType <isValidType>`
     - Check if a GeoJSON object is a valid representative of the given type.
   * - :ref:`parseFeature <parseFeature>`
     - Convert a feature object from GeoJSON into an ZOO.Feature. 
   * - :ref:`parseGeometry <parseGeometry>`
     - Convert a geometry object from GeoJSON into an ZOO.Geometry.   
     
parseCoords Properties	
----------------------

.. list-table::
   :widths: 20 50
   :header-rows: 1

   * - NAME
     - DESCRIPTION
   * - :ref:`parseCoords <parseCoords>`
     - Object with properties corresponding to the GeoJSON geometry types.  
     
parseCoords Functions	
---------------------

.. list-table::
   :widths: 12 50
   :header-rows: 1

   * - NAME
     - DESCRIPTION
   * - :ref:`parseCoords.point <parseCoords.point>`
     - Convert a coordinate array from GeoJSON into an ZOO.Geometry.Point.
   * - :ref:`parseCoords.multipoint <parseCoords.multipoint>`
     - Convert a coordinate array from GeoJSON into an ZOO.Geometry.MultiPoint.
   * - :ref:`parseCoords.linestring <parseCoords.linestring>`
     - Convert a coordinate array from GeoJSON into an ZOO.Geometry.LineString.
   * - :ref:`parseCoords.multilinestring <parseCoords.multilinestring>`
     - Convert a coordinate array from GeoJSON into an ZOO.Geometry.MultiLineString.
   * - :ref:`parseCoords.polygon <parseCoords.polygon>`
     - Convert a coordinate array from GeoJSON into an ZOO.Geometry.Polygon.  
   * - :ref:`parseCoords.multipolygon <parseCoords.multipolygon>`
     - Convert a coordinate array from GeoJSON into an ZOO.Geometry.MultiPolygon.
   * - :ref:`parseCoords.box <parseCoords.box>`
     - Convert a coordinate array from GeoJSON into an ZOO.Geometry.Polygon.
   * - :ref:`write <write>`
     - Serialize a feature, geometry, array of features into a GeoJSON string.
   * - :ref:`createCRSObject <createCRSObject>`
     - Create the CRS object for an object.     
     
extract Properties
------------------

.. list-table::
   :widths: 20 50
   :header-rows: 1

   * - NAME
     - DESCRIPTION
   * - :ref:`extract <extract>`
     - Object with properties corresponding to the GeoJSON types.   
     
extract Functions	
-----------------

.. list-table::
   :widths: 12 50
   :header-rows: 1

   * - NAME
     - DESCRIPTION
   * - :ref:`extract.feature <extract.feature>`
     - Return a partial GeoJSON object representing a single feature.
   * - :ref:`extract.geometry <extract.geometry>`
     - Return a GeoJSON object representing a single geometry.
   * - :ref:`extract.point <extract.point>`
     - Return an array of coordinates from a point.
   * - :ref:`extract.multipoint <extract.multipoint>`
     - Return an array of coordinates from a multipoint.  
   * - :ref:`extract.linestring <extract.linestring>`
     - Return an array of coordinate arrays from a linestring.
   * - :ref:`extract.multilinestring <extract.multilinestring>`
     - Return an array of linestring arrays from a linestring.
   * - :ref:`extract.polygon <extract.polygon>`
     - Return an array of linear ring arrays from a polygon.
   * - :ref:`extract.multipolygon <extract.multipolygon>`
     - Return an array of polygon arrays from a multipolygon.  
   * - :ref:`extract.collection <extract.collection>`
     - Return an array of geometries from a geometry collection.      
     
**Functions**	
  
.. _ZOO.Format.GeoJSON:                         
  
ZOO.Format.GeoJSON	
  Create a new parser for GeoJSON.


  *Parameters*

  ``options {Object}`` An optional object whose properties will be set on this instance.
  
.. _read:                           
  
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 :ref:`ZOO.Feature <api-zoo-feature>`.  If type is "Geometry", the input json must 
  represent a single geometry, and the return will be an :ref:`ZOO.Geometry <api-zoo-geometry>`.  If type 
  is "Feature", the input json must represent a single feature, and the return will be an :ref:`ZOO.Feature <api-zoo-feature>`.
  
.. _isValidType:                             
  
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	
  ::
  
    parseFeature: function(obj)

  Convert a feature object from GeoJSON into a :ref:`ZOO.Feature <api-zoo-feature>`.

  *Parameters*
  
  ``obj	{Object}`` An object created from a GeoJSON object

  *Returns*

  :ref:`{ZOO.Feature} <api-zoo-feature>` A feature.  
  
.. _parseGeometry:                                 
  
parseGeometry	
  ::
  
    parseGeometry: function(obj)

  Convert a geometry object from GeoJSON into a :ref:`ZOO.Geometry <api-zoo-geometry>`.

  *Parameters*
  
  ``obj {Object}`` An object created from a GeoJSON object

  *Returns*

  :ref:`{ZOO.Geometry} <api-zoo-geometry>` A geometry.
  
**parseCoords Properties**

.. _parseCoords:                                 

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

.. _parseCoords.point:                                 

parseCoords.point	
  Convert a coordinate array from GeoJSON into a :ref:`ZOO.Geometry.Point <api-zoo-geometry-point>`.

  *Parameters*

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

  *Returns*

  :ref:`{ZOO.Geometry.Point} <api-zoo-geometry-point>` A geometry.
  
.. _parseCoords.multipoint:                                   
  
parseCoords.multipoint	
  Convert a coordinate array from GeoJSON into a :ref:`ZOO.Geometry.MultiPoint <api-zoo-geometry-multipoint>`.

  *Parameters*
  
  ``array {Object}`` The coordinates array from the GeoJSON fragment.

  *Returns*

  :ref:`{ZOO.Geometry.MultiPoint} <api-zoo-geometry-multipoint>` A geometry.
  
.. _parseCoords.linestring:                                     
  
parseCoords.linestring	
  Convert a coordinate array from GeoJSON into a :ref:`ZOO.Geometry.LineString <api-zoo-geometry-linestring>`.

  *Parameters*
  
  ``array {Object}`` The coordinates array from the GeoJSON fragment.
  
  *Returns*

  :ref:`{ZOO.Geometry.LineString} <api-zoo-geometry-linestring>` A geometry. 
  
.. _parseCoords.multilinestring: 
  
parseCoords.multilinestring	
  Convert a coordinate array from GeoJSON into a :ref:`ZOO.Geometry.MultiLineString <api-zoo-geometry-multilinestring>`.

  *Parameters*
  
  ``array {Object}`` The coordinates array from the GeoJSON fragment.

  *Returns*

  :ref:`{ZOO.Geometry.MultiLineString} <api-zoo-geometry-multilinestring>` A geometry.
  
.. _parseCoords.polygon:  
  
parseCoords.polygon	
  Convert a coordinate array from GeoJSON into a :ref:`ZOO.Geometry.Polygon <api-zoo-geometry-polygon>`.

  *Parameters*
  
  ``array {Object}`` The coordinates array from the GeoJSON fragment.

  *Returns*

  :ref:`{ZOO.Geometry.Polygon} <api-zoo-geometry-polygon>` A geometry.
  
.. _parseCoords.multipolygon:  

parseCoords.multipolygon	
  Convert a coordinate array from GeoJSON into a :ref:`ZOO.Geometry.MultiPolygon <api-zoo-geometry-multipolygon>`.
  
  *Parameters*

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

  *Returns*

  :ref:`{ZOO.Geometry.MultiPolygon} <api-zoo-geometry-multipolygon>` A geometry.  
  
.. _parseCoords.box:  
  
parseCoords.box	
  Convert a coordinate array from GeoJSON into a :ref:`ZOO.Geometry.Polygon <api-zoo-geometry-polygon>`.

  *Parameters*
  
  ``array {Object}`` The coordinates array from the GeoJSON fragment.

  *Returns*

  :ref:`{ZOO.Geometry.Polygon} <api-zoo-geometry-polygon>` A geometry.  
  
.. _write:  
  
write	
  ::
  
    write: function(obj,pretty)

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

  *Parameters*
  
  | ``obj {Object}`` A :ref:`{ZOO.Feature} <api-zoo-feature>`, :ref:`{ZOO.Geometry} <api-zoo-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	
  ::
  
    createCRSObject: function(object)

  Create the CRS object for an object.
  
  *Parameters*
  
  ``object`` :ref:`{ZOO.Feature} <api-zoo-feature>`

  *Returns*

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

.. _extract:    

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

.. _extract.feature:    

extract.feature	
  Return a partial GeoJSON object representing a single feature.


  *Parameters*
  
  ``feature`` :ref:`{ZOO.Feature} <api-zoo-feature>`

  *Returns*

  ``{Object}`` An object representing the point.  
  
.. _extract.geometry:      
  
extract.geometry	
  Return a GeoJSON object representing a single geometry.

  *Parameters*
  
  ``geometry`` :ref:`{ZOO.Geometry} <api-zoo-geometry>`
  
  *Returns*

  ``{Object}`` An object representing the geometry. 
  
.. _extract.point:        
  
extract.point	
  Return an array of coordinates from a point.

  *Parameters*
  
  ``point`` :ref:`{ZOO.Geometry.Point} <api-zoo-geometry-point>`

  *Returns*

  ``{Array}`` An array of coordinates representing the point. 
  
.. _extract.multipoint:          
  
extract.multipoint	
  Return an array of coordinates from a multipoint.

  *Parameters*
  
  ``multipoint`` :ref:`{ZOO.Geometry.MultiPoint} <api-zoo-geometry-multipoint>`

  *Returns*

  ``{Array}`` An array of point coordinate arrays representing the multipoint.
  
.. _extract.linestring:            
  
extract.linestring	
  Return an array of coordinate arrays from a linestring.

  *Parameters*
  
  ``linestring`` :ref:`{ZOO.Geometry.LineString} <api-zoo-geometry-linestring>`

  *Returns*

  ``{Array}`` An array of coordinate arrays representing the linestring. 
  
.. _extract.multilinestring:              
  
extract.multilinestring	
  Return an array of linestring arrays from a linestring.

  *Parameters*
  
  ``multilinestring`` :ref:`{ZOO.Geometry.MultiLineString} <api-zoo-geometry-multilinestring>`

  *Returns*

  ``{Array}`` An array of linestring arrays representing the multilinestring. 
  
.. _extract.polygon:             
  
extract.polygon	
  Return an array of linear ring arrays from a polygon.

  *Parameters*
  
  ``polygon`` :ref:`{ZOO.Geometry.Polygon} <api-zoo-geometry-polygon>`
  
  *Returns*

  ``{Array}`` An array of linear ring arrays representing the polygon. 
  
.. _extract.multipolygon:                 
  
extract.multipolygon	
  Return an array of polygon arrays from a multipolygon.
  
  *Parameters*
  
  ``multipolygon`` :ref:`{ZOO.Geometry.MultiPolygon} <api-zoo-geometry-multipolygon>`

  *Returns*

  ``{Array}`` An array of polygon arrays representing the multipolygon  
  
.. _extract.collection:  
  
extract.collection	
  Return an array of geometries from a geometry collection.

  *Parameters*

  ``collection`` :ref:`{ZOO.Geometry.Collection} <api-zoo-geometry-collection>`

  *Returns*

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