Form Diagram for large networks

I was trying to generate the form diagram with line data input from a json file. The formDiagram function exits with a ‘Key error’ at line 1507 of mesh.py. The network is of 2514 line segments. It works fine when I try getting the form diagram from first 1185 lines (edges).

The code section is as follows

with open(‘lines.json’) as f:>
data = json.load(f)
lines =
for i in range(1,len(data)): #error at 1186th line
tmp = [(data[i][‘End X’],data[i][‘End Y’], data[i][‘End Z’]), (data[i][‘Start X’], data[i][‘Start Y’], data[i][‘Start Z’])]
lines.append(tmp)
form = FormDiagram.from_lines(lines)

json file is as follow

[
{
“End X”: 355.6245,
“End Y”: -372.2939,
“End Z”: 0.6798,
“Start X”: 355.4023,
“Start Y”: -377.328,
“Start Z”: 0.6796,
“Layer”: 1
},

Has it something to do with the preprocessing of line data? But formdiagram seems to work well with duplicated lines and reversed order of start/end of lines.

Hi Isuru,

The from_lines function does not change if the data comes from a json file or not. So the problem is likely come from the pre-processing the lines or with the data itself. Could you send me the json file?

Hi Isuru,

The problem lies with your data, there are a few lines that start and end from the same point. This causes a problem generating the topology of the diagram. If you correct the data it should work. Otherwise you can check for this error in the data as you are generating the lines, like so:


import json
from compas_tna.diagrams import FormDiagram

with open('lines.json') as f:
    data = json.load(f)
lines = []
print len(data)
for i in range(1, len(data)):
    tmp = [(data[i]['End X'], data[i]['End Y'], data[i]['End Z']), (data[i]['Start X'], data[i]['Start Y'], data[i]['Start Z'])]

    if tmp[0] != tmp[1]:
        lines.append(tmp)

form = FormDiagram.from_lines(lines, precision='3f')

This should work and return a FormDiagram object.

Thank you very much. It works well with that check