|
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | + |
| 4 | +""" |
| 5 | +*************************************************************************** |
| 6 | + qgis.v.upgrade.py |
| 7 | + --------------------- |
| 8 | + Date : October 2015 |
| 9 | + Copyright : (C) 2015 by Radim Blazek |
| 10 | + Email : radim.blazek@gmail.com |
| 11 | +*************************************************************************** |
| 12 | +* * |
| 13 | +* This program is free software; you can redistribute it and/or modify * |
| 14 | +* it under the terms of the GNU General Public License as published by * |
| 15 | +* the Free Software Foundation; either version 2 of the License, or * |
| 16 | +* (at your option) any later version. * |
| 17 | +* * |
| 18 | +*************************************************************************** |
| 19 | +""" |
| 20 | + |
| 21 | +__author__ = 'Radim Blazek' |
| 22 | +__date__ = 'October 2015' |
| 23 | +__copyright__ = '(C) 2015 by Radim Blazek' |
| 24 | +# This will get replaced with a git SHA1 when you do a git archive |
| 25 | +__revision__ = '$Format:%H$' |
| 26 | + |
| 27 | + |
| 28 | +############################################################################ |
| 29 | +# |
| 30 | +# MODULE: qgis.v.upgrade.py |
| 31 | +# AUTHOR(S): Radim Blazek |
| 32 | +# |
| 33 | +# PURPOSE: Upgrade all vectors from GRASS 6 to GRASS 7 |
| 34 | +# |
| 35 | +# COPYRIGHT: (C) 2015 by Radim Blazek |
| 36 | +# |
| 37 | +# This program is free software under the GNU General Public |
| 38 | +# License (>=v2). Read the file COPYING that comes with GRASS |
| 39 | +# for details. |
| 40 | +# |
| 41 | +############################################################################# |
| 42 | + |
| 43 | +#%Module |
| 44 | +#% description: Upgrade all vectors from GRASS 6 to GRASS 7 |
| 45 | +#% keywords: vector, upgrade |
| 46 | +#%End |
| 47 | + |
| 48 | +import os |
| 49 | +try: |
| 50 | + from grass.script import core as grass |
| 51 | +except ImportError: |
| 52 | + import grass |
| 53 | +except: |
| 54 | + raise Exception("Cannot find 'grass' Python module. Python is supported by GRASS from version >= 6.4") |
| 55 | + |
| 56 | +def main(): |
| 57 | + # see https://grasswiki.osgeo.org/wiki/Convert_all_GRASS_6_vector_maps_to_GRASS_7 |
| 58 | + grass.message('Building topology') |
| 59 | + if grass.run_command('v.build.all') != 0: |
| 60 | + grass.warning('Cannot build topology') |
| 61 | + |
| 62 | + grass.message('Creating new DB connection') |
| 63 | + if grass.run_command('db.connect', flags='d') != 0: |
| 64 | + grass.warning('Cannot create new DB connection') |
| 65 | + return |
| 66 | + |
| 67 | + grass.message('Transfering tables to the new DB') |
| 68 | + if grass.run_command('v.db.reconnect.all', flags='cd') != 0: |
| 69 | + grass.warning('Cannot transfer tables') |
| 70 | + |
| 71 | +if __name__ == "__main__": |
| 72 | + options, flags = grass.parser() |
| 73 | + main() |
0 commit comments