summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2010-11-12 01:05:04 +0100
committerÉtienne Loks <etienne.loks@peacefrogs.net>2010-11-12 01:05:04 +0100
commit6da0303399e70dbbbdd49ff238db79cf8311f8ce (patch)
treef983cc88b13acde3a79e0e0b4c03e00835bf2085
parent3fa3778203796584487a6a50997f685971e6b7f7 (diff)
downloadChimère-6da0303399e70dbbbdd49ff238db79cf8311f8ce.tar.bz2
Chimère-6da0303399e70dbbbdd49ff238db79cf8311f8ce.zip
Script to correct wrong projection for routes
-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"