Skip to main content

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" : "q-74.25854312432821,46.386997802914244],2-74.25854690900775,46.38701144003504],5-74.2585653228558,46.387067245480985],9-74.25858324562817,46.38711253856072],0-74.25860564958018,46.38716441447192],1-74.25863316909272,46.38721772574174],1-74.2586621220497,46.387263112167304],3-74.25868443781086,46.387296593907124],1-74.25871705708458,46.38733611753558],5-74.25875451356887,46.38737796040637],6-74.25879054029394,46.38741485104289],2-74.25882794110998,46.38744954337804],8-74.25887278469673,46.38748681119428],4-74.25892123510432,46.387523940955084],0-74.25895746648295,46.38755045206047],0-74.25901329979445,46.38758878797128],1-74.25913982910255,46.38767222825822],8-74.25940083981125,46.3878403504997],9-74.25956300930707,46.38794632092807],8-74.2597132822642,46.38804405737224],2-74.25980446456325,46.38810494537259],2-74.25994679007928,46.38820429067078],0-74.26002858477202,46.388264106803646],6-74.26008679540334,46.38830694274102],1-74.26014523548275,46.38835263111074],0-74.26021766973918,46.3884117330616],6-74.26028515283164,46.38846708997433],4-74.2603526337176,46.388528884057855],8-74.2604341089418,46.38860409168643],6-74.26054188160033,46.388710839434644],6-74.26067563832441,46.388845203790986],9-74.26081683667209,46.388988583263824],8-74.26100973596748,46.38918103030566],5-74.26119530714436,46.38936500992952],9-74.26133267533878,46.389499235362806],8-74.26143564486438,46.38959758259815],8-74.26152130044738,46.38967978216387],3-74.26161511338357,46.389767034919096],0-74.26176513598493,46.38990435210414],4-74.26191175292726,46.39003786589748],7-74.26209795259837,46.39020741666241],2-74.26222865896744,46.39032294090129],1-74.26232545284485,46.39040864791902],9-74.26242027077426,46.39049550385481],4-74.26249516825042,46.39056595432294],2-74.26256457168218,46.39063232466387],3-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.

 

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.


Thank you, the geometry extractor work great!


Reply