Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: b189939226
Fetching contributors…

Cannot retrieve contributors at this time

file 45 lines (40 sloc) 1.67 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
Test c2c features
=================

  >>> class Feature(object):
  ... def __init__(self, id, geometry, **props):
  ... self.id = id
  ... self.geometry = geometry
  ... self.properties = {}
  ... for key, value in props.items():
  ... self.properties[key] = value
  ...
  ... @property
  ... def __geo_interface__(self):
  ... return {
  ... 'type': 'Feature',
  ... 'id': self.id,
  ... 'geometry': self.geometry,
  ... 'properties': self.properties
  ... }

  >>> class FeatureCollection(list):
  ... @property
  ... def __geo_interface__(self):
  ... return {
  ... 'type': 'FeatureCollection',
  ... 'features': list(f for f in self)
  ... }

  >>> class Point(object):
  ... """Mock shapely point."""
  ... def __init__(self, x, y):
  ... self.x = x; self.y = y
  ... @property
  ... def __geo_interface__(self):
  ... return dict(type="Point", coordinates=[self.x, self.y])

  >>> f = Feature(12, Point(49.132323, 55.341411), foo='bar')
  >>> import geojson
  >>> geojson.dumps(f, sort_keys=True) # doctest: +ELLIPSIS
  '{"geometry": {"coordinates": [49..., 55...], "type": "Point"}, "id": 12, "properties": {"foo": "bar"}, "type": "Feature"}'

  >>> features = [f]
  >>> c = FeatureCollection(features)
  >>> geojson.dumps(c, sort_keys=True) # doctest: +ELLIPSIS
  '{"features": [{"geometry": {"coordinates": [49..., 55...], "type": "Point"}, "id": 12, "properties": {"foo": "bar"}, "type": "Feature"}], "type": "FeatureCollection"}'
Something went wrong with that request. Please try again.