
Tests of the Geometry collections protocol
-----------------------------------------

A dictionary can satisfy the protocol
-------------------------------------

  >>> gc = {"type": "GeometryCollection", 
  ...       "geometries": [{"type": "Point", "coordinates": [44.556, 67.192]}]
  ... }

  Encoding

  >>> import geojson
  >>> json = geojson.dumps(gc)
  >>> json  # doctest: +ELLIPSIS
  '{"type": "GeometryCollection", "geometries": [{"type": "Point", "coordinates": [44..., 67...]}]}'


  Decoding
  
  >>> gcb = geojson.loads(json)
  >>> gcb  # doctest: +ELLIPSIS
  {u'type': u'GeometryCollection', u'geometries': [{u'type': u'Point', u'coordinates': [44..., 67...]}]}


GeoJSON types thmeselves satisfy the protocol (of course!)
-----------------------------------------------------------
  
  >>> geometries = [geojson.Point(coordinates=[53.04781795911469, -4.10888671875])]
  >>> gc2 = geojson.GeometryCollection(geometries)
  >>> gc2.geometries # doctest: +ELLIPSIS
  [Point(coordinates=[53..., -4...])]

  Encoding

  >>> json = geojson.dumps(gc2)
  >>> json  # doctest: +ELLIPSIS
  '{"type": "GeometryCollection", "geometries": [{"type": "Point", "coordinates": [53..., -4...]}]}'

  
  and can decode back into a instance of the same kind, or supply your own hook:

  >>> gc = geojson.loads(json, object_hook=geojson.GeoJSON.to_instance)
  >>> gc.geometries  # doctest: +ELLIPSIS
  [Point(coordinates=[53..., -4...])]
  
  >>> geometry = gc.geometries[0]  
  >>> geometry # doctest: +ELLIPSIS
  Point(coordinates=[53..., -4...])

  >>> geometry.coordinates  # doctest: +ELLIPSIS
  [53..., -4...]
 

