Question

How to remove gaps in lines created from lists of coordinates

  • 16 February 2017
  • 7 replies
  • 17 views

Badge

Hello, this problem probably has a very simple solution but I'm struggling to come up with anything!

My input is a large number of CSV files where each CSV contains a list of coordinates that form a route.

Within each route, there are different travel modes which each need to be represented by a separate line. The travel mode for a segment within a route is identified by an attribute in the input CSV.

To create the lines, I am using a PointConnector transformer, using both the 'route ID' and 'travel mode' attributes as the Connection Break Attributes.

If we joined the the list of coordinates for a route all together, they would form a continuous line, but because we are breaking the routes up by travel mode, the output segments have gaps between them where their ends should meet.

actual result:

desired result:

The gaps are occurring because the start coordinates of one travel mode segment, are also the end coordinates of the previous segment:

If anyone has ideas about how to fix this it'd be much appreciated. Have tried the snapper without much success. There are almost 2000 input files so it's not practical to manually duplicate rows in the data.


7 replies

Badge +7

Hi @katiem

I suggest to take a look at the Neighborfinder. It allows you to find a 'neighbor' withing a certain search radius. It also returns the coordinates of the point it snapped to allowing you to create the link.

https://docs.safe.com/fme/2017.0/html/FME_Desktop_Documentation/FME_Transformers/Transformers/neighborfinder.htm

Userlevel 5
Badge +25

The NeighborFinder that @jeroenstiers suggests will leave the original geometries intact. Depending on the size of the gaps it might be better to use the Snapper instead (although this will, subtly, alter the geometry)

Userlevel 2
Badge +16

I would use the AnchoredSnapper as I assume the bus stop to be accurate. Snap the walk to the bus stop by using the bus stops as Anchor and the walks as Candidate.

Badge +16

Hi @katiem,

You can do that via the AnchoredSnapper and joining the lines to form a longer one.

Hope this helps.

Badge

Thanks for the replies all, I've tried the AnchoredSnapper and that seems to work reasonably well for most of the data.

However, I've discovered that there are some features where the middle section only has one row for the segment, so no line is created for that segment (because it only has one set of coordinates, when in reality the start coordinates of the segment are the last set of coordinates from the previous 'walk' segment). I think ideally I need to find a way to append the last set of coordinates from the previous segment as the first set of coordinates on the next segment....

Userlevel 2
Badge +16

If you are looking to use the X and Y coordinates of the previous line this can help:

The AttributeCreator transformer has the advanced option to take attributes from the previous feature.

You can use those to create line segments.

Badge

Unfortunately I don't think that would work - we only want to do it with specific rows, not all. E.g. for the bus segment, we need to add an additional row, which contains the coordinates of the first row of the walking segment. I now have nearly 4000 files to process so I think the snapping method gives the easiest solution for now.

Reply