【发布时间】:2019-09-15 12:06:24
【问题描述】:
我有一些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)
【问题讨论】:
标签: python operating-system subprocess