Skip to main content
Question

Creating geojson with JSONtemplater


Hi,

 

I'm currently trying to create geojson with the JSONTemplater to get a txt file at the end of the process. I'm really close to get it but there is something I cannot work around. Here's my final txt file that I have right now :

 

{ "message" : { "sucess" : true, "message" : "La tâche a fonctionné. Vous recevrez un courriel dans les prochaines minutes. Votre numéro d'analyse est le dc82c137-f34a-4fae-806a-af03f2a16cca." }, "geojson" : { "type" : "FeatureCollection", "name" : "transport_hors_norme", "features" : { "type" : "Feature", "geometry" : { "type" : "LineString", "coordinates" : "[-74.25854312432821,46.386997802914244],[-74.25854690900775,46.38701144003504],[-74.2585653228558,46.387067245480985],[-74.25858324562817,46.38711253856072],[-74.25860564958018,46.38716441447192],[-74.25863316909272,46.38721772574174],[-74.2586621220497,46.387263112167304],[-74.25868443781086,46.387296593907124],[-74.25871705708458,46.38733611753558],[-74.25875451356887,46.38737796040637],[-74.25879054029394,46.38741485104289],[-74.25882794110998,46.38744954337804],[-74.25887278469673,46.38748681119428],[-74.25892123510432,46.387523940955084],[-74.25895746648295,46.38755045206047],[-74.25901329979445,46.38758878797128],[-74.25913982910255,46.38767222825822],[-74.25940083981125,46.3878403504997],[-74.25956300930707,46.38794632092807],[-74.2597132822642,46.38804405737224],[-74.25980446456325,46.38810494537259],[-74.25994679007928,46.38820429067078],[-74.26002858477202,46.388264106803646],[-74.26008679540334,46.38830694274102],[-74.26014523548275,46.38835263111074],[-74.26021766973918,46.3884117330616],[-74.26028515283164,46.38846708997433],[-74.2603526337176,46.388528884057855],[-74.2604341089418,46.38860409168643],[-74.26054188160033,46.388710839434644],[-74.26067563832441,46.388845203790986],[-74.26081683667209,46.388988583263824],[-74.26100973596748,46.38918103030566],[-74.26119530714436,46.38936500992952],[-74.26133267533878,46.389499235362806],[-74.26143564486438,46.38959758259815],[-74.26152130044738,46.38967978216387],[-74.26161511338357,46.389767034919096],[-74.26176513598493,46.38990435210414],[-74.26191175292726,46.39003786589748],[-74.26209795259837,46.39020741666241],[-74.26222865896744,46.39032294090129],[-74.26232545284485,46.39040864791902],[-74.26242027077426,46.39049550385481],[-74.26249516825042,46.39056595432294],[-74.26256457168218,46.39063232466387],[-74.26262011213274,46.39069047560172]" }, "properties" : { "rt_item" : 1, "rts_debut" : "001250315209083", "rts_fin" : "001250315209605" } } } }

 

The problem that have is there are " before and after the coordinate, which I'm guessing they are read as string feature. My xquery is this at the moment :

 

{

  "type" : "Feature",

  "geometry" : {

    "type" : "LineString",

    "coordinates" : fme:get-attribute("_coordinates")

    },

    "properties": {

  "rt_item" : fme:get-attribute("rt_item"),

  "rts_debut" : fme:get-attribute("rts_debut"),

  "rts_fin" : fme:get-attribute("rts_fin")

      }  

  }

 

There must be a function to get the coordinate of a line feature in the query, but can't find it. Is there a way to remove the " from the result for the coordinate.

 

Thank you in advance.

 

2 replies

daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • March 3, 2022

Hi @Ian Gagnon-Renaud​,

Before the JSONTemplater, use a GeometryExtractor to extract the geometry as GeoJSON to the attribute '_geometry'.

In the JSONTemplater, change your template to:

{
  "type" : "Feature",
  "geometry" : fme:get-json-attribute("_geometry"),
    "properties": {
  "rt_item" : fme:get-attribute("rt_item"),
  "rts_debut" : fme:get-attribute("rts_debut"),
  "rts_fin" : fme:get-attribute("rts_fin")
      }  
}

The fme:get-json-attribute("_geometry") will paste the GeoJSON geometry in without adding any quotes.

 

You could also use a FeatureWriter to write the features out to a temporary GeoJSON file, then read it back into an attribute with the AttributeFileReader, before sending to the Textline writer.


  • Author
  • March 4, 2022

Thank you, the geometry extractor work great!


Reply


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