我有一些dxf
文件,希望将它们转换为geojson
文件:
import subprocess
from subprocess import call
import os
working_directory = 'D:/dxf_files/'
for subdir, dirs, files in os.walk(working_directory):
for file in files:
if file.endswith('.dxf'):
print(file)
输出:
BJ-SZZDS-1010084246-dongta-11.dxf
BJ-SZZDS-1010084246-dongta-12.dxf
BJ-SZZDS-1010084246-dongta-17.dxf
BJ-SZZDS-1010084246-dongta-18.dxf
BJ-SZZDS-1010084246-dongta-19.dxf
...
我想把这些文件放在下面的input_file
中,通过替换文件的扩展名保持output_file
文件名与input_file
相同。现在两个代码块是分开的,我怎样才能把它们组合在一起呢?谢谢你的帮助。你知道吗
input_file = 'BJ-SZZDS-1010084246-dongta-11.dxf'
output_file = 'BJ-SZZDS-1010084246-dongta-11.geojson'
def dxf2geojson(output_file, input_file):
command = ['ogr2ogr', '-f', 'GeoJSON', output_file, input_file]
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
return p
dxf2geojson(output_file, input_file)
您可以通过将文件迭代代码中的打印函数替换为转换函数来实现这一点。你知道吗
首先,可以将所有文件名保存在列表中,例如
file_list
:然后,从
file_list
执行每个文件:您可以将所有文件保存到一个列表中,然后对其进行迭代。你知道吗
相关问题 更多 >
编程相关推荐