Skip to content
Browse files
[Processing] GRASS7 v.distance (implements Redmine #12817)
  • Loading branch information
Médéric Ribreux committed Feb 12, 2016
1 parent 9e0043c commit 4196293f06db3eb3b6161619e0572aadf8f0353f
@@ -0,0 +1,14 @@
Finds the nearest element in vector map 'to' for elements in vector map 'from'.
Vector (v.*)
ParameterVector|from|'from' vector map|-1|False
*ParameterString|from_type|'from' feature type (point,line,boundary,centroid,area)|point,line,area|False|False
ParameterVector|to|'to' vector map|-1|False
*ParameterString|to_type|'to' feature type (point,line,boundary,centroid,area)|point,line,area|False|False
ParameterNumber|dmax|Maximum distance or -1.0 for no limit|-1.0|None|-1.0|False
ParameterNumber|dmin|Minimum distance or -1.0 for no limit|-1.0|None|-1.0|False
ParameterString|upload|'upload': Values describing the relation between two nearest features (cat,dist,to_x,to_y,to_along,to_angle,to_attr)|cat|False|True
ParameterString|column|Column name(s) where values specified by 'upload' option will be uploaded|None|False|True
ParameterTableField|to_column|Column name of nearest feature (used with upload=to_attr)|to|-1|True
@@ -0,0 +1,77 @@
# -*- coding: utf-8 -*-

Date : February 2016
Copyright : (C) 2016 by Médéric Ribreux
Email : medspx at medspx dot fr
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *

__author__ = 'Médéric Ribreux'
__date__ = 'February 2016'
__copyright__ = '(C) 2016, Médéric Ribreux'

# This will get replaced with a git SHA1 when you do a git archive

__revision__ = '$Format:%H$'

import os

def checkParameterValuesBeforeExecuting(alg):
""" Verify if we have the right parameters """
# Verify upload value
upload = alg.getParameterValue(u'upload')
if upload:
uploadList = [f for f in upload.split(",") if f not in ['cat', 'dist', 'to_x', 'to_y', 'to_along', 'to_angle', 'to_attr']]
if len(uploadList) > 0:
return"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'")
# Verifiy that we have the good number of columns
column = alg.getParameterValue(u'column')
if ((column is None or len(column) == 0) and upload) or (len(column.split(",")) != len(upload.split(","))):
return"The number of columns and the number of upload parameters should be equal !")

# Verify from_type and to_type values
for geom in [u'from', u'to']:
geoType = alg.getParameterValue(u'{}_type'.format(geom))
if geoType:
geoTypeList = [f for f in geoType.split(",") if f not in ['point', 'line', 'boundary', 'centroid', 'area']]
if len(geoTypeList) > 0:
return"Feature type for '{}' should be a list of elements taken in the following values:\n'point', 'line', 'boundary', 'centroid', 'area'".format(geom))

return None

def processCommand(alg):
# We temporary remove the output 'from_output'
fromOutput = alg.getOutputFromName(u'from_output')
fromParam = alg.getParameterValue(u'from')
alg.exportedLayers[fromOutput.value] = alg.exportedLayers[fromParam]

# We re-add the new output

def processOutputs(alg):
# Output results ('from' table and output table)
for output in [u'from_output', u'output']:
out = alg.getOutputValue(output)
command = u"v.out.ogr -c type=auto -s -e input={} output=\"{}\" format=ESRI_Shapefile output_layer={}".format(

0 comments on commit 4196293

Please sign in to comment.