我有动物位置(X,Y,Z)数据和树数据(X,Y,Z)。我需要提取所有出现在动物位置周围的XYZ树输入-所以我需要将包含XYZ动物位置的numpy数组与包含同一区域中树的XYZ点位置的numpy数组进行比较。我想把所有的xyz树拉成半径为4个单位的点,并编写了一个函数来完成它。但它并不仅仅是把树拉到动物的周围。它只会打印出所有可能的树。我怎样才能只拉动物点周围的树,然后把它们放到一个.txt文件中,我可以在另一个程序中使用?我是一个新的编程和任何帮助我可以得到非常感谢。在
以下是我的代码及其说明:
#using array instead of dataframe
import numpy as np
from laspy.file import File
#load and consolidate Veg Point Coordinates into one array
VegList = sorted(glob.glob('/Users/sophiathompson/Desktop/copys/Clips/*.las'))
VegListCoords = []
for f in VegList:
print(f)
Veg= File(filename = f, mode = "r") # Open the file # Eventually, this will need to be the actual .laz files
VegListCoords.append(np.vstack((Veg.x, Veg.y, Veg.z)).transpose())
print (VegListCoords)
XYZVegComplete = np.concatenate((VegListCoords), axis = 0)
#Load animal point locations (x, y, z .csv file) from clip 240967 into array
Animal240967 = np.loadtxt(fname='/Users/ST/Desktop/copys/CatTXTfiles/240967_CatsFt.csv', delimiter =',')
#Use to find all vegetation heights in a 4 unit diameter of each animal point (animalx, animaly). #'d out lines of code are my attempts to make something work
def near_Animal(animalx, animaly):
for x, y, z in XYZVegComplete:
r=2 #xy coordinates in ft
PointsNearAnml = []
if (x-animalx)**2 + (y-animaly)**2 >= r**2:
PracticeTxt=open("/Users/ST/Desktop/practicefilecreate.txt", "w")
print (x, y, z)
#print (x, y, z) >> PracticeTxt, x, y, z
#PracticeTxt.write('%d %d %d \n' % Points)
#PracticeTxt.write('%d %d %d \n' % x y z)
#Points= (x, y, z)
#with open("/Users/sophiathompson/Desktop/practicefilecreate.txt", "w") as PracticeTxt:
#print >> PracticeTxt, Points
#PracticeTxt.close
#Use to call near_Animal: gather Veg Points based on proximity to animal points (using arrays)-
for animalx, animaly in Animal240967:
near_Animal(animalx, animaly)
实际上,你需要两个不同的函数,这取决于你是在一个集合内还是在两个集合之间进行测量。这两个功能的解释是:
它的作用是:
^{} 查找集合元素之间的距离,但只找到值的右上三角(因为} 给出的位置。找到小于阈值的距离(} )
a->b
与b->a
之间的距离相同,a->
总是0
)。这是一个一维数组,它对应于^{pdist < dist
),将其映射到索引(k = i[...]
),并将与这些索引对应的坐标写入磁盘(^{^{} 查找两个集合之间的距离,如二维矩阵。找到小于阈值(} ),然后再次将所有坐标写入磁盘(
cdist(ind, dep, . . . ) < dist
)的元素,找到其中包含True
的任何列(^{np.savetxt(ind[k] . . .)
)如果有很多值,可能需要使用^{}
^{pr2}$相关问题 更多 >
编程相关推荐