
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, sort_keys=True)
  >>> json  # doctest: +ELLIPSIS
  '{"geometries": [{"coordinates": [44..., 67...], "type": "Point"}], "type": "GeometryCollection"}'


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


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

  Encoding

  >>> json = geojson.dumps(gc2, sort_keys=True)
  >>> json  # doctest: +ELLIPSIS
  '{"geometries": [{"coordinates": [53..., -4...], "type": "Point"}], "type": "GeometryCollection"}'
  
  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
  [{"coordinates": [53..., -4...], "type": "Point"}]
  
  >>> geometry = gc.geometries[0]  
  >>> geometry # doctest: +ELLIPSIS
  {"coordinates": [53..., -4...], "type": "Point"}

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

