#main_script
import fme
import fmeobjects
import math
def compute_second_point(start_point, bearing, distance):
x1, y1 = start_point
# Convert bearing to radians
bearing_rad = math.radians(bearing)
# Calculate delta x and delta y
dx = distance * math.sin(bearing_rad)
dy = distance * math.cos(bearing_rad)
# Compute second point
x2 = x1 + dx
y2 = y1 + dy
return (x2, y2)
def compute_bearing(x0,y0,x1,y1):
# Calculate differences
delta_x = x1- x0
delta_y = y1 - y0
# Calculate the angle in radians
theta = math.atan2(delta_x, delta_y)
# Convert to degrees and ensure the angle is within [0, 360)
bearing = (math.degrees(theta) + 360) % 360
return bearing
class FeatureProcessor(object):
def __init__(self):
pass
def input(self, feature: fmeobjects.FMEFeature):
# grab parameters to make the "ribs"
distance = feature.getAttribute('segment_size')
angle = feature.getAttribute('angle')
id = feature.getAttribute('ID')
x0,y0,z0 = feature.getGeometry().getStartPoint().getXYZ()
x1,y1,z1 = feature.getGeometry().getEndPoint().getXYZ()
bearing = compute_bearing(x0,y0,x1,y1)
start_point = (x1,y1)
start_point_fme = fmeobjects.FMEPoint(x1,y1)
# right side rib
outpt_r = compute_second_point(start_point, bearing+ angle, distance)
newFeature = fmeobjects.FMEFeature()
line_r = fmeobjects.FMELine([start_point, outpt_r])
# line_r.copyAttributesFromFeature(feature, True)
newFeature.setGeometry(line_r)
newFeature.setAttribute('ID',id)
self.pyoutput(feature)
self.pyoutput(newFeature)
# left side rib
outpt_l = compute_second_point(start_point, bearing- angle, distance)
newFeature = fmeobjects.FMEFeature()
line_l = fmeobjects.FMELine([start_point, outpt_l])
# line_l.copyAttributesFromFeature(feature, True)
newFeature.setGeometry(line_l)
newFeature.setAttribute('ID',id)
self.pyoutput(feature)
self.pyoutput(newFeature)
def close(self):
pass
def process_group(self):
pass