Skip to main content
Solved

Converting JSON nested point coordinates to lines

  • December 13, 2023
  • 4 replies
  • 104 views

mzondervan
Contributor

I'm using the HTTPCaller to read in an MDS data feed that I would like to convert to an AGOL line feature by connecting the points together from the "route" attribute. I'm able to extract the attributes for each trip in the dataset using the JSON Fragmenter and JSON Extractor, but I'm getting stuck on creating the geometry. How can I take each point coordinate from a trip and connect them into a line and keep the trip attributes associated with it? Example of the JSON format is attached.

 

Best answer by takashi

Hi @mzondervan ,

Alternatively, you can read every Feature object as GeoJSON features directly with JSONFragmenter, since the "route" object is a GeoJSON document.

  • JSON Query: json["data"]["trips"][*]["route"]
  • Fragment as Format: GEOJSON

jsonfragmenter-parameters

View original
Did this help you find an answer to your question?

4 replies

ctredinnick
Supporter
Forum|alt.badge.img+18
  • Supporter
  • December 14, 2023

imageBecause there could be multiple trips, and you need attributes from the top level and also from each point, it's an awkward series of json transformers.

 

JSONFragmenter by json["data"]["trips"][*]

Then JSONExtractor to extract the route and device with json["route"] and json["device_id"]. Perhaps remove the original json attribute at this point if it's going to be too large.

Then fragment that route into point parts with json["features"][*]

Then JSONExtractor the attributes for each point json["geometry"]["coordinates"][0] and json["geometry"]["coordinates"][1] and json["properties"]["timestamp"]. If you don't need the time you can ignore that.

Then VertexCreator, and lastly a LineBuilder, grouping by the device_id


takashi
Influencer
  • Best Answer
  • December 14, 2023

Hi @mzondervan ,

Alternatively, you can read every Feature object as GeoJSON features directly with JSONFragmenter, since the "route" object is a GeoJSON document.

  • JSON Query: json["data"]["trips"][*]["route"]
  • Fragment as Format: GEOJSON

jsonfragmenter-parameters


ctredinnick
Supporter
Forum|alt.badge.img+18
  • Supporter
  • December 14, 2023
takashi wrote:

Hi @mzondervan ,

Alternatively, you can read every Feature object as GeoJSON features directly with JSONFragmenter, since the "route" object is a GeoJSON document.

  • JSON Query: json["data"]["trips"][*]["route"]
  • Fragment as Format: GEOJSON

jsonfragmenter-parameters

Aha, fragment as format GeoJSON. I didn't know that was an option, thanks!


mzondervan
Contributor
  • Author
  • Contributor
  • December 14, 2023
takashi wrote:

Hi @mzondervan ,

Alternatively, you can read every Feature object as GeoJSON features directly with JSONFragmenter, since the "route" object is a GeoJSON document.

  • JSON Query: json["data"]["trips"][*]["route"]
  • Fragment as Format: GEOJSON

jsonfragmenter-parameters

Thank you @takashi, this works perfectly.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings