Skip to main content
Question

How to add a measure on point of a line?

  • March 15, 2019
  • 3 replies
  • 54 views

arthy
Contributor
Forum|alt.badge.img+8
  • Contributor
  • 101 replies

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?

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

3 replies

david_r
Celebrity
  • 8394 replies
  • March 15, 2019

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 that setMeasure() requires that the given list contains the exact same number of floats as the number of vertices on the line geometry. Otherwise you can use setMeasureAt() 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

 


arthy
Contributor
Forum|alt.badge.img+8
  • Author
  • Contributor
  • 101 replies
  • March 15, 2019

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.


takashi
Celebrity
  • 7843 replies
  • March 15, 2019

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 fmeobjects
def 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.