如何从使用numpy arange生成的坐标列表中生成坐标列表(纬度,经度)

时间:2019-03-26 12:49:06

标签: python coordinates

我正在尝试生成具有lat,long,i,j,z值的txt文件。我已经可以使用以下命令创建i,j,z值的列表:

n = 51
m = 31

data = [(i,j,i*2) for i in range(n) for j in range(m)]

但是,如果我使用numpy arange创建一系列值,我不确定该怎么做

lat = np.arange(33.8916,34.0426,0.003)
long = np.arange(78.0136,77.9236,-0.003)

有没有办法做到这一点? (n,m)和(lat,long)都是相同的尺寸(51,31)。所以我想拥有一个txt文件,该文件具有:

33.8916,78.0136,0,0,0
33.8946,78.0166,0,1,0
...
34.0416,77.9236,50,30,100

1 个答案:

答案 0 :(得分:0)

使用<div class="ax-cb-div"> <input class="inp-cbx" id="1" type="checkbox" style="display: none;"/> <label for="1" class="cbx"><span> <svg width="12px" height="10px" viewbox="0 0 12 10"> <polyline points="1.5 6 4.5 9 10.5 1"></polyline> </svg></span><span>Checkbox number 1</span> </label> </div> <div class="ax-cb-div"> <input class="inp-cbx" id="2" type="checkbox" style="display: none;"/> <label for="2" class="cbx"><span> <svg width="12px" height="10px" viewbox="0 0 12 10"> <polyline points="1.5 6 4.5 9 10.5 1"></polyline> </svg></span><span>Checkbox number 2</span> </label> </div> <div class="ax-cb-div"> <input class="inp-cbx" id="3" type="checkbox" style="display: none;"/> <label for="3" class="cbx"><span> <svg width="12px" height="10px" viewbox="0 0 12 10"> <polyline points="1.5 6 4.5 9 10.5 1"></polyline> </svg></span><span>Checkbox number 3</span> </label> </div> <div class="ax-cb-div"> <input class="inp-cbx" id="4" type="checkbox" style="display: none;"/> <label for="4" class="cbx"><span> <svg width="12px" height="10px" viewbox="0 0 12 10"> <polyline points="1.5 6 4.5 9 10.5 1"></polyline> </svg></span><span>Checkbox number 4</span> </label> </div>

zip()

输出(list.txt)

n = 51
m = 31

data = [(i,j,i*2) for i in range(n) for j in range(m)]
data = [', '.join(map(str, x)) for x in data]   # removing the tuples

lat = np.arange(33.8916,34.0426,0.003)
long = np.arange(78.0136,78.1036,0.003)

res = list(zip(lat,long,data))     # zipping the lists together

logFile = "list.txt"

with open(logFile, "w") as f:
   for data in res:
       f.write("%s, %s, %s" % data + "\n")

编辑

要一直使用到33.8916, 78.0136, 0, 0, 0 33.8946, 78.0166, 0, 1, 0 33.8976, 78.0196, 0, 2, 0 33.9006, 78.0226, 0, 3, 0 33.9036, 78.0256, 0, 4, 0 33.9066, 78.0286, 0, 5, 0 . . . ,请使用data

zip_longest()
  

注意:使用res = list(zip_longest(lat,long,data)) logFile = "list.txt" with open(logFile, "w") as f: for data in res: f.write("%s, %s, %s" % data + "\n") zip_longest插入None

例如

missing

因此:

输出

print(len(data))    # 1581
print(len(lat))     # 51
print(len(long))    # 31

编辑2

要具有一致的列表,请进行以下更改:

33.8916, 78.0136, 0, 0, 0
33.8946, 78.0166, 0, 1, 0
33.8976, 78.0196, 0, 2, 0
.
.
33.9846, None, 1, 0, 2
33.9876, None, 1, 1, 2
.
.
None, None, 50, 28, 100
None, None, 50, 29, 100
None, None, 50, 30, 100