Skip to main content
Solved

Nested structure of GEOJSON

  • October 20, 2021
  • 2 replies
  • 121 views

whkarto
Contributor
Forum|alt.badge.img+14

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 😁 )

Best answer by daveatsafe

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.

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

2 replies

daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • Best Answer
  • November 3, 2021

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.


whkarto
Contributor
Forum|alt.badge.img+14
  • Author
  • Contributor
  • January 18, 2022
daveatsafe wrote:

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.


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