Skip to main content
Best Answer

From Feature list to FeatureWriter

  • April 3, 2018
  • 8 replies
  • 30 views

Forum|alt.badge.img

Hello,

I have a Feature and I am using a FeatureWriter to output a final GeoJson, until there everything is working fine when it's about direct attribute.

How about automatically looping a nested list, to get a list of one specific attribute and attach it to my FeatureWriter as a json property (an array) and keeping in the mean time the already well defined relation between the main object and it's list 

Basically I want this attribute "classification" (see the screenshot attached), to be output at the end as a json property of a type array using a FeatureWriter Geojson.

Bellow the final output expected, of course without building the GeoJson by myself but letting the FeatureWriter (GeoJson) to do the job:

{
"type" : "FeatureCollection",
"name" : "SomeName",
"features" : [
{
"type" : "Feature",
"geometry" : {
"type" : "GeometryCollection",
"geometries" : null
},
"properties" : {
"someProperty" : "someValue",
"classification": ["value1", "value2"]
}
},
{
"type" : "Feature",
"geometry" : {
"type" : "GeometryCollection",
"geometries" : null
},
"properties" : {
"someProperty" : "someValue",
"classification": ["value1", "value2"]
}
}
]
}

Best answer by takashi

Hi @jacquint, if you have created already the list "class{}.AirspaceLayerClass.classification" that stores the values, you can convert it to a JSON array with the JSONTemplater and write it to the destination GeoJSON dataset as a 'json' type attribute.

Template Expression in JSONTemplater [Updated]:

[
    fme:get-list-attribute("class{}.AirspaceLayerClass.classification")
]

0684Q00000ArJnfQAF.png

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

8 replies

takashi
Celebrity
  • Best Answer
  • April 3, 2018

Hi @jacquint, if you have created already the list "class{}.AirspaceLayerClass.classification" that stores the values, you can convert it to a JSON array with the JSONTemplater and write it to the destination GeoJSON dataset as a 'json' type attribute.

Template Expression in JSONTemplater [Updated]:

[
    fme:get-list-attribute("class{}.AirspaceLayerClass.classification")
]

0684Q00000ArJnfQAF.png


Forum|alt.badge.img
  • Author
  • April 3, 2018

Thank you very much @takashi it works perfectly !


Forum|alt.badge.img
  • Author
  • April 3, 2018

Hi !

Actually I talk too fast probably :)

It's working but now I have duplicated feature in the output. Any idea?

Thank you.


gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • April 3, 2018

Hi !

Actually I talk too fast probably :)

It's working but now I have duplicated feature in the output. Any idea?

Thank you.

duplicate sets in the input probably.

 

Like features with multi classifications can lead to this.

 

 


takashi
Celebrity
  • April 3, 2018

Hi !

Actually I talk too fast probably :)

It's working but now I have duplicated feature in the output. Any idea?

Thank you.

The JSONTemplater won't duplicate features. To find where the features would duplicate, consider run the workspace with Full Inspection mode (Workbench menu Run > Run with Full Inspection).

 


Forum|alt.badge.img
  • Author
  • April 3, 2018

Yes a feature can have multiple classifications that's why I want in the same level of the feature in the GeoJson output to have a classification array.

The way I am doing it is probably not the right one, see the screenshot attached: screen-shot-2018-04-03-at-71447-pm.png

The JSONTemplater is here only to handle the templating of the classification's array see screenshot:

screen-shot-2018-04-03-at-72144-pm.png

then each array must be merged back in to the feature where it belongs by the FeatureWriter right? see screenshot: screen-shot-2018-04-03-at-72425-pm.png

Thank you very much in advance !


takashi
Celebrity
  • April 3, 2018

Yes a feature can have multiple classifications that's why I want in the same level of the feature in the GeoJson output to have a classification array.

The way I am doing it is probably not the right one, see the screenshot attached: screen-shot-2018-04-03-at-71447-pm.png

The JSONTemplater is here only to handle the templating of the classification's array see screenshot:

screen-shot-2018-04-03-at-72144-pm.png

then each array must be merged back in to the feature where it belongs by the FeatureWriter right? see screenshot: screen-shot-2018-04-03-at-72425-pm.png

Thank you very much in advance !

In your workflow, the two data flows from the AttributeManager and the JSONTemplter will join into a singel flow, but features won't be merged. It's the reason why the features have been duplicated. If you need to merge the features, consider using the FeatureMerger.

 

However, the JSONTempleter preserves all attributes of the input feature, so it's not essential to merge back the resulting feature to the original feature. I think you can just remove the connection between the AttributeManager and the AttributeRenamer.

 

 

 


Forum|alt.badge.img
  • Author
  • April 4, 2018

Yes a feature can have multiple classifications that's why I want in the same level of the feature in the GeoJson output to have a classification array.

The way I am doing it is probably not the right one, see the screenshot attached: screen-shot-2018-04-03-at-71447-pm.png

The JSONTemplater is here only to handle the templating of the classification's array see screenshot:

screen-shot-2018-04-03-at-72144-pm.png

then each array must be merged back in to the feature where it belongs by the FeatureWriter right? see screenshot: screen-shot-2018-04-03-at-72425-pm.png

Thank you very much in advance !

Thank you very much @takashi

 

 

It's workign as expected. I didn't know that the JSONTemplater preserved the other non