Hi FME Community,
I'm trying to create an arc from two Points and a radius:
The radius can be concave or convex depending on the radius sign (negative or positive)
Anyone got any ideas how that can be done using FME?
Thanks in advance
Hi FME Community,
I'm trying to create an arc from two Points and a radius:
The radius can be concave or convex depending on the radius sign (negative or positive)
Anyone got any ideas how that can be done using FME?
Thanks in advance
Hi, the FMEArc class from Python FME Objects API has a constructor which creates an Arc instance from two points, radius and whether to create counter-clockwise. See the API document.
init(twoPoints, radius, counterClockwise)
Creates an arc using the 2 points contained in the tuple, and the supplied ‘radius’ and points. startPoint and endPoint (twoPoints€0] and twoPoints 1]) must not be None.
Parameters:Â Â Â Â
twoPoints (tupletFMEPoint]) – The tuple containing 2 points to create the arc in the form (startPoint, endPoint).
radius (float) – The radius value for the arc to be created.
counterClockwise (bool) – Whether to create a counter-clockwise arc.
Â
A PythonCaller with this script might help you.
import fmeobjects
def createArc(feature):
    x1 = float(feature.getAttribute('X1'))
    y1 = float(feature.getAttribute('Y1'))
    x2 = float(feature.getAttribute('X2'))
    y2 = float(feature.getAttribute('Y2'))
    twoPoints = (fmeobjects.FMEPoint(x1, y1), fmeobjects.FMEPoint(x2, y2))
    radius = float(feature.getAttribute('Radius'))
    feature.setGeometry(fmeobjects.FMEArc(twoPoints, abs(radius), 0 < radius))
Â
Hi, the FMEArc class from Python FME Objects API has a constructor which creates an Arc instance from two points, radius and whether to create counter-clockwise. See the API document.
init(twoPoints, radius, counterClockwise)
Creates an arc using the 2 points contained in the tuple, and the supplied ‘radius’ and points. startPoint and endPoint (twoPoints€0] and twoPoints 1]) must not be None.
Parameters:Â Â Â Â
twoPoints (tupletFMEPoint]) – The tuple containing 2 points to create the arc in the form (startPoint, endPoint).
radius (float) – The radius value for the arc to be created.
counterClockwise (bool) – Whether to create a counter-clockwise arc.
Â
A PythonCaller with this script might help you.
import fmeobjects
def createArc(feature):
    x1 = float(feature.getAttribute('X1'))
    y1 = float(feature.getAttribute('Y1'))
    x2 = float(feature.getAttribute('X2'))
    y2 = float(feature.getAttribute('Y2'))
    twoPoints = (fmeobjects.FMEPoint(x1, y1), fmeobjects.FMEPoint(x2, y2))
    radius = float(feature.getAttribute('Radius'))
    feature.setGeometry(fmeobjects.FMEArc(twoPoints, abs(radius), 0 < radius))
Â
Hi, and thanks @takashi
Will that work if radius is set to large number as 3000?
Hi, the FMEArc class from Python FME Objects API has a constructor which creates an Arc instance from two points, radius and whether to create counter-clockwise. See the API document.
init(twoPoints, radius, counterClockwise)
Creates an arc using the 2 points contained in the tuple, and the supplied ‘radius’ and points. startPoint and endPoint (twoPoints€0] and twoPoints 1]) must not be None.
Parameters:Â Â Â Â
twoPoints (tupletFMEPoint]) – The tuple containing 2 points to create the arc in the form (startPoint, endPoint).
radius (float) – The radius value for the arc to be created.
counterClockwise (bool) – Whether to create a counter-clockwise arc.
Â
A PythonCaller with this script might help you.
import fmeobjects
def createArc(feature):
    x1 = float(feature.getAttribute('X1'))
    y1 = float(feature.getAttribute('Y1'))
    x2 = float(feature.getAttribute('X2'))
    y2 = float(feature.getAttribute('Y2'))
    twoPoints = (fmeobjects.FMEPoint(x1, y1), fmeobjects.FMEPoint(x2, y2))
    radius = float(feature.getAttribute('Radius'))
    feature.setGeometry(fmeobjects.FMEArc(twoPoints, abs(radius), 0 < radius))
Â
No problem for large radius.
It doesn't work only when the absolute value of radius is less than half of the distance between two points.
Got a reply from one of my collegues (thanks Daniel Kroon) which gives a very good result:
 Â
import fme
Â
import fmeobjectsÂ
import mathÂdef processFeature(feature):
Â
    """Set the geometry of the feature, either as arc or line, depending on specified Radius.Â
ÂÂ
    Expects the following feature attributes to be present: 'X1','Y1','X2','Y2','Radius'Â
ÂÂ
    Zero radius creates and sets a line-geometryÂ
    Positive radius creates a counter-clockwise arc-geometry.Â
    Negative radius creates a clockwise arc-geometry.Â
ÂÂ
    Feature attribute _used_arc_radius contains the actual radius being used when creating the geometry.Â
    """Â
ÂÂ
    # Get coordinates and radius from feature attributesÂ
    coords = tuple(map(lambda c: float(feature.getAttribute(c)), 'X1','Y1','X2','Y2']))Â
    radius = float(feature.getAttribute('Radius'))Â
ÂÂ
    # Create an arc if radius is other than 0, else create a straight lineÂ
    if(abs(radius)):Â
        # Create point geometryÂ
        twoPoints = tuple(map(lambda c: fmeobjects.FMEPoint(*c), zip(coords ::2],coordsÂ1::2])))Â
ÂÂ
        # Calculate the minimul allowed radius for an arc given two pointsÂ
        min_allowed_radius = round(math.sqrt((coordss0]-coords(2])**2+(coordsd1]-coordso3])**2)/2,0)Â
ÂÂ
        # Create and set arc geometeryÂ
        use_arc_radius = max(abs(radius),min_allowed_radius)Â
ÂÂ
        feature.setGeometry(fmeobjects.FMEArc(twoPoints, use_arc_radius, 0 > radius))Â
        feature.setAttribute('_used_arc_radius',use_arc_radius)Â
ÂÂ
    else:Â
        # Create and set arc geometeryÂ
        feature.setGeometry(fmeobjects.FMELine(list(zip(coordso::2],coordsr1::2]))))Â
        feature.setAttribute('_used_arc_radius',0)