summaryrefslogtreecommitdiff
path: root/chimere/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'chimere/utils.py')
-rw-r--r--chimere/utils.py21
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)