Changeset 1111
- Timestamp:
- 06/17/08 16:38:26
- Files:
-
- geojsonlib/trunk/CHANGES.txt (modified) (2 diffs)
- geojsonlib/trunk/geojsonlib (moved) (moved from geojsonlib/trunk/geojson)
- geojsonlib/trunk/geojsonlib/base.py (copied) (copied from geojsonlib/trunk/geojson/base.py)
- geojsonlib/trunk/geojsonlib/crs.py (copied) (copied from geojsonlib/trunk/geojson/crs.py)
- geojsonlib/trunk/geojsonlib/encoding.py (copied) (copied from geojsonlib/trunk/geojson/encoding.py)
- geojsonlib/trunk/geojsonlib/examples.py (copied) (copied from geojsonlib/trunk/geojson/examples.py)
- geojsonlib/trunk/geojsonlib/factory.py (copied) (copied from geojsonlib/trunk/geojson/factory.py)
- geojsonlib/trunk/geojsonlib/feature.py (copied) (copied from geojsonlib/trunk/geojson/feature.py)
- geojsonlib/trunk/geojsonlib/geometry.py (copied) (copied from geojsonlib/trunk/geojson/geometry.py)
- geojsonlib/trunk/geojsonlib/__init__.py (copied) (copied from geojsonlib/trunk/geojson/__init__.py)
- geojsonlib/trunk/geojsonlib/mapping.py (copied) (copied from geojsonlib/trunk/geojson/mapping.py)
- geojsonlib/trunk/setup.py (modified) (1 diff)
- geojsonlib/trunk/tests/blog.txt (modified) (2 diffs)
- geojsonlib/trunk/tests/c2c_features.txt (modified) (1 diff)
- geojsonlib/trunk/tests/featurecollection.txt (modified) (6 diffs)
- geojsonlib/trunk/tests/features.txt (modified) (5 diffs)
- geojsonlib/trunk/tests/geometrycollection.txt (modified) (5 diffs)
- geojsonlib/trunk/tests/geometry.txt (modified) (7 diffs)
- geojsonlib/trunk/tests/including_additional_members.txt (modified) (4 diffs)
- geojsonlib/trunk/tests/objects.txt (modified) (5 diffs)
- geojsonlib/trunk/VERSION.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
geojsonlib/trunk/CHANGES.txt
r1085 r1111 3 3 4 4 1.0a4 (Sun Apr 27 2008) 5 ------------------ 5 ----------------------- 6 6 7 7 - Get in step with GeoJSON draft version 6. … … 11 11 12 12 - Made tests use ELLIPSIS to avoid output transmogification due to floating 13 point representation. 14 13 point representation. 14 15 16 1.0a5 (Tues June 17 2008) 17 ------------------------ 18 19 - Renamed package to "geojsonlib" 20 geojsonlib/trunk/setup.py
r1084 r1111 5 5 version = open("VERSION.txt", "rb").read() 6 6 7 setup(name = " GeoJSON",7 setup(name = "geojsonlib", 8 8 version = version, 9 9 description = "Encoder/decoder for simple GIS features", 10 10 license = "BSD", 11 keywords = "gis geography json",11 keywords = "gis geography geometry json", 12 12 author = "Sean Gillies", 13 13 author_email = "sgillies@frii.com", 14 maintainer = " Sean Gillies",15 maintainer_email = " sgillies@frii.com",14 maintainer = "Matthew Russell", 15 maintainer_email = "matt@sanoodi.com", 16 16 url = "http://trac.gispython.org/projects/PCL/wiki/GeoJSON", 17 17 long_description = readme_text, 18 packages = ["geojson "],18 packages = ["geojsonlib"], 19 19 install_requires = ["simplejson", "setuptools"], 20 20 test_suite = "tests.test_suite", geojsonlib/trunk/tests/blog.txt
r1054 r1111 5 5 >>> d = {"blog": {"posts": [{"atom:summary": "post 1", "type": "atom:item", "atom:description": "i love blogging"}, {"atom:summary": "post 2 from CA", "type": "atom:item", "location": {"type": "Point", "coordinates": [-120.2138, 40.1231]}, "atom:description": "geoblogging in California"}], "location": {"type": "Polygon", "coordinates": [[[-121.5627, 39.8173], [-119.5221, 39.8173], [-119.1232, 41.1231], [-121.5632, 41.3321], [-121.2156, 39.8103]]]}}} 6 6 7 >>> import geojson 7 >>> import geojsonlib 8 8 9 9 Encoding 10 10 11 >>> json = geojson .dumps(d)11 >>> json = geojsonlib.dumps(d) 12 12 >>> json # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE 13 13 '{"blog": {"posts": [{"atom:summary": "post 1", "type": "atom:item", "atom:description": "i love blogging"}, {"atom:summary": "post 2 from CA", "type": "atom:item", "location": {"type": "Point", "coordinates": [-120..., 40...]}, "atom:description": "geoblogging in California"}], "location": {"type": "Polygon", "coordinates": [[[-121..., 39...], [-119..., 39...], [-119..., 41...], [-121..., 41...], [-121..., 39...]]]}}}' … … 15 15 Decoding 16 16 17 >>> o = geojson .loads(json)17 >>> o = geojsonlib.loads(json) 18 18 >>> type(o) 19 19 <type 'dict'> geojsonlib/trunk/tests/c2c_features.txt
r1063 r1111 36 36 37 37 >>> f = Feature(12, Point(49.132323, 55.341411), foo='bar') 38 >>> import geojson 39 >>> geojson .dumps(f) # doctest: +ELLIPSIS38 >>> import geojsonlib 39 >>> geojsonlib.dumps(f) # doctest: +ELLIPSIS 40 40 '{"geometry": {"type": "Point", "coordinates": [49..., 55...]}, "type": "Feature", "properties": {"foo": "bar"}, "id": 12}' 41 41 >>> c = FeatureCollection([f]) 42 >>> geojson .dumps(c) # doctest: +ELLIPSIS42 >>> geojsonlib.dumps(c) # doctest: +ELLIPSIS 43 43 '{"type": "FeatureCollection", "features": [{"geometry": {"type": "Point", "coordinates": [49..., 55...]}, "type": "Feature", "properties": {"foo": "bar"}, "id": 12}]}' geojsonlib/trunk/tests/featurecollection.txt
r1063 r1111 15 15 Encoding 16 16 17 >>> import geojson 18 >>> json = geojson .dumps(fc)17 >>> import geojsonlib 18 >>> json = geojsonlib.dumps(fc) 19 19 >>> json # doctest: +ELLIPSIS 20 20 '{"type": "FeatureCollection", "features": [{"geometry": {"type": "Point", "coordinates": [44..., 67...]}, "type": "Feature", "id": "1"}]}' … … 22 22 Decoding 23 23 24 >>> fcb = geojson .loads(json)24 >>> fcb = geojsonlib.loads(json) 25 25 >>> fcb # doctest: +ELLIPSIS 26 26 {u'type': u'FeatureCollection', u'features': [{u'geometry': {u'type': u'Point', u'coordinates': [44..., 67...]}, u'type': u'Feature', u'id': u'1'}]} … … 30 30 ----------------------------------------------------------- 31 31 32 >>> features = [geojson .Feature(id=1, geometry=geojson.Point(coordinates=(53.04781795911469, -4.10888671875)))]33 >>> fco = geojson .FeatureCollection(features=features)32 >>> features = [geojsonlib.Feature(id=1, geometry=geojsonlib.Point(coordinates=(53.04781795911469, -4.10888671875)))] 33 >>> fco = geojsonlib.FeatureCollection(features=features) 34 34 >>> fco.features # doctest: +ELLIPSIS 35 35 [Feature(geometry={'type': 'Point', 'coordinates': (53..., -4...)}, properties={}, id=1)] … … 38 38 Encoding 39 39 40 >>> json = geojson .dumps(fco)40 >>> json = geojsonlib.dumps(fco) 41 41 >>> json # doctest: +ELLIPSIS 42 42 '{"type": "FeatureCollection", "features": [{"geometry": {"type": "Point", "coordinates": [53..., -4...]}, "type": "Feature", "properties": {}, "id": 1}]}' … … 45 45 and can encode back into a instnace of the same kind, or supply your own hook: 46 46 47 >>> hook = lambda ob: geojson .GeoJSON.to_instance(ob, geojson.feature)48 >>> fc = geojson .loads(json, object_hook=hook)47 >>> hook = lambda ob: geojsonlib.GeoJSON.to_instance(ob, geojsonlib.feature) 48 >>> fc = geojsonlib.loads(json, object_hook=hook) 49 49 >>> fc.features # doctest: +ELLIPSIS 50 50 [Feature(geometry={'type': 'Point', 'coordinates': [53..., -4...]}, properties={}, id=1)] … … 67 67 ... @property 68 68 ... def __geo_interface__(self): 69 ... return geojson .Point(coordinates=[self.x, self.y])69 ... return geojsonlib.Point(coordinates=[self.x, self.y]) 70 70 71 71 >>> p = Point(53.04781795911469, -4.10888671875) 72 >>> geojson .dumps(p) # doctest: +ELLIPSIS72 >>> geojsonlib.dumps(p) # doctest: +ELLIPSIS 73 73 '{"type": "Point", "coordinates": [53..., -4...]}' geojsonlib/trunk/tests/features.txt
r1063 r1111 12 12 ... } 13 13 14 >>> import geojson 14 >>> import geojsonlib 15 15 16 16 Encoding 17 17 18 >>> json = geojson .dumps(f)18 >>> json = geojsonlib.dumps(f) 19 19 >>> json # doctest: +ELLIPSIS 20 20 '{"geometry": {"type": "Point", "coordinates": [53..., -4...]}, "type": "Feature", "properties": {"title": "Dict 1"}, "id": "1"}' … … 22 22 Decoding 23 23 24 >>> o = geojson .loads(json)24 >>> o = geojsonlib.loads(json) 25 25 >>> o # doctest: +ELLIPSIS 26 26 {u'geometry': {u'type': u'Point', u'coordinates': [53..., -4...]}, u'type': u'Feature', u'properties': {u'title': u'Dict 1'}, u'id': u'1'} … … 30 30 --------------------- 31 31 32 >>> from geojson .examples import SimpleWebFeature32 >>> from geojsonlib.examples import SimpleWebFeature 33 33 >>> feature = SimpleWebFeature(id='1', 34 34 ... geometry={'type': 'Point', 'coordinates': [53.04781795911469, -4.10888671875]}, … … 51 51 Encoding 52 52 53 >>> geojson .dumps(feature) # doctest: +ELLIPSIS53 >>> geojsonlib.dumps(feature) # doctest: +ELLIPSIS 54 54 '{"geometry": {"type": "Point", "coordinates": [53..., -4...]}, "type": "Feature", "properties": {"summary": "The first feature", "link": "http:\\/\\/example.org\\/features\\/1", "title": "Feature 1"}, "id": "1"}' 55 55 56 56 Decoding 57 57 58 >>> factory = geojson .examples.createSimpleWebFeature58 >>> factory = geojsonlib.examples.createSimpleWebFeature 59 59 >>> json = '{"geometry": {"type": "Point", "coordinates": [53.04781795911469, -4.10888671875]}, "id": "1", "properties": {"summary": "The first feature", "link": "http:\\/\\/example.org\\/features\\/1", "title": "Feature 1"}}' 60 >>> feature = geojson .loads(json, object_hook=factory)60 >>> feature = geojsonlib.loads(json, object_hook=factory) 61 61 >>> type(feature) 62 <class 'geojson .examples.SimpleWebFeature'>62 <class 'geojsonlib.examples.SimpleWebFeature'> 63 63 >>> feature.id 64 64 '1' … … 88 88 >>> ob.__geo_interface__['geometry'] # doctest: +ELLIPSIS 89 89 {'type': 'Point', 'coordinates': (-106..., 40...)} 90 >>> geojson .dumps(ob) # doctest: +ELLIPSIS90 >>> geojsonlib.dumps(ob) # doctest: +ELLIPSIS 91 91 '{"geometry": {"type": "Point", "coordinates": [-106..., 40...]}, "id": "1", "properties": {"title": "thingy one"}}' geojsonlib/trunk/tests/geometrycollection.txt
r1063 r1111 12 12 Encoding 13 13 14 >>> import geojson 15 >>> json = geojson .dumps(gc)14 >>> import geojsonlib 15 >>> json = geojsonlib.dumps(gc) 16 16 >>> json # doctest: +ELLIPSIS 17 17 '{"type": "GeometryCollection", "geometries": [{"type": "Point", "coordinates": [44..., 67...]}]}' … … 20 20 Decoding 21 21 22 >>> gcb = geojson .loads(json)22 >>> gcb = geojsonlib.loads(json) 23 23 >>> gcb # doctest: +ELLIPSIS 24 24 {u'type': u'GeometryCollection', u'geometries': [{u'type': u'Point', u'coordinates': [44..., 67...]}]} … … 28 28 ----------------------------------------------------------- 29 29 30 >>> geometries = [geojson .Point(coordinates=[53.04781795911469, -4.10888671875])]31 >>> gc2 = geojson .GeometryCollection(geometries)30 >>> geometries = [geojsonlib.Point(coordinates=[53.04781795911469, -4.10888671875])] 31 >>> gc2 = geojsonlib.GeometryCollection(geometries) 32 32 >>> gc2.geometries # doctest: +ELLIPSIS 33 33 [Point(coordinates=[53..., -4...])] … … 35 35 Encoding 36 36 37 >>> json = geojson .dumps(gc2)37 >>> json = geojsonlib.dumps(gc2) 38 38 >>> json # doctest: +ELLIPSIS 39 39 '{"type": "GeometryCollection", "geometries": [{"type": "Point", "coordinates": [53..., -4...]}]}' … … 42 42 and can decode back into a instance of the same kind, or supply your own hook: 43 43 44 >>> gc = geojson .loads(json, object_hook=geojson.GeoJSON.to_instance)44 >>> gc = geojsonlib.loads(json, object_hook=geojsonlib.GeoJSON.to_instance) 45 45 >>> gc.geometries # doctest: +ELLIPSIS 46 46 [Point(coordinates=[53..., -4...])] geojsonlib/trunk/tests/geometry.txt
r1063 r1111 11 11 ... } 12 12 13 >>> import geojson 14 >>> import geojson .geometry13 >>> import geojsonlib 14 >>> import geojsonlib.geometry 15 15 16 16 Encoding 17 17 18 >>> json = geojson .dumps(g)18 >>> json = geojsonlib.dumps(g) 19 19 >>> json # doctest: +ELLIPSIS 20 20 '{"type": "Point", "coordinates": [1..., -54...]}' … … 22 22 Decoding 23 23 24 >>> o = geojson .loads(json)24 >>> o = geojsonlib.loads(json) 25 25 >>> o # doctest: +ELLIPSIS 26 26 {u'type': u'Point', u'coordinates': [1..., -54...]} … … 30 30 --------------------- 31 31 32 >>> ls = geojson .geometry.LineString(((52.1, -34.131), (65.231, -34.234)))32 >>> ls = geojsonlib.geometry.LineString(((52.1, -34.131), (65.231, -34.234))) 33 33 34 34 >>> ls.__geo_interface__ # doctest: +ELLIPSIS … … 42 42 Encoding 43 43 44 >>> json = geojson .dumps(ls)44 >>> json = geojsonlib.dumps(ls) 45 45 >>> json # doctest: +ELLIPSIS 46 46 '{"type": "LineString", "coordinates": [[52..., -34...], [65..., -34...]]}' 47 47 48 48 Decoding 49 >>> geojson .loads(json) # doctest: +ELLIPSIS49 >>> geojsonlib.loads(json) # doctest: +ELLIPSIS 50 50 {u'type': u'LineString', u'coordinates': [[52..., -34...], [65..., -34...]]} 51 51 52 >>> factory = lambda o: geojson .GeoJSON.to_instance(o, geojson.geometry)53 >>> geom = geojson .loads(json, object_hook=factory)52 >>> factory = lambda o: geojsonlib.GeoJSON.to_instance(o, geojsonlib.geometry) 53 >>> geom = geojsonlib.loads(json, object_hook=factory) 54 54 >>> type(geom) 55 <class 'geojson .geometry.LineString'>55 <class 'geojsonlib.geometry.LineString'> 56 56 >>> geom.type 57 57 'LineString' … … 62 62 Test custom crs 63 63 64 >>> from geojson .crs import Named64 >>> from geojsonlib.crs import Named 65 65 66 66 >>> coords = ((-1918145.0108183471, -4098018.9166399641), (-680004.67204747663, -3864394.3196185972)) 67 67 68 >>> ls = geojson .geometry.LineString(coords, crs=Named(properties=dict(name='EPSG:4326')))68 >>> ls = geojsonlib.geometry.LineString(coords, crs=Named(properties=dict(name='EPSG:4326'))) 69 69 70 70 >>> ls.__geo_interface__ # doctest: +ELLIPSIS … … 73 73 It satisfies the geometry protocol 74 74 75 >>> json = geojson .dumps(ls)75 >>> json = geojsonlib.dumps(ls) 76 76 >>> json # doctest: +ELLIPSIS 77 77 '{"crs": {"type": "name", "properties": {"name": "EPSG:4326"}}, "type": "LineString", "coordinates": [[-1918145..., -4098018...], [-680004..., -3864394...]]}' 78 78 79 79 Decoding 80 >>> geojson .loads(json) # doctest: +ELLIPSIS80 >>> geojsonlib.loads(json) # doctest: +ELLIPSIS 81 81 {u'crs': {u'type': u'name', u'properties': {u'name': u'EPSG:4326'}}, u'type': u'LineString', u'coordinates': [[-1918145..., -4098018...], [-680004..., -3864394...]]} 82 82 83 83 84 >>> factory = lambda o: geojson .GeoJSON.to_instance(o, geojson.geometry)85 >>> geom = geojson .loads(json, object_hook=factory)84 >>> factory = lambda o: geojsonlib.GeoJSON.to_instance(o, geojsonlib.geometry) 85 >>> geom = geojsonlib.loads(json, object_hook=factory) 86 86 >>> type(geom) 87 <class 'geojson .geometry.LineString'>87 <class 'geojsonlib.geometry.LineString'> 88 88 >>> geom.type 89 89 'LineString' … … 105 105 >>> ob.__geo_interface__['coordinates'] # doctest: +ELLIPSIS 106 106 (-106..., 40...) 107 >>> geojson .dumps(ob) # doctest: +ELLIPSIS107 >>> geojsonlib.dumps(ob) # doctest: +ELLIPSIS 108 108 '{"type": "Point", "coordinates": [-106..., 40...]}' geojsonlib/trunk/tests/including_additional_members.txt
r1063 r1111 19 19 ... } 20 20 21 >>> import geojson 21 >>> import geojsonlib 22 22 23 23 Encoding 24 24 25 >>> json = geojson .dumps(f)25 >>> json = geojsonlib.dumps(f) 26 26 27 27 >>> json … … 30 30 Decoding 31 31 32 >>> o = geojson .loads(json)32 >>> o = geojsonlib.loads(json) 33 33 34 34 >>> json … … 36 36 37 37 38 Custom objects can be decoded into a json structure containing valid geojson 38 Custom objects can be decoded into a json structure containing valid geojsonlib 39 39 ---------------------------------------------------------------------------- 40 40 … … 52 52 >>> r = Route("Snowdonia circular", "A nice bike ride around some mountains", ((1.0, 2.0), (2.0, 3.2))) 53 53 54 >>> json = geojson .dumps(r)54 >>> json = geojsonlib.dumps(r) 55 55 56 56 >>> json # doctest: +ELLIPSIS 57 57 '{"description": "A nice bike ride around some mountains", "title": "Snowdonia circular", "geometry": {"type": "LineString", "coordinates": [[1..., 2...], [2..., 3...]]}, "type": "Feature", "properties": {}, "id": null}' 58 58 59 >>> r = geojson .loads(json)59 >>> r = geojsonlib.loads(json) 60 60 >>> r # doctest: +ELLIPSIS 61 61 {u'description': u'A nice bike ride around some mountains', u'title': u'Snowdonia circular', u'geometry': {u'type': u'LineString', u'coordinates': [[1..., 2...], [2..., 3...]]}, u'id': None, u'type': u'Feature', u'properties': {}} geojsonlib/trunk/tests/objects.txt
r1063 r1111 1 1 Encoding objects with __geo_interface__ 2 2 ------------------------------------------ 3 >>> import geojson 3 >>> import geojsonlib 4 4 5 5 >>> class LatLon(object): … … 16 16 >>> lat_lon = LatLon(-54.1231, 4.53242) 17 17 18 Can be encoded into geojson geometry:18 Can be encoded into geojsonlib geometry: 19 19 20 >>> json = geojson .dumps(lat_lon)20 >>> json = geojsonlib.dumps(lat_lon) 21 21 >>> json # doctest: +ELLIPSIS 22 22 '{"type": "Point", "coordinates": [4..., -54...]}' 23 23 24 Objects with a __geo_interface__ attribute or property can be nested in geojson feature:24 Objects with a __geo_interface__ attribute or property can be nested in geojsonlib feature: 25 25 26 >>> f = geojson .Feature(geometry=lat_lon)26 >>> f = geojsonlib.Feature(geometry=lat_lon) 27 27 28 28 And feature will encode: 29 29 30 >>> json = geojson .dumps(f)30 >>> json = geojsonlib.dumps(f) 31 31 >>> json # doctest: +ELLIPSIS 32 32 '{"geometry": {"type": "Point", "coordinates": [4..., -54...]}, "type": "Feature", "properties": {}, "id": null}' 33 33 34 geojson types can be used to implemented a __geo_interface__:34 geojsonlib types can be used to implemented a __geo_interface__: 35 35 36 36 >>> class LatLon2(LatLon): 37 37 ... @property 38 38 ... def __geo_interface__(self): 39 ... return geojson .Point((self.lon, self.lat))39 ... return geojsonlib.Point((self.lon, self.lat)) 40 40 ... 41 41 … … 44 44 ... @property 45 45 ... def __geo_interface__(self): 46 ... return geojson .Point((self.lon, self.lat))46 ... return geojsonlib.Point((self.lon, self.lat)) 47 47 ... 48 48 ... 49 49 50 50 >>> ll2 = LatLon2(-54.1231, 4.53242) 51 >>> json2 = geojson .dumps(ll2)51 >>> json2 = geojsonlib.dumps(ll2) 52 52 >>> json2 # doctest: +ELLIPSIS 53 53 '{"type": "Point", "coordinates": [4..., -54...]}' … … 57 57 - to a dict 58 58 59 >>> feature_dict = geojson .loads(json)59 >>> feature_dict = geojsonlib.loads(json) 60 60 >>> feature_dict # doctest: +ELLIPSIS 61 61 {u'geometry': {u'type': u'Point', u'coordinates': [4..., -54...]}, u'type': u'Feature', u'properties': {}, u'id': None} … … 64 64 65 65 >>> ll2 = LatLon2(43.3,-154.1) 66 >>> json = geojson .dumps(ll2)66 >>> json = geojsonlib.dumps(ll2) 67 67 >>> json # doctest: +ELLIPSIS 68 68 '{"type": "Point", "coordinates": [-154..., 43...]}' 69 69 70 >>> geojson .loads(json) # doctest: +ELLIPSIS70 >>> geojsonlib.loads(json) # doctest: +ELLIPSIS 71 71 {u'type': u'Point', u'coordinates': [-154..., 43...]} 72 72 73 >>> factory = lambda ob: geojson .GeoJSON.to_instance(ob)74 >>> geometry = geojson .loads(json, object_hook=factory)73 >>> factory = lambda ob: geojsonlib.GeoJSON.to_instance(ob) 74 >>> geometry = geojsonlib.loads(json, object_hook=factory) 75 75 >>> geometry # doctest: +ELLIPSIS 76 76 Point(coordinates=[-154..., 43...]) geojsonlib/trunk/VERSION.txt
r1084 r1111 1 1.0a 41 1.0a5
