| 1 |
Test c2c features |
|---|
| 2 |
================= |
|---|
| 3 |
|
|---|
| 4 |
>>> class Feature(object): |
|---|
| 5 |
... def __init__(self, id, geometry, **props): |
|---|
| 6 |
... self.id = id |
|---|
| 7 |
... self.geometry = geometry |
|---|
| 8 |
... self.properties = {} |
|---|
| 9 |
... for key, value in props.items(): |
|---|
| 10 |
... self.properties[key] = value |
|---|
| 11 |
... |
|---|
| 12 |
... @property |
|---|
| 13 |
... def __geo_interface__(self): |
|---|
| 14 |
... return { |
|---|
| 15 |
... 'type': 'Feature', |
|---|
| 16 |
... 'id': self.id, |
|---|
| 17 |
... 'geometry': self.geometry, |
|---|
| 18 |
... 'properties': self.properties |
|---|
| 19 |
... } |
|---|
| 20 |
|
|---|
| 21 |
>>> class FeatureCollection(list): |
|---|
| 22 |
... @property |
|---|
| 23 |
... def __geo_interface__(self): |
|---|
| 24 |
... return { |
|---|
| 25 |
... 'type': 'FeatureCollection', |
|---|
| 26 |
... 'features': list(f for f in self) |
|---|
| 27 |
... } |
|---|
| 28 |
|
|---|
| 29 |
>>> class Point(object): |
|---|
| 30 |
... """Mock shapely point.""" |
|---|
| 31 |
... def __init__(self, x, y): |
|---|
| 32 |
... self.x = x; self.y = y |
|---|
| 33 |
... @property |
|---|
| 34 |
... def __geo_interface__(self): |
|---|
| 35 |
... return dict(type="Point", coordinates=[self.x, self.y]) |
|---|
| 36 |
|
|---|
| 37 |
>>> f = Feature(12, Point(49.132323, 55.341411), foo='bar') |
|---|
| 38 |
>>> import geojson |
|---|
| 39 |
>>> geojson.dumps(f) # doctest: +ELLIPSIS |
|---|
| 40 |
'{"geometry": {"type": "Point", "coordinates": [49..., 55...]}, "type": "Feature", "properties": {"foo": "bar"}, "id": 12}' |
|---|
| 41 |
>>> c = FeatureCollection([f]) |
|---|
| 42 |
>>> geojson.dumps(c) # doctest: +ELLIPSIS |
|---|
| 43 |
'{"type": "FeatureCollection", "features": [{"geometry": {"type": "Point", "coordinates": [49..., 55...]}, "type": "Feature", "properties": {"foo": "bar"}, "id": 12}]}' |
|---|