Skip to main content
Solved

What is python 'CROSS' function equivalent expression in FME ?

  • December 6, 2023
  • 12 replies
  • 44 views

vimva679
Supporter
Forum|alt.badge.img+9

Python = np.cross(XYZ, ABC) ????

image

Best answer by geomancer

It's all just a bit of math.

CrossProd_X = @Evaluate(@Value(Y)*@Value(C)-@Value(Z)*@Value(B))
CrossProd_Y = @Evaluate(@Value(Z)*@Value(A)-@Value(X)*@Value(C))
CrossProd_Z = @Evaluate(@Value(X)*@Value(B)-@Value(Y)*@Value(A))

 

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.

12 replies

paalpedersen
Contributor
Forum|alt.badge.img+7
  • Contributor
  • December 6, 2023

Use the pythoncaller. If you need further guideance you must provide som example data.


paalpedersen
Contributor
Forum|alt.badge.img+7
  • Contributor
  • December 6, 2023

Use the pythoncaller. If you need further guideance you must provide som example data.

import fmeobjects

import numpy as np

 

class FeatureProcessor:

   

  def __init__(self):

    pass

     

  def input(self, feature):

     

    a = feature.getAttribute('_list{}.a')

    b = feature.getAttribute('_list{}.b')

     

    r = np.cross(a, b)

    for i, v in enumerate(r):

      feature.setAttribute(f'_list{{{i}}}.result', v)

    self.pyoutput(feature)

     

  def close(self):

    pass

 


vimva679
Supporter
Forum|alt.badge.img+9
  • Author
  • Supporter
  • December 6, 2023

import fmeobjects

import numpy as np

 

class FeatureProcessor:

   

  def __init__(self):

    pass

     

  def input(self, feature):

     

    a = feature.getAttribute('_list{}.a')

    b = feature.getAttribute('_list{}.b')

     

    r = np.cross(a, b)

    for i, v in enumerate(r):

      feature.setAttribute(f'_list{{{i}}}.result', v)

    self.pyoutput(feature)

     

  def close(self):

    pass

 

Based on L and F and UVN

 

I would like to assign DX, DY and DZ values to DU, DV and DN

image 

def myfinction(L, F, Dxyz):

   DLF = [0,0,-1]

   ULF = [0,0,1]

 

   NLF = [0,1,0]

   SLF = [0,-1,0]

 

   ELF = [1 ,0,0]

   WLF = [-1 ,0,0]

   if L == "D":

      UAP = DLF

   elif L == "U":

        UAP = ULF

   elif L == "N":

       UAP = NLF

   elif L == "S":

       UAP = SLF

   elif L == "E":

       UAP = ELF

   elif L == "W":

       UAP = WLF

 

   if F == "D":

      FAP = DLF

   elif F == "U":

        FAP = ULF

   elif F == "N":

       FAP = NLF

   elif F == "S":

       FAP = SLF

   elif F == "E":

       FAP = ELF

   elif F == "W":

       FAP = WLF

 

   # STEP 3 a

   # Cross produ²ct 

   VAP = np.cross(FAP, UAP)

   DU,DV,DN = np.linalg.inv(np.column_stack((UAP, VAP, FAP))).dot(np.array(Dxyz))

   return DU,DV,DN


vimva679
Supporter
Forum|alt.badge.img+9
  • Author
  • Supporter
  • December 6, 2023

import fmeobjects

import numpy as np

 

class FeatureProcessor:

   

  def __init__(self):

    pass

     

  def input(self, feature):

     

    a = feature.getAttribute('_list{}.a')

    b = feature.getAttribute('_list{}.b')

     

    r = np.cross(a, b)

    for i, v in enumerate(r):

      feature.setAttribute(f'_list{{{i}}}.result', v)

    self.pyoutput(feature)

     

  def close(self):

    pass

 

The empty BLACK cells should have the values as Target


paalpedersen
Contributor
Forum|alt.badge.img+7
  • Contributor
  • December 6, 2023

import fmeobjects

import numpy as np

 

class FeatureProcessor:

   

  def __init__(self):

    pass

     

  def input(self, feature):

     

    a = feature.getAttribute('_list{}.a')

    b = feature.getAttribute('_list{}.b')

     

    r = np.cross(a, b)

    for i, v in enumerate(r):

      feature.setAttribute(f'_list{{{i}}}.result', v)

    self.pyoutput(feature)

     

  def close(self):

    pass

 

image


vimva679
Supporter
Forum|alt.badge.img+9
  • Author
  • Supporter
  • December 6, 2023

