Skip to main content
Question

I would like to change the results of a GeoJSON writer.

  • June 11, 2021
  • 5 replies
  • 42 views

Hi,

I would like to change the results of a GeoJSON writer when there's no attributes that pass my transformers. For example, when I got what its like in the left picture, I got a reply from my GeoJSON writer like so : {

"type" : "FeatureCollection",

"name" : "aspvhn_Strct_sur",

"features" : [

{

"type" : "Feature",

"geometry" : {

"type" : "Point",

"coordinates" : [ -73.8119918787, 45.6095554592 ]

},

"properties" : {

"idstruct" : null,

"producteur" : "MTQ"

}

}.

But, when its like the right picture, I got nothing from the GeoJSON writer. What I want is that when I got no attribute that pass my transformers, i'll still have an answer that looks like what you see as above but with space instead of nothing at all. Thanks.

5 replies

david_r
Celebrity
  • 8392 replies
  • June 11, 2021

Just before your writer, insert a NoFeaturesTester. Send the OUTPUT port to the GeoJSON writer. Then send the NOINPUT feature to a Text File writer with the same name as the GeoJSON output. You may want to introduce the attribute "text_line_data" with a space first.

 


Thanks David, it seems like it worked out.


I might have another problem. What I want now is that when there's no attribute that pass my transformers, I want this in my GeoJSON writer :

[]

and nothing else. I don't know if it is possible tho. @david_r​ 

Thanks for the answer.


david_r
Celebrity
  • 8392 replies
  • June 14, 2021

I might have another problem. What I want now is that when there's no attribute that pass my transformers, I want this in my GeoJSON writer :

[]

and nothing else. I don't know if it is possible tho. @david_r​ 

Thanks for the answer.

Simply set text_line_data to "[]" rather than a space.


I'll make another exemple for you. If aspvhn_traversier has attribute in his transformers, the GeoJSON writer will write : {

"type" : "FeatureCollection",

"name" : "aspvhn_traversier",

"features" : [

{

"type" : "Feature",

"geometry" : {

"type" : "Point",

"coordinates" : [ -69.726550367, 48.1395144222 ]

},

"properties" : {

"Traverse" : "Point_traversier",

"gaodoreclg" : "Baie-Sainte-Catherine/Tadoussac"

}

}

But, if aspvhn_municipalite has no attributes, I just want to have this :

[].

I don't want this :

{

"type" : "FeatureCollection",

"name" : "aspvhn_entraves",

"features" : []

}

I hope i'm being more clear. Once again, thanks David.