Solved

Nested structure of GEOJSON

  • 20 October 2021
  • 2 replies
  • 35 views

Badge +11

Hi,

 

I'm trying to figure out how to write nested attribute structure to a GEOJSON file. For that reason I've prepared some sample data for a Quick Translation to see how FME would set up the writer feature type properly. But surprisingly, my nested structure is lost during that translation! So in fact my test endet up in two questions instead of delivering a solution:

1.) Why does the Quick Translation fail

2.) How do I set up the GEOJSON Writer properly to build the desired nested structure.

2.1) In case JSONTemplater is the solution to this task, how do I have to set it up properly? I spent some time playing around but never came up with some suiteable result, especially for proper GEOJSON (geometry handling, type defintion and so on).

 

Find attached my sample file. Looking forward to any suggestions (and maybe solutions 😁 )

icon

Best answer by daveatsafe 4 November 2021, 00:12

View original

2 replies

Userlevel 2
Badge +17

Hi @whkarto​,

The Quick Translator will set the output schema to match the input, but the TOPOLOGIE array is converted to a list on reading, and the GeoJSON writer cannot write list attributes, so it does not come through on the conversion.

In order to retain the TOPOLOGIE structure, we need to explode the list and rebuild the JSON structure in a JSONTemplater. Then we can write the TOPOLOGIE structure as a json type attribute on the output feature. This is fairly simple, since we only need to create the TOPOLOGIE structure in the templater, not the entire GeoJSON feature.

We will also need to set the GeoJSON writer File Structure parameter to Object with feature type names as keys, to match your source file.

 

Screen Shot 2021-11-03 at 4.09.09 PMI am attaching a workspace that will successfully roundtrip your sample file.

Badge +11

Hi @whkarto​,

The Quick Translator will set the output schema to match the input, but the TOPOLOGIE array is converted to a list on reading, and the GeoJSON writer cannot write list attributes, so it does not come through on the conversion.

In order to retain the TOPOLOGIE structure, we need to explode the list and rebuild the JSON structure in a JSONTemplater. Then we can write the TOPOLOGIE structure as a json type attribute on the output feature. This is fairly simple, since we only need to create the TOPOLOGIE structure in the templater, not the entire GeoJSON feature.

We will also need to set the GeoJSON writer File Structure parameter to Object with feature type names as keys, to match your source file.

 

Screen Shot 2021-11-03 at 4.09.09 PMI am attaching a workspace that will successfully roundtrip your sample file.

Sorry for my late answer, I managed to solve the problem via the JSON Templater. Fore sure this is the prefered solution but it is still somehow strange to me that I can't loop this dataset through FME doing a Quick Translation. Especially as the list created by FME JSON Reader does include both attributes and nested structure.

Reply