#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 _create_and_output_line(self, start_point, end_point): 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 input(self, feature: fmeobjects.FMEFeature): grid = { n + 1: ( (n % 5) * _offset + (_offset * random.uniform(0.5, 1)), # (n % 5): 0-based column *offset = X coord (n // 5) * _offset + (_offset * random.uniform(0.5, 1))# (n // 5): 0-based row * offset = Y coord ) for n in range(num_points) } for _count,j in grid.items(): newFeature = fmeobjects.FMEFeature() newFeature.setAttribute('_count', int(_count)) point = fmeobjects.FMEPoint() point.setXYZ(float(j[0]), float(j[1]), 0) newFeature.setGeometry(point) self.pyoutput(newFeature) for i in range(len(grid)): for j in range(i + 1, len(grid)): start_point = grid[i + 1] end_point = grid[j + 1] # Check if the points are in the same row or column if i == j-1: # or start_point[1] == end_point[1]: self._create_and_output_line(start_point, end_point) 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) # grid2 grid = { n + 1: ( (n % 5) * _offset, # (n % 5): 0-based column *offset = X coord (n // 5) * _offset + 1000 # (n // 5): 0-based row * offset = Y coord ) for n in range(num_points) } for _count,j in grid.items(): newFeature = fmeobjects.FMEFeature() newFeature.setAttribute('_count', int(_count)) point = fmeobjects.FMEPoint() point.setXYZ(float(j[0]), float(j[1]), 0) newFeature.setGeometry(point) self.pyoutput(newFeature) for i in range(len(grid)): for j in range(i + 1, len(grid)): start_point = grid[i + 1] end_point = grid[j + 1] # Check if the points are in the same row or column if i == j-1 : # or start_point[1] == end_point[1]: self._create_and_output_line(start_point, end_point) 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) # grid 3 grid = { n + 1: ( (n % 5) * _offset + (_offset * random.uniform(0.5, 1)), # (n % 5): 0-based column *offset = X coord (n // 5) * _offset + (_offset * random.uniform(0.5, 1)) -1000 # (n // 5): 0-based row * offset = Y coord ) for n in range(num_points) } for _count,j in grid.items(): newFeature = fmeobjects.FMEFeature() newFeature.setAttribute('_count', int(_count)) point = fmeobjects.FMEPoint() point.setXYZ(float(j[0]), float(j[1]), 0) newFeature.setGeometry(point) self.pyoutput(newFeature) for i in range(len(grid)): for j in range(i + 1, len(grid)): start_point = grid[i + 1] end_point = grid[j + 1] # Check if the points are in the same row or column if i == j-2: # or start_point[1] == end_point[1]: self._create_and_output_line(start_point, end_point) 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