span8
span4
span8
span4
Hello,
I have multiple segments line for which I would like to add a measure on the starting/ending of each segment.In other words,I would like to create a "fake" LRS where the measure will be computed from some attributes of the feature.
I thinking of using python with this logic
def addMeasure(feature coord = feature.getAllCoordinates() n=len(coord) mfr=feature.getAttribute('MEASURE_TO') mto=feature.getAttribute('MEASURE_FROM') if mfr!=None and str(mfr)!='':setMeasure(coord[0],mfr)setMeasure(coord[n-1],mfr feature.addCoordinates(coord)
where setMeasure should be a python version of the measureSetter Transformer.
How should I proceed?
The FMEArc class has setMeasureValues method.You can use the method to set measure to two points (start and end) or three points (start,mid and end) of an arc.This is an example that will set measure to two points of an arc.
import fmeobjectsdef addMeasureToArc(feature): try: arc = feature.getGeometry() mfr = float(feature.getAttribute('MEASURE_FROM')) mto = float(feature.getAttribute('MEASURE_TO')) arc.setMeasureValues(False,(mfr,mto)) feature.setGeometry(arc) except Exception as ex: logger = fmeobjects.FMELogFile() logger.logMessageString(str(ex),fmeobjects.FME_ERROR) raise ex # Terminate the translation.
Hope this helps.
Try something like the following:
from fmeobjects import *def set_measure(feature): mfr = str(feature.getAttribute('MEASURE_FROM')) or '' mto = str(feature.getAttribute('MEASURE_TO')) or '' if mfr.isdigit() and mto.isdigit(): measures = [float(mfr),float(mto)] if feature.getGeometryType() == FME_GEOM_LINE: line = feature.getGeometry() line.setMeasure(measures) feature.setGeometry(line)
Note thatsetMeasure()requires that the given list contains the exact same number of floats as the number of vertices on the line geometry.Otherwise you can usesetMeasureAt() which allows you to specfiy the vertex index for each measure,e.g.
line.setMeasureAt(0,measures[0]) line.setMeasureAt(line.numPoints()-1,measures[1])
More info in the fmeobjects API docs:
http://docs.亚搏在线safe.com/fme/html/FME_Objects_Python_API/index.html
Thanks@david_r
The function setMeasureAt does what I want but only for line.
What similar function could I be used to do the same thing for arc?
I wasn't able to see any function like setMeasure for Arc in the fmeobjects API docs.
What I really want is to add a measure to points of curves that could be line or arc.
Importing Orfeo Toolbox to FME (or running mean-shift algorithm in FME)?1 Answer
Replace attribute values for all attributes2 Answers
Pass attribute values to a custom transformer loop3 Answers
Dynamic attribute creation and expose?1 Answer
Join Two table unique attribute using contains value3 Answers
© 2019 亚搏在线Safe Software Inc |Legal