如何从DXF文件中提取所有坐标 [英] How to extract all coordinates from a dxf file

查看:1824
本文介绍了如何从DXF文件中提取所有坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个dxf文件 https://filebin.net/7l8izrv2js7doicc/5holes-8x8.dxf?t = 9ro7k928 (下载并扩展名为.dxf) 我能够将其解析为行和其他所有内容,但是我现在想提取所有坐标. 目的是,如果我获得所有坐标,则Id能够为所有这些坐标创建一个边界框. 由于该图形具有曲线和线条,因此我不知道如何为曲线等做画.

===我的显示行​​的部分代码&拔出启动和线的终点====

flist=open("test2.dxf")

#fil.readlines()
# entityflist = open("filename.txt").readlines()
lst=[]

parsing = False
for line in flist:
    #print ("==================")
    if line.startswith("ENDSEC"):
        parsing = False
    if parsing:
        #print (line)
        lst.append(line)
        #Do stuff with data 
    if line.startswith("LINE"):
        parsing = True
        #print ("LINE")

# lines coordinates list
ts=(''.join(lst).split('LINE'))

#print out all the point coordinates of lines start & end
# i.e. 2 coordinate pairs for each line
for i in ts:
    print ((i.split()[19],i.split()[21]))
    print ((i.split()[15],i.split()[17]))

解决方案

您的链接不起作用,而是发布了几行文件以显示结构,因为这是要求人们下载大文件的不良做法.

好像有一个名为ezdxf的用于处理dxf文件的库. 此处是指向他们的指南的链接,说明了如何从dxf文件中提取数据

Ive got a dxf file https://filebin.net/7l8izrv2js7doicc/5holes-8x8.dxf?t=9ro7k928 (download and name extension as .dxf) Im able to parse it for lines and all but I want to extract all coordinates now. The purpose is that if I get all the coordinates then Id be able to create a bounding box for all these coordinates. Since the drawing has curves and lines I dont know how to do it for curves etc.

===MY PARTIAL CODE TO DISPLAY LINES & pull out start & end point of lines====

flist=open("test2.dxf")

#fil.readlines()
# entityflist = open("filename.txt").readlines()
lst=[]

parsing = False
for line in flist:
    #print ("==================")
    if line.startswith("ENDSEC"):
        parsing = False
    if parsing:
        #print (line)
        lst.append(line)
        #Do stuff with data 
    if line.startswith("LINE"):
        parsing = True
        #print ("LINE")

# lines coordinates list
ts=(''.join(lst).split('LINE'))

#print out all the point coordinates of lines start & end
# i.e. 2 coordinate pairs for each line
for i in ts:
    print ((i.split()[19],i.split()[21]))
    print ((i.split()[15],i.split()[17]))

解决方案

Your link doesn't work but rather post a few lines of the file to show the structure, as it's bad practice to request people downloading huge files.

Looks like there is a library for handling dxf files called ezdxf. Here is a link to their guide on how to extract data from a dxf file

这篇关于如何从DXF文件中提取所有坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