Skip to main content

Hi have you tried the json templater transformer?


Looks like GeoJSON, so try the GeoJSON writer.


Hi @gefo, looks like it's the GeoJSON format. Does the GeoJSON writer help you?


I did use the GeoJSON writer but the structure is not the same. is there a option in FME to change the structure in a GeoJSON file?


I did use the GeoJSON writer but the structure is not the same. is there a option in FME to change the structure in a GeoJSON file?

If you don't need the properties other than "id", you can remove them in the writer feature type (User Attributes tab).

 


Yes i know i can remove Attributes in the writer, but what i need is the same stucture, first the attributes and at lest the geo information.


Yes i know i can remove Attributes in the writer, but what i need is the same stucture, first the attributes and at lest the geo information.

The objects (type, properties and geometry) are in an unordered list, the order in which they appear in your output should make no difference for practically all use cases.

 

Are you sure this is a problem?

 


I have tried to re-order the original file, and yes its a problem the data wil not load in the webmap, so i need to chance the order. but the question is how can i do that in FME?


the json templater gives you total control on the schema.


I have tried to re-order the original file, and yes its a problem the data wil not load in the webmap, so i need to chance the order. but the question is how can i do that in FME?

If the order of members is critical, you will have to construct a JSON document with the JSONTemplater as Itay mentioned first.

 


I have tried to re-order the original file, and yes its a problem the data wil not load in the webmap, so i need to chance the order. but the question is how can i do that in FME?

Sounds like you should complain to the author of the webmap for not following conventions ;-)

 

But yes, the JsonTemplater is the next step.

 


I have tried to re-order the original file, and yes its a problem the data wil not load in the webmap, so i need to chance the order. but the question is how can i do that in FME?

I've asked our JSON developer for an opinion. As far as I can see, nothing in the GeoJSON spec says it has to be Geometry/Properties in that order, but all the examples they show are in that structure. IF it's known to be permitted, and IF a known web mapping tool insists on that order, then we might be able to implement a setting in FME to switch them around.

 


For so far thanks for all the answers, it seems the webmap did not accept using another order in the geojson file, so i will look if i can change the order with the json templater.

The webmap was created with Qgis and Qgis2Web, you can find it here :

https://www.rijssen-holten.nl/data/publicatie-website/_XA000902014C69DADB9778625A8AF871/index1.html?_dc=1459501106970&_dc=1459501107204#11/52.2866/6.4663

All the data in it comes from a postgisDB so its a litle hard to update it with Qgis, in FME it must be easyer, just read the DB and write it to a JSON file in.


Hi @gefo, if the source point features are read from a PostGIS database, you can convert them to a required JSON document directly with some transformers including the JSONTemplater. e.g.

0684Q00000ArKx8QAF.png

After extracting feature geometry as an attribute (e.g. "_geometry") in GeoJSON format with the GeometryExtractor, send one feature to the Root port of the JSONTemplater and set the Root template:

{
    "type": "FeatureCollection",
    "crs": {
        "type": "name",
        "properties": {
            "name": "urn:ogc:def:crs:OGC:1.3:CRS84"
        }
    },
    "features": fme:process-features("SUB")
}
add a SUB template:
{
    "type": "Feature",
    "properties": {
        "id": fme:get-attribute("id")
    },
    "geometry": fme:get-json-attribute("_geometry")
}
then, send all features to the SUB port.

If there are multiple feature types which should be converted to different JSON documents for each, set feature type identifier attribute to both the "Group By" parameter in the Sampler and the "Group Sub-Features By" parameter in the JSONTemplater


Thanks For the answer i am close to the solution of my problem, the only thing is now how to change the order, it seems the templater does not change the order of the features.


Looks like you are trying to write GeoJSON. However, due to a problem with our GeoJSON writer at the moment, our output has some slight differences, particularly when multiple feature types are written. The workaround for now is to use one feature type per dataset, or use dataset fanout. A more comprehensive solution is planned for 2018.1. For more info see: https://knowledge.safe.com/articles/40806/workarounds-to-known-issues-in-fme-20170.html


Hi @gefo, looks like it's the GeoJSON format. Does the GeoJSON writer help you?

I have a case where the GeoJSON format is not compatible with the output needed (Mapbox GL with each polygon independently colored). I am struggling to figure out how to do JSON Templater or a way to "fix" the GeoJSON output to become compatible.

Goal: output as embedded JSON in a Mapbox html page.


I have a case where the GeoJSON format is not compatible with the output needed (Mapbox GL with each polygon independently colored). I am struggling to figure out how to do JSON Templater or a way to "fix" the GeoJSON output to become compatible.

Goal: output as embedded JSON in a Mapbox html page.

Hi @jnotter,

As this original thread is quite a few years old, would you be open to posting a new question to the Forums? This will increase the visibility of your question and encourage more helpful answers for you from the Community. It would also be helpful to include any screenshots or examples of what you've got currently and what your ideal output would look like. Thanks!


Reply