forked from Oslandia/albion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dxf_section.py
52 lines (42 loc) · 1.28 KB
/
dxf_section.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# coding: utf-8
"""
USAGE
dxf_section "dbname..." graph_id file.dxf
"""
import sys
import psycopg2
from dxfwrite import DXFEngine as dxf
from shapely import wkb
from builtins import bytes
con = psycopg2.connect(sys.argv[1])
cur = con.cursor()
cur.execute("""
delete from albion.section
where graph_id='{}'""".format(sys.argv[2]))
cur.execute("""
insert into albion.section(id, triangulation, graph_id, grid_id)
select
_albion.unique_id()::varchar,
st_collectionhomogenize(st_collect(albion.triangulate_edge(ceil_, wall_))),
graph_id, grid_id
from albion.edge
where graph_id='{}'
group by graph_id, grid_id
""".format(sys.argv[2]))
cur.execute("""
select st_collectionhomogenize(st_collect(triangulation))
from albion.section
where graph_id='{}'
""".format(sys.argv[2]))
drawing = dxf.drawing(sys.argv[3]+'.dxf')
m = wkb.loads(bytes.fromhex(cur.fetchone()[0]))
for p in m:
r = p.exterior.coords
drawing.add(dxf.face3d([tuple(r[0]), tuple(r[1]), tuple(r[2])], flags=1))
drawing.save()
cur.execute("""
select albion.to_obj(st_collectionhomogenize(st_collect(triangulation)))
from albion.section
where graph_id='{}'
""".format(sys.argv[2]))
open(sys.argv[3]+'.obj', 'w').write(cur.fetchone()[0])