跳转到主要内容

CityGML转可打印STL

项目描述

Python库,用于将CityGML数据转换为FDM 3D打印机可打印的STL 3D模型,例如各种RepRap打印机。

支持CityGML版本2.0.0、1.0.0和0.4.0。其他版本也可能工作。

这是布拉格查理技术大学土木工程学院免费软件GIS课程的一个课程项目(2014/2015学年,F组)。以MIT许可证发布(见LICENSE)。

Image of generated STL

柏林亚历山大广场的德国CityGML作为STL。数据© 卡尔斯鲁厄研究中心,应用计算机科学研究所

安装

要安装,只需使用常规Python方法,例如pip。建议在安装此或其他需求之前安装Cython。支持Python 3.3+、2.7和pypy。

pip install Cython
pip install citygml2stl

或者,如果您是从克隆的存储库或解压的源代码安装

pip install Cython
pip install -r requirements.txt
python setup.py install

用法

要从Python中使用cityglm2stl,请按照以下步骤操作

# import stuff
from citygml2stl import citygml
from citygml2stl import polygons
from citygml2stl import stl

# parse the CityGML file
c = citygml.CityGML('Berlin_Alexanderplatz_v0.4.0.xml')

# export to file berlin.stl
with stl.StlFile('berlin.stl') as berlin:
    # Specify as many types as you want,
    # or leave without arguments to get all city objects
    for obj in c.get_objects_of_types('Building'):
        berlin.write_triangles(polygons.object2triangles(obj))

或者,如果您更喜欢有多个STL文件

# initialize a counter for filenames
counter = 0

for obj in c.get_objects_of_types('Building'):
    with stl.StlFile('berlin{}.stl'.format(counter)) as berlin:
        berlin.write_triangles(polygons.object2triangles(obj))
    counter += 1

请注意,由于大多数CityGML数据的质量,STL可能不有效,因为面可能会相交。此外,由于算法的工作方式,面的顶点顺序是随机的,并且不一定遵循右手定则。

虽然如此,考虑到输出需要修复。使用公共云服务,例如 netfabb Cloud 或甚至开源工具 ADMesh 来修复输出。

您甚至可以使用 Python的admesh模块 来修复STL文件

import admesh
...

filename = 'berlin{}.stl'.format(counter)
with stl.StlFile(filename) as berlin:
    berlin.write_triangles(polygons.object2triangles(obj))

s = admesh.Stl(filename)
s.repair()

# the results are often located on unthinkable coordinates
s.translate(0, 0, 0)
s.write_binary(filename)

请注意,由于admesh模块的限制,目前无法将citygml2stl的输出重定向到admesh,而无需首先将其写入文件。

安装到PATH的示例脚本已安装

$ citygml2stl Berlin_Alexanderplatz_v0.4.0.xml
Converting Berlin_Alexanderplatz_v0.4.0.xml to Berlin_Alexanderplatz_v0.4.0.stl

作者

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码分发

citygml2stl-0.1a1.tar.gz(10.9 kB 查看哈希

上传时间 源代码

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面