#main_script import numpy as np import random import math import matplotlib.pyplot as plt import fme import fmeobjects from fmeobjects import FMELine grid_cnt = 5 num_points = 20 _offset = 200 class FeatureProcessor(object): def __init__(self): pass def input(self, feature: fmeobjects.FMEFeature): """This method is called for each feature which enters the PythonCaller. Processed input features can be emitted from this method using self.pyoutput(). If knowledge of all input features is required for processing, then input features should be cached to a list instance variable and processed using group processing or in the close() method. """ grid = { n + 1: ( (n % 5) * _offset, # (n % 5): 0-based column *offset = X coord (n // 5) * _offset # (n // 5): 0-based row * offset = Y coord ) for n in range(num_points) } for i in range(len(grid)): for j in range(i + 1, len(grid)): start_point = grid[i + 1] end_point = grid[j + 1] line = FMELine() line.appendPoint((start_point[0], start_point[1], 0)) line.appendPoint((end_point[0], end_point[1], 0)) lineFeature = fmeobjects.FMEFeature() lineFeature.setGeometry(line) self.pyoutput(lineFeature) # distorted grid grid = { n + 1: ( (n % 5) * _offset * random.uniform(0.5, 1) , # (n % 5): 0-based column * offset * random factor = X coord (n // 5) * _offset * random.uniform(0.5, 1) +1000 # (n // 5): 0-based row * offset = Y coord ) for n in range(num_points) } for i in range(len(grid)): for j in range(i + 1, len(grid)): start_point = grid[i + 1] end_point = grid[j + 1] line = FMELine() line.appendPoint((start_point[0], start_point[1], 0)) line.appendPoint((end_point[0], end_point[1], 0)) lineFeature = fmeobjects.FMEFeature() lineFeature.setGeometry(line) self.pyoutput(lineFeature) def close(self): """This method is called once all the FME Features have been processed from input().""" pass def process_group(self): pass