Commit ee65e93b authored by Baptiste Jonglez's avatar Baptiste Jonglez

Add a Django command to separate ground altitude from height

It uses the API to estimate the ground altitude for each point, and then
sets the remaining altitude to "height above ground".  The total altitude
(ground altitude + height above ground) remains unchanged.

To see what would happen with your data without saving the result, run:

    ./ fix_ground_altitude --dry-run

If you're happy with the result, run it for real:

    ./ fix_ground_altitude
parent d115330b
# -*- coding: utf-8 -*-
"""Fix the ground altitude of all reference points, by splitting it
between the actual ground altitude and the height above ground.
This makes call to an external API to get accurate ground altitude, and
simply substract the remaining altitude as "height above aground".
from __future__ import unicode_literals, division, print_function
from import BaseCommand, CommandError
from django.conf import settings
from altitude.providers import get_altitude
from panorama.models import ReferencePoint
class Command(BaseCommand):
help = __doc__
def add_arguments(self, parser):
parser.add_argument('--dry-run', action='store_true',
help="Don't actually save the new altitudes")
def handle(self, *args, **options):
if options['dry_run']:
self.stdout.write("Running in dry run mode, not saving anything"))
for p in ReferencePoint.objects.all():
alt = get_altitude([settings.ALTITUDE_PROVIDERS[0]],
if alt == None:
self.stderr.write("Error while fetching ground altitude for {}".format(
self.stdout.write("{} before: {:.2f} m + {:.2f} m".format(, p.ground_altitude, p.height_above_ground))
p.height_above_ground = p.altitude - alt
p.ground_altitude = alt
self.stdout.write("{} after : {:.2f} m + {:.2f} m".format(, p.ground_altitude, p.height_above_ground))
if not options['dry_run']:
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