peteralstorp wrote:
@virtualcitymatt Thanks, Matt! That's interesting but I need the correct lengths so the solution must account for 3D.
Ahh that's too bad.
The next thing I've seen is that the pipe sections that are not joins or corners seem to be read by FME as FMEExtrusion geometry - this is great because the extrusion is just a vector which is stored in the geometry.
The downside is that there is no transformer to extract this, but fortunately there is some pretty simply python that can be used to get it and calculate the length.
Here is a screen shot from a small workspace which just filters out the unsupported geometries types (we just want the IFME Extrusion.
The Pyhton Caller is used to extract the extrusion vector and create a _len attribute from it.
Here is the python inside the transformer:
1import fme
2import fmeobjects
3from fmeobjects import FMEFeature, FMELine, FMEGeometryTools
4
5class FeatureProcessor(object):
6 def __init__(self):
7 """Base constructor for class members."""
8 pass
9
10 def input(self, feature):
11
12
13 #Here we get the extrusion vector from the pipes, create a line feature out of it and calculate the lines length
14
15 #extract the vector
16 vec=feature.getGeometry().getExtrusionVectorXYZ()
17
18 #create an empty line
19 _line=FMELine()
20
21 #add two points to the line, 0,0,0 (the origin) and the end of the vector we extracted above)
22 _line.appendPoints([(0,0,0),vec])
23
24 #extract the length of the lines (the "True" incuicates a 3D Length)
25 _len=_line.getLength(True)
26
27 #dd _len as an attribtue to the feature
28 feature.setAttribute("_len",_len)
29
30 #output the feature with a new attribute
31 self.pyoutput(feature)
32
33 def close(self):
34 """This method is called once all the FME Features have been processed
35 from input().
36 """
37 pass
The important stuff is Indie the 'Input' function.
This of course only works on those pipe sections which are read as extrusions, sadly not the bends or joins.