Skip to main content
Solved

Configuring the JSONTemplater

  • October 20, 2023
  • 3 replies
  • 124 views

nedwaterman
Contributor
Forum|alt.badge.img+9

Hi all,

I'm having issues configuring the JSONTemplater to output my data.

I currently have 7 rows, with 2 unique IncidentIDs. I'd like to aggregate the postcode data and geometry for these 2 IncidentIDs so that the json can be used on a webmap showing all the postcodes associated with an incident:

 

imageI've configured my ROOT and SUB templates but the JSONTemplater fails at the root. Can anyone see what I am doing wrong?

imageROOT:

{ "type":"FeatureCollection",

"features":

[

fme-process-features("SUB")

]

}

 

 

SUB:

 

{

    "type":"Feature",

"properties":{"Postcode":fme:get-attribute("POSTCODE")},

    "geometry": {fme:get-json-attribute("_geometry")}

}

 

Thanks in advance

N

Best answer by takashi

Hi @nedwaterman​ ,

The reason for the error in the Root expression is a typo in the function name.

wrong: fme-process-features("SUB")

correct: fme:process-features("SUB")

 

However, if you intend to aggregate Polygons to form a MultiPolygon for each Incident_ID, I don't think JSONTemplater works as expected.

In that case, I think you can create polygon geometry from the "_geometry" attribute value with GeometryRelacer, aggregate the polygons with Aggregator grouping by Incident_ID, then write the features with GeoJSON writer.

 

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.

3 replies

nielsgerrits
VIP
Forum|alt.badge.img+61

With these settings it works for me:

ROOT

{
"type": "FeatureCollection",
"features": [fme:process-features("SUB")]
}

SUB

{
"type": "Feature",
"properties": {
"Postcode": fme:get-attribute("POSTCODE")
},
"geometry": fme:get-attribute("_geometry")
}

 


takashi
Celebrity
  • Best Answer
  • October 22, 2023

Hi @nedwaterman​ ,

The reason for the error in the Root expression is a typo in the function name.

wrong: fme-process-features("SUB")

correct: fme:process-features("SUB")

 

However, if you intend to aggregate Polygons to form a MultiPolygon for each Incident_ID, I don't think JSONTemplater works as expected.

In that case, I think you can create polygon geometry from the "_geometry" attribute value with GeometryRelacer, aggregate the polygons with Aggregator grouping by Incident_ID, then write the features with GeoJSON writer.

 


nedwaterman
Contributor
Forum|alt.badge.img+9
  • Author
  • Contributor
  • October 23, 2023

Hi @nedwaterman​ ,

The reason for the error in the Root expression is a typo in the function name.

wrong: fme-process-features("SUB")

correct: fme:process-features("SUB")

 

However, if you intend to aggregate Polygons to form a MultiPolygon for each Incident_ID, I don't think JSONTemplater works as expected.

In that case, I think you can create polygon geometry from the "_geometry" attribute value with GeometryRelacer, aggregate the polygons with Aggregator grouping by Incident_ID, then write the features with GeoJSON writer.

 

Thanks both for your help - much appreciated!