Skip to main content
Solved

X & Y distance between two points

  • December 9, 2019
  • 5 replies
  • 1528 views

aron
Enthusiast
Forum|alt.badge.img+16

This seems such a simple thing but I can not find a transformer to achieve it.

I want to measure the distance between two points along X and Y. I could of course do this with a LineBuilder, LengthCalculator, a AzimutCalculator and some math. But surely there is a simpler way?

Best answer by bwn

@aron: The triangulation of 2 points is just 1 half of a 2D X,Y rectangle. For a pair of points, and if only interested in the Absolute difference of X and Y: Can use Aggregator, with Group By the common attribute, then BoundsExtractor.

This gives pairs of X values (XMin and XMax) and Y values (YMin and YMax) as Attributes that then is trivial to calculate Absolute Delta X and Delta Y from in an AttributeCreator.

In theory this should be one of the least expensive ways of geoprocessing since no Spatial Indexing and analysis required. Aggregator just literally merges two sets of X and Y coordinates into the one feature record and BoundsExtractor pulls them out into ready-made attributes.

If the Relative X,Y difference is important (ie. Want to know when the change in X and Y is either in the negative or positive direction rather than just the absolute differences) then the other ways suggested are great, with probably another fairly inexpensive solution to use maybe something like InlineQuerier after running CoordinateExtractor so long as there was an Attribute/convention to say which was the Origin Point and which was the Destination Point: Origin Points use in SQL as Table A, and Destination Points in SQL as Table B, and then can directly write calculated expressions in SQL as (A.XCoord-B.XCoord) AS DeltaX etc. It's much the same method as calculating with AttributeCreator but gets rid of the expense of an AttributeRenamer and FeatureJoiner to merge the Destination X,Y Coords onto the Origin X,Y Coords.

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.

5 replies

redgeographics
Celebrity
Forum|alt.badge.img+62

Another option, depending on your requirements, could be a NeighborFinder.

But yeah, there isn't really a simple way. It depends on how the points are coming in. If they're separate point objects, I'd use the NeighborFinder, but you'd have to be sure which points go together. If you have them as sets of x and y attributes simple math in an AttributeCreator is probably best


david_r
Celebrity
  • December 9, 2019

If you only need to measure short-ish distances between two (x,y) coordinates specified in a meaningful ground unit (meters, feet, etc), then you can simply use Pythagoras or whatever to calculate a simple cartesian distance.

But the safest and most correct measurement is certainly the one you'll get by using two VertexCreators (replace with point + add point), a CoordinateSystemSetter followed by a GeographicLengthCalculator.


bwn
Evangelist
Forum|alt.badge.img+26
  • Evangelist
  • Best Answer
  • December 9, 2019

@aron: The triangulation of 2 points is just 1 half of a 2D X,Y rectangle. For a pair of points, and if only interested in the Absolute difference of X and Y: Can use Aggregator, with Group By the common attribute, then BoundsExtractor.

This gives pairs of X values (XMin and XMax) and Y values (YMin and YMax) as Attributes that then is trivial to calculate Absolute Delta X and Delta Y from in an AttributeCreator.

In theory this should be one of the least expensive ways of geoprocessing since no Spatial Indexing and analysis required. Aggregator just literally merges two sets of X and Y coordinates into the one feature record and BoundsExtractor pulls them out into ready-made attributes.

If the Relative X,Y difference is important (ie. Want to know when the change in X and Y is either in the negative or positive direction rather than just the absolute differences) then the other ways suggested are great, with probably another fairly inexpensive solution to use maybe something like InlineQuerier after running CoordinateExtractor so long as there was an Attribute/convention to say which was the Origin Point and which was the Destination Point: Origin Points use in SQL as Table A, and Destination Points in SQL as Table B, and then can directly write calculated expressions in SQL as (A.XCoord-B.XCoord) AS DeltaX etc. It's much the same method as calculating with AttributeCreator but gets rid of the expense of an AttributeRenamer and FeatureJoiner to merge the Destination X,Y Coords onto the Origin X,Y Coords.


aron
Enthusiast
Forum|alt.badge.img+16
  • Author
  • Enthusiast
  • December 9, 2019

If you only need to measure short-ish distances between two (x,y) coordinates specified in a meaningful ground unit (meters, feet, etc), then you can simply use Pythagoras or whatever to calculate a simple cartesian distance.

But the safest and most correct measurement is certainly the one you'll get by using two VertexCreators (replace with point + add point), a CoordinateSystemSetter followed by a GeographicLengthCalculator.

Thanks! Yes, using the fature coordinates and Phytagoras makes sense, but the thing is that the pairs are in a larger dataset and the AttributeCreator does not sort on groups. Is there method to apply the calculations to a selected pair?


david_r
Celebrity
  • December 9, 2019

Thanks! Yes, using the fature coordinates and Phytagoras makes sense, but the thing is that the pairs are in a larger dataset and the AttributeCreator does not sort on groups. Is there method to apply the calculations to a selected pair?

Without knowing anything about your data, my first response would be to use the either the FeatureMerger or the Aggregator to assemble the necessary features to create the start and end points.

If you're reading from an SQL database I would recommend consider using a SORT BY clause in stead, if you have a fair amount of data it's going to be much quicker.