summaryrefslogtreecommitdiff
path: root/chimere/scripts/upgrade.py
diff options
context:
space:
mode:
Diffstat (limited to 'chimere/scripts/upgrade.py')
-rwxr-xr-xchimere/scripts/upgrade.py24
1 files changed, 21 insertions, 3 deletions
diff --git a/chimere/scripts/upgrade.py b/chimere/scripts/upgrade.py
index 2628ec8..a850acf 100755
--- a/chimere/scripts/upgrade.py
+++ b/chimere/scripts/upgrade.py
@@ -14,7 +14,7 @@ from django.db import connection, transaction
cursor = connection.cursor()
from main.models import Area, Route
-
+from django.contrib.gis.geos import LineString
# early versions before 0.1: urn field doesn't exist for area
@@ -62,7 +62,6 @@ UNIQUE"
from osgeo import osr
-areas = Area.objects.all()
srs = osr.SpatialReference()
srs.ImportFromEPSG(4326) # WGS84
ll = srs.CloneGeogCS()
@@ -70,10 +69,11 @@ srs.ImportFromEPSG(settings.EPSG_PROJECTION)
proj = osr.CoordinateTransformation(srs, ll)
changed = False
+areas = Area.objects.all()
for area in areas:
# only one test: assume each point as been save with the same SRID...
if area.upper_left_corner.srid == 4326 and area.upper_left_corner.x > 90 \
- or area.upper_left_corner < -90:
+ or area.upper_left_corner.x < -90:
changed = True
pt = proj.TransformPoint(area.upper_left_corner.y,
area.upper_left_corner.x)
@@ -87,3 +87,21 @@ for area in areas:
if changed:
print " * projections of areas corrected"
+# early versions before 0.1: save route with wrong SRID
+# only errors with default SRID is managed adapt the script for your SRID
+
+changed = False
+routes = Route.objects.all()
+for route in routes:
+ # only one test: assume each point as been save with the same SRID...
+ if route.route and route.route.srid == 4326 and \
+ route.route[0][0] > 90 or route.route[0][0] < -90:
+ changed = True
+ new_route = []
+ for pt in route.route:
+ pt = proj.TransformPoint(pt[0], pt[1])
+ new_route.append((pt[0], pt[1]))
+ route.route = LineString(new_route)
+ route.save()
+if changed:
+ print " * projections of routes corrected"