diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2012-10-06 15:09:31 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2012-10-06 15:09:31 +0200 |
commit | 8d5caabe7159a0e8982b58952689413f73958dc8 (patch) | |
tree | 1cd2d1c499a8e595b7929f176b08806f2db372cb /chimere/utils.py | |
parent | 99b03a18a8d8a4d8ee9f9b78b927d8b5c9fb4004 (diff) | |
download | Chimère-8d5caabe7159a0e8982b58952689413f73958dc8.tar.bz2 Chimère-8d5caabe7159a0e8982b58952689413f73958dc8.zip |
Import/export: KML route import - KML, CSV, ShapeFile route export
Diffstat (limited to 'chimere/utils.py')
-rw-r--r-- | chimere/utils.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/chimere/utils.py b/chimere/utils.py index c89ec56..53834dc 100644 --- a/chimere/utils.py +++ b/chimere/utils.py @@ -194,7 +194,7 @@ class KMLManager(ImportManager): - number of item updated ; - error detail on error """ - from models import Marker + from models import Marker, Route new_item, updated_item, msg = 0, 0, '' source, msg = self.get_source_file(['.kml']) if msg: @@ -218,7 +218,7 @@ class KMLManager(ImportManager): if self.importer_instance.filtr else self.DEFAULT_XPATH for placemark in tree.xpath(xpath, namespaces={'kml':self.ns}): - name, point = None, None + name, point, line = None, None, None pl_id = placemark.attrib.get('id') pl_key = 'kml-%d' % self.importer_instance.pk ns = '{%s}' % self.ns @@ -235,6 +235,13 @@ class KMLManager(ImportManager): if coord.tag == ns + 'coordinates': x, y, z = coord.text.split(',') point = 'SRID=4326;POINT(%s %s)' % (x, y) + elif item.tag == ns + 'LineString': + for coord in item: + if coord.tag == ns + 'coordinates': + points = coord.text.replace('\n', ' ').split(' ') + points = ",".join([" ".join(p.split(',')[:2]) + for p in points if p]) + line = 'SRID=4326;LINESTRING(%s)' % points cls = None dct = {'description':description, 'name':name, @@ -243,6 +250,10 @@ class KMLManager(ImportManager): if point: dct['point'] = point cls = Marker + if line: + dct['route'] = line + dct.pop('description') + cls = Route if cls: item, updated, created = self.create_or_update_item( cls, dct, pl_id, key=pl_key) @@ -459,7 +470,7 @@ class CSVManager(ImportManager): dct['data'].append(data) filename = unicode_normalize(settings.PROJECT_NAME + dct['description']\ + '.csv') - result = render_to_response('chimere/export_%s.csv' % cls_name, dct) + result = render_to_response('chimere/export.csv', dct) return filename, result class GeoRSSManager(ImportManager): @@ -505,8 +516,8 @@ class GeoRSSManager(ImportManager): reordered_points = [] # lat, lon -> x, y for idx in xrange(len(points)/2): - reordered_points.append(points[idx*2+1]) - reordered_points.append(points[idx*2]) + reordered_points.append("%s %s" % (points[idx*2+1], + points[idx*2])) dct['route'] = 'SRID=4326;LINESTRING(%s)' % \ ",".join(reordered_points) |