[GRASS-user] Re: Feed and manipulate the result of "v.distance -pa" in python

Nikos Alexandris nikos.alexandris at felis.uni-freiburg.de
Fri Aug 6 14:01:50 EDT 2010


On Wednesday 04 of August 2010 15:20:58 schorschli wrote:
> For your task the use of lists and the split tool may help.
> The different lines have are seperated by a  '\n' (which is interpreted as
> a new line). After splitting the string into a line list you can make a
> loop each item of this list. Something like this:
> 
> output='7839|16\n7839|17\n7839|22\n7839|23\n7839|24'
> 
> seccond_column_list=[]
> max_value=0
> 
> line_list=output.split('\n')
> 
> for line in line_list:
> 	columns=line.split('|')
> 	seccond_column_list.append(float(columns[1]))
> 
> max_value=max(seccond_column_list)
> 
> print seccond_column_list
> print max_value
> 
> 
> I may missunderstood your question but I hope this helps.

Thanks Hamish and Matthias.

Here one (more) solution:

# get distances from v.distance -pa
 distances = grass.read_command("v.distance",\
 flags = 'pa',\
 _from = reference_points_map,\
 to = lowres_vector_grid,\
 column = gridcell_column,\
 to_column = "cat",\
 upload = "to_attr")

 # get max distance
 max_distance=max([float(d.split('|')[1]) for d in distances.splitlines()
[1:]])


(Thanks to Aggelos Nikolaou for the solution. It's something trivial but when 
_not_ working all-the-time with python looks difficult in the beginning.)

Nikos


More information about the grass-user mailing list