import fmeobjects

import numpy as np

 

class FeatureProcessor:

   

  def __init__(self):

    pass

     

  def input(self, feature):

     

    a = feature.getAttribute('_list{}.a')

    b = feature.getAttribute('_list{}.b')

     

    r = np.cross(a, b)

    for i, v in enumerate(r):

      feature.setAttribute(f'_list{{{i}}}.result', v)

    self.pyoutput(feature)

     

  def close(self):

    pass

 

Noooo, this target column is just to give idea how at the end excel sheet should look ........i.e. what are the values expected in that empty BLACK header Cell (D:U , D:V and D:N)

 

this is how the excel sheet looks like

image 

the values are dependent on

DLF = [0,0,-1]....down

ULF = [0,0,1]....up

NLF = [0,1,0]...North

SLF = [0,-1,0].....South

ELF = [1 ,0,0]..... East

WLF = [-1 ,0,0].....West


vimva679
Supporter
Forum|alt.badge.img+9
  • Author
  • Supporter
  • December 6, 2023

import fmeobjects

import numpy as np

 

class FeatureProcessor:

   

  def __init__(self):

    pass

     

  def input(self, feature):

     

    a = feature.getAttribute('_list{}.a')

    b = feature.getAttribute('_list{}.b')

     

    r = np.cross(a, b)

    for i, v in enumerate(r):

      feature.setAttribute(f'_list{{{i}}}.result', v)

    self.pyoutput(feature)

     

  def close(self):

    pass

 

if you cld also share me your FME workbench that wld be ease as well


geomancer
Evangelist
Forum|alt.badge.img+60
  • Evangelist
  • Best Answer
  • December 6, 2023

It's all just a bit of math.

CrossProd_X = @Evaluate(@Value(Y)*@Value(C)-@Value(Z)*@Value(B))
CrossProd_Y = @Evaluate(@Value(Z)*@Value(A)-@Value(X)*@Value(C))
CrossProd_Z = @Evaluate(@Value(X)*@Value(B)-@Value(Y)*@Value(A))

 


paalpedersen
Contributor
Forum|alt.badge.img+7
  • Contributor
  • December 6, 2023

import fmeobjects

import numpy as np

 

class FeatureProcessor:

   

  def __init__(self):

    pass

     

  def input(self, feature):

     

    a = feature.getAttribute('_list{}.a')

    b = feature.getAttribute('_list{}.b')

     

    r = np.cross(a, b)

    for i, v in enumerate(r):

      feature.setAttribute(f'_list{{{i}}}.result', v)

    self.pyoutput(feature)

     

  def close(self):

    pass

 

Its just a boilerplate for you to work with. You can setup your if else statements, and all that stuff. This is just to show how to get started.


paalpedersen
Contributor
Forum|alt.badge.img+7
  • Contributor
  • December 6, 2023

import fmeobjects

import numpy as np

 

class FeatureProcessor:

   

  def __init__(self):

    pass

     

  def input(self, feature):

     

    a = feature.getAttribute('_list{}.a')

    b = feature.getAttribute('_list{}.b')

     

    r = np.cross(a, b)

    for i, v in enumerate(r):

      feature.setAttribute(f'_list{{{i}}}.result', v)

    self.pyoutput(feature)

     

  def close(self):

    pass

 

Everything in the workspace is evidently present in the image.


vimva679
Supporter
Forum|alt.badge.img+9
  • Author
  • Supporter
  • December 6, 2023

import fmeobjects

import numpy as np

 

class FeatureProcessor:

   

  def __init__(self):

    pass

     

  def input(self, feature):

     

    a = feature.getAttribute('_list{}.a')

    b = feature.getAttribute('_list{}.b')

     

    r = np.cross(a, b)

    for i, v in enumerate(r):

      feature.setAttribute(f'_list{{{i}}}.result', v)

    self.pyoutput(feature)

     

  def close(self):

    pass

 

alright let me get started and see if my workbench is able to get it right inserted .


vimva679
Supporter
Forum|alt.badge.img+9
  • Author
  • Supporter
  • December 6, 2023

import fmeobjects

import numpy as np

 

class FeatureProcessor:

   

  def __init__(self):

    pass

     

  def input(self, feature):

     

    a = feature.getAttribute('_list{}.a')

    b = feature.getAttribute('_list{}.b')

     

    r = np.cross(a, b)

    for i, v in enumerate(r):

      feature.setAttribute(f'_list{{{i}}}.result', v)

    self.pyoutput(feature)

     

  def close(self):

    pass

 

this is the error image