Skip to main content
Solved

From Feature list to FeatureWriter


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

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

8 replies

takashi
Evangelist
  • 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
jacquint wrote:

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
Evangelist
  • April 3, 2018
jacquint wrote:

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
Evangelist
  • April 3, 2018
jacquint wrote:

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
jacquint wrote:

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

 


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