Solved

JSON Polyline Creation

  • 16 October 2017
  • 3 replies
  • 6 views

First, I apologize if this is very basic, but I can't seem to find out how to make this work. Additionally, I'm very new to FME so I'm learning as I'm going. This data is about a bike sharing program.

I have two CSVs, one contains the station IDs with Lat / Long, the other contains the trip information. Here are some of the columns (I've removed all the others for this question)

Station File:

station_id latitude longitude

 

Trip File:

trip_id from_station_id to_station_id

What I would like to go is add them to a (Geo?)JSON file, so each TRIP_ID contains a polyline geometry of the FROM and TO locations.

How would I got about doing this?

icon

Best answer by daveatsafe 16 October 2017, 19:13

View original

3 replies

Userlevel 2
Badge +17

Hi @misterpoints,

This is definitely a case for the FeatureMerger transformer. This transformer will let you merge the locations from the stations file to the from/to stations in the trips file. You can then use a LineCombiner to combine the trip segments into a single line.

 

Two FeatureMergers are used in a row - one for the from points and one for the to points. You can set a different prefix in each merger to prevent overwriting the attributes.

The VertexCreators are used to turn the from/to location attributes into a line geometry.

Set the Group By in the LineCombiner to trip_id to create separate lines for each trip.

I have attached the workspace for you: csv2triplines.fmw.

Userlevel 2
Badge +17

Hi @misterpoints,

This is definitely a case for the FeatureMerger transformer. This transformer will let you merge the locations from the stations file to the from/to stations in the trips file. You can then use a LineCombiner to combine the trip segments into a single line.

 

Two FeatureMergers are used in a row - one for the from points and one for the to points. You can set a different prefix in each merger to prevent overwriting the attributes.

The VertexCreators are used to turn the from/to location attributes into a line geometry.

Set the Group By in the LineCombiner to trip_id to create separate lines for each trip.

I have attached the workspace for you: csv2triplines.fmw.

I'm afraid that a single trip (a pair of from_station_id and to_station_id) contains two or more line segments. e.g.

 

station_idlatitudelongitude12345trip_idfrom_station_idto_station_id115

 

@misterpoints, could you please share a sample dataset with us?

 

Hi @misterpoints,

This is definitely a case for the FeatureMerger transformer. This transformer will let you merge the locations from the stations file to the from/to stations in the trips file. You can then use a LineCombiner to combine the trip segments into a single line.

 

Two FeatureMergers are used in a row - one for the from points and one for the to points. You can set a different prefix in each merger to prevent overwriting the attributes.

The VertexCreators are used to turn the from/to location attributes into a line geometry.

Set the Group By in the LineCombiner to trip_id to create separate lines for each trip.

I have attached the workspace for you: csv2triplines.fmw.

Wow thank you very much for your help, I didn't expect that much. I'm happy to see I was on the right path with my workflow, but I left out a second feature merger and I was using a wrong line transformer.

I got the output I wanted. If I use your model and connect up the Line Combiner to a reject and "accept" writer, it rejects 2000 of them, why I'm not sure, but that's not important at this point.

Now, I just have to put this file to use. Thank you very much.

Reply