|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +""" |
| 4 | +*************************************************************************** |
| 5 | + v_distance.py |
| 6 | + ------------- |
| 7 | + Date : February 2016 |
| 8 | + Copyright : (C) 2016 by Médéric Ribreux |
| 9 | + Email : medspx at medspx dot fr |
| 10 | +*************************************************************************** |
| 11 | +* * |
| 12 | +* This program is free software; you can redistribute it and/or modify * |
| 13 | +* it under the terms of the GNU General Public License as published by * |
| 14 | +* the Free Software Foundation; either version 2 of the License, or * |
| 15 | +* (at your option) any later version. * |
| 16 | +* * |
| 17 | +*************************************************************************** |
| 18 | +""" |
| 19 | + |
| 20 | +__author__ = 'Médéric Ribreux' |
| 21 | +__date__ = 'February 2016' |
| 22 | +__copyright__ = '(C) 2016, Médéric Ribreux' |
| 23 | + |
| 24 | +# This will get replaced with a git SHA1 when you do a git archive |
| 25 | + |
| 26 | +__revision__ = '$Format:%H$' |
| 27 | + |
| 28 | +import os |
| 29 | + |
| 30 | + |
| 31 | +def checkParameterValuesBeforeExecuting(alg): |
| 32 | + """ Verify if we have the right parameters """ |
| 33 | + # Verify upload value |
| 34 | + upload = alg.getParameterValue(u'upload') |
| 35 | + if upload: |
| 36 | + uploadList = [f for f in upload.split(",") if f not in ['cat', 'dist', 'to_x', 'to_y', 'to_along', 'to_angle', 'to_attr']] |
| 37 | + if len(uploadList) > 0: |
| 38 | + return alg.tr(u"Upload parameters should be a list of elements taken in the following values:\n'cat', 'dist', 'to_x', 'to_y', 'to_along', 'to_angle', 'to_attr'") |
| 39 | + # Verifiy that we have the good number of columns |
| 40 | + column = alg.getParameterValue(u'column') |
| 41 | + if ((column is None or len(column) == 0) and upload) or (len(column.split(",")) != len(upload.split(","))): |
| 42 | + return alg.tr(u"The number of columns and the number of upload parameters should be equal !") |
| 43 | + |
| 44 | + # Verify from_type and to_type values |
| 45 | + for geom in [u'from', u'to']: |
| 46 | + geoType = alg.getParameterValue(u'{}_type'.format(geom)) |
| 47 | + if geoType: |
| 48 | + geoTypeList = [f for f in geoType.split(",") if f not in ['point', 'line', 'boundary', 'centroid', 'area']] |
| 49 | + if len(geoTypeList) > 0: |
| 50 | + return alg.tr(u"Feature type for '{}' should be a list of elements taken in the following values:\n'point', 'line', 'boundary', 'centroid', 'area'".format(geom)) |
| 51 | + |
| 52 | + return None |
| 53 | + |
| 54 | + |
| 55 | +def processCommand(alg): |
| 56 | + # We temporary remove the output 'from_output' |
| 57 | + fromOutput = alg.getOutputFromName(u'from_output') |
| 58 | + fromParam = alg.getParameterValue(u'from') |
| 59 | + alg.exportedLayers[fromOutput.value] = alg.exportedLayers[fromParam] |
| 60 | + alg.removeOutputFromName(u'from_output') |
| 61 | + alg.processCommand() |
| 62 | + |
| 63 | + # We re-add the new output |
| 64 | + alg.addOutput(fromOutput) |
| 65 | + |
| 66 | + |
| 67 | +def processOutputs(alg): |
| 68 | + # Output results ('from' table and output table) |
| 69 | + for output in [u'from_output', u'output']: |
| 70 | + out = alg.getOutputValue(output) |
| 71 | + command = u"v.out.ogr -c type=auto -s -e input={} output=\"{}\" format=ESRI_Shapefile output_layer={}".format( |
| 72 | + alg.exportedLayers[out], |
| 73 | + os.path.dirname(out), |
| 74 | + os.path.basename(out)[:-4] |
| 75 | + ) |
| 76 | + alg.commands.append(command) |
| 77 | + alg.outputCommands.append(command) |
0 commit comments