【发布时间】:2017-09-03 23:39:41
【问题描述】:
我有动物位置(X、Y、Z)数据和树数据(X、Y、Z)。我需要提取在动物位置周围发生的所有 XYZ 树输入 - 所以我需要将包含 xyz 动物位置的 numpy 数组与包含同一区域中树木的 x y z 点位置的 numpy 数组进行比较。我想将所有 xyz 树拉到点的 4 个单位半径内,并编写了一个函数来做到这一点。但它实际上并不仅仅拉动动物位置周围的树木。它只是打印所有可能的树。如何仅拉动动物点周围的树木,然后将它们放入可以在另一个程序中使用的 .txt 文件中?我是编程新手,非常感谢我能得到的任何帮助。
以下是我的#descriptions 代码:
#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)
【问题讨论】:
-
使用您提供的代码并不容易。考虑创建一个Minimum, Complete, and Verifiable Example,具有代表性示例数据和预期输出。这样,您将更有可能更快地获得更好的答案。
标签: python arrays python-3.x numpy compare