Commit 251e892a authored by Kris Vanneste's avatar Kris Vanneste
Browse files

Added export_geojson method to SingleData and MultiData.

git-svn-id: https://svn.seismo.oma.be/svn/seismo/mapping/layeredbasemap/trunk@7711 40b490c5-b4d9-47cb-8714-9bef99b524d5
parent 25e2c66a
......@@ -147,7 +147,29 @@ class SingleData(BasemapData):
json["properties"] = props
return json
# TODO: dump_geojson method with json_handler for arrays and datetimes cf. eqcatalog
def export_geojson(self, fp=None, **kwargs):
"""
Export to geojson
:param fp:
FILE object or None
(default: None, will generate string)
**kwargs:
additional keyword arguments understood by json.dump(s)
:return:
str (if :param:`fp` is None)
or None (if :param:`fp` is a FILE object)
"""
import json
from mapping.geotools.json_handler import json_handler
kwargs['default'] = kwargs.get('default', json_handler)
if fp is None:
return json.dumps(self.to_geojson(), **kwargs)
else:
json.dump(self.to_geojson(), fp, **kwargs)
def to_ogr_geom(self):
"""
......@@ -499,6 +521,32 @@ class MultiData(BasemapData):
json['features'].append(item.to_geojson())
return json
def export_geojson(self, fp=None, as_multi=False, **kwargs):
"""
Export to geojson
:param fp:
FILE object or None
(default: None, will generate string)
:param as_multi:
see :meth:`to_geojson`
**kwargs:
additional keyword arguments understood by json.dump(s)
:return:
str (if :param:`fp` is None)
or None (if :param:`fp` is a FILE object)
"""
import json
from mapping.geotools.json_handler import json_handler
kwargs['default'] = kwargs.get('default', json_handler)
if fp is None:
return json.dumps(self.to_geojson(as_multi=as_multi), **kwargs)
else:
json.dump(self.to_geojson(as_multi=as_multi), fp, **kwargs)
def to_ogr_geom(self):
"""
Convert to ogr geometry
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment