使用Python迭代大型DEM

时间:2017-04-05 02:02:12

标签: python iteration arcgis

我正在尝试迭代一个大型数字高程模型(DEM),并使用Python创建新内容,其内容以4000为增量。下面是逐行迭代文件的代码,但我想增加写入新文件的行数。任何帮助将不胜感激。

import pandas as pd
import numpy as np

#Read in File
df1 = pd.read_table('Large_DEM_File.txt', skiprows=6, chunksize=500)

df = pd.concat(df1)
rows = 320000
y= -1003.00
delta = 0.00025
linecount= 4001

#initialize counter
i = 0
while i <= rows:
    for i, row in df.iterrows():
        filename = open(str(i)+'.txt','w')
        filename.write("ncols 136000\nrows 320000\nxllcorner 122\n")
        filename.write("yllcorner %.5f" %(y+rows*delta-(i+1)*delta))
        filename.write("\ncellsize 0.00025\nNODATA_value -9999\n")
        filename.write(row[0:4000+i])
        i += 4000

1 个答案:

答案 0 :(得分:0)

我没有您的数据,并且对您尝试做的事情感到有点困惑,但这会让您得到您想要的吗?

rows = 320000
y= -1003.00
delta = 0.00025

df_chunk_reader = pd.read_table('Large_DEM_File.txt', skiprows=6, chunksize=500)

for i,chunk in enumerate(df_chunk_reader):

    filename = open(str(i)+'.txt','wb')
    filename.write("ncols 136000\nrows 320000\nxllcorner 122\n")
    filename.write("yllcorner %.5f" %(y+rows*delta-(i+1)*delta))
    filename.write("\ncellsize 0.00025\nNODATA_value -9999\n")
    filename.write(chunk)

有关按块处理数据帧的更多信息,请参阅此处: http://pandas.pydata.org/pandas-docs/stable/io.html#iterating-through-files-chunk-by-chunk