Encoding objects with __geo_interface__
------------------------------------------
  >>> import geojson

  >>> class LatLon(object):
  ...     
  ...    def __init__(self, lat, lon):
  ...        super(LatLon, self).__init__()
  ...        self.lat = lat
  ...        self.lon = lon
  ... 
  ...    @property
  ...    def __geo_interface__(self):
  ...        return dict(type="Point", coordinates=(self.lon, self.lat))

  >>> lat_lon = LatLon(-54.1231, 4.53242)
  
  Can be encoded into geojson geometry:

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

  Objects with a __geo_interface__ attribute or property can be nested in geojson feature:

  >>> f = geojson.Feature(geometry=lat_lon)

  And feature will encode:

  >>> json = geojson.dumps(f)
  >>> json # doctest: +ELLIPSIS
  '{"geometry": {"type": "Point", "coordinates": [4..., -54...]}, "type": "Feature", "properties": {}, "id": null}'

  geojson types can be used to implemented a __geo_interface__:

  >>> class LatLon2(LatLon):
  ...     @property
  ...     def __geo_interface__(self):
  ...             return geojson.Point((self.lon, self.lat))
  ... 


  >>> class LatLon2(LatLon):
  ...     @property
  ...     def __geo_interface__(self):
  ...         return geojson.Point((self.lon, self.lat))
  ...     
  ...   

  >>> ll2 = LatLon2(-54.1231, 4.53242)
  >>> json2 = geojson.dumps(ll2)
  >>> json2 # doctest: +ELLIPSIS
  '{"type": "Point", "coordinates": [4..., -54...]}'
  

  Decoding
    - to a dict

  >>> feature_dict = geojson.loads(json)
  >>> feature_dict # doctest: +ELLIPSIS
  {u'geometry': {u'type': u'Point', u'coordinates': [4..., -54...]}, u'type': u'Feature', u'properties': {}, u'id': None}

  - or to an object, via a factory. Here we'll create GeoJSON object.

  >>> ll2 = LatLon2(43.3,-154.1) 
  >>> json = geojson.dumps(ll2) 
  >>> json # doctest: +ELLIPSIS
  '{"type": "Point", "coordinates": [-154..., 43...]}'
  
  >>> geojson.loads(json) # doctest: +ELLIPSIS
  {u'type': u'Point', u'coordinates': [-154..., 43...]}
  
  >>> factory = lambda ob: geojson.GeoJSON.to_instance(ob)
  >>> geometry = geojson.loads(json, object_hook=factory)
  >>> geometry   # doctest: +ELLIPSIS     
  Point(coordinates=[-154..., 43...])
 
