Skip to main content
I am trying to figure out a way to plot a series of points based off xy values in a table. The initial xy values is a lat long and the each of the other points is a set of xy offsets. So, I may have record 1 with.. -107.55 36.55 and the offset is .01 .01. So, the new xy for 1 would be +.01. Then I need it to goto the next record and use the new offset xy. Keeping in mind that the 2nd record has no spatial and needs to adopt the new xy from the last record. In the end the table will create a line based off the 1st starting point. Any thoughts on this? I've tried using the offsetter but without the previous coordinate attached to the offset it doesnt work. Any thoughts?
Hi,

 

 

I would use a PythonCaller with a script like this:

 

-----

 

import fmeobjects   class XYSetter(object):     def __init__(self):         self.lastXY = None              def input(self, feature):

 

        # Get x, y of the feature.

 

        # Assuming each feature has x, y as its attributes named 'x', 'y'.         x = float(feature.getAttribute('x'))         y = float(feature.getAttribute('y'))                  # If the last (x, y) exists (the feature is not the first one),         # calculate new offset (x, y) and set them back to the feature.         if self.lastXY:             x, y = self.lastXY 0] + x, self.lastXY 1] + y             feature.setAttribute('x', x)             feature.setAttribute('y', y)                      # Update the last (x, y) for the next feature.         self.lastXY = (x, y)         self.pyoutput(feature)              def close(self):         pass -----

 

 

After this, create points (2DPointReplacer) and connect them into a line (PointConnector).

 

 

Takashi
... if you initialize the last (x, y) to (0, 0), the script will be more concise:

 

-----

 

import fmeobjects   class XYSetter(object):     def __init__(self):         self.lastXY = (0.0, 0.0)              def input(self, feature):         # Calculate new offset (x, y) and set them back to the feature.         x = self.lastXYÂ0] + float(feature.getAttribute('x'))         y = self.lastXY 1] + float(feature.getAttribute('y'))         feature.setAttribute('x', x)         feature.setAttribute('y', y)                      # Update the last (x, y).         self.lastXY = (x, y)         self.pyoutput(feature)              def close(self):         pass -----

 

 

Takashi
supplementation: I assume the table and the expected (x, y) as followings: table x, y -107.55, 36.55 .01, .01 .03, .03 ...   expected (x, y) (-107.55, 36.55) (-107.54, 36.56) = (-107.55+.01, 36.55+.01) (-107.51, 36.59) = (-107.54+.03, 36.56+.03)
Hi,

 

 

you can also use the VariableSetter and the VariableRetriever to store values between features. Something like:

 

  • Sort features based on feature ID and point sequence
  • Use VariableRetriever to check if current ID is different from previous ID
  • If ID is different, set starting point to absolute X,Y coordinates, store this value using the VariableSetter
  • If same ID, use ExpressionEvaluator and 2DPointReplacer to transform relative coordinates to absolute coordinates
  • Store the current ID with the VariableSetter

 

David
Thank you both for some direction. I was able to come closest with Davids idea, however I am hitting a stumbling block. I can't figure out exactly how to get the previous coordinate. I tried using the same method as with the offsets using the new XY, but it still thinks the original XY value is the source. So, when I add the offset its still adding to the original and not the new xy that should have been created in the previous record. This is a confusing one for me! I can see it in my head but just can't get there.

 

 

Maybe I can try to explain it better. I have an origin xy value and xy offset distances. Only the initial point has a coordinate. I need to generate a point for each xy offset value base off the distance from eachother. So, for row one I need it to move -0.37.. and 0.39.. from the origin point and create a point. Then I need that new location to be the point of origin and for row 2 I need it to move -0.58.. and 0.42.. from the newly created previous point.

 

 

Here is the table I am looking at. 

 

 

 

 

ID ORIG_Y ORIG_X DIST_EW DIST_NS 1000 29672.25014 1233391.628 -0.373693773 0.394007793 1000 29672.25014 1233391.628 -0.585059531 0.425315864 1000 29672.25014 1233391.628 -0.483257026 0.53700797 1000 29672.25014 1233391.628 -0.429638987 0.68798732 1000 29672.25014 1233391.628 -0.562537274 0.69506628
Hi,

 

 

If my understanding is not wrong, this workflow would work: 1) Add sequential number to each record (Counter). 2) Based on the number, decide whether the record is the first one (Tester). 3) Only if the record is the first one, store the origin (x, y) read from the record (VariableSetter). 4) Retrieve the current origin (x, y) (VariableRetriever), and then calculate new (x, y) (ExpressionEvaluator or AttributeCreator). 5) Store the new (x, y) as the origin for the next record (VariableSetter).

 

 

Takashi
If you are using FME 2013 SP2, you can also use the "Multiple Feature Attribute Support" functionality of the AttributeCreator.

 

See more information here.

 

 

Takashi
Thank you both!!! Using the variablesetter I got it up and running and now have a directional survey mapper!

Reply