首页 > 解决方案 > Python Script to find lowest coordinates in a list

问题描述

I have a list containing coordinates in the order of Y,X,Z. I am trying to use python to find the coordinates for lowest Z value. The list contains 4 sets of coordinates separated by space. Part of the code I am using is below.

<gml:coordList>200.0001 400.0001 30.0001 210.0002 410.0002 31.0002 190.0003 401.0003 29.0003 213.0004 402.0004 38.0004</gml:coordList>


y1,x1,z1,y2,x2,z2,y3,x3,z3,y4,x4,z4 = coordList[0:-1].split(' ')

list1 = []

list1.append((z1,y1,x1))
list1.append((z2,y2,x2))
list1.append((z3,y3,x3))
list1.append((z4,y4,x4))
minz = min((list1))
x, y, z = minz[0:-1].split(' ') 

The error I am getting is this : AttributeError: 'tuple' object has no attribute 'split'

May I know why I am getting error and if there is a better way to achieve my goal?

Thank you

标签: pythonfindcoordinates

解决方案


If minz is already a tuple type, you can assign x,y,z to each tuple value.

z, y, x = minz

推荐阅读