TERR Expression function to convert binary blob to image for each row in a table ...

Hello,

I have the following scenario:  My data source returns png pictures as a column of long strings (see column vcImage below).

[[{"fid":"132936","view_mode":"default","attributes":{"height":"201","width":"437","class":"media-element file-default"},"fields":{"format":"default","field_file_image_alt_text[und][0][value]":"","field_file_image_title_text[und][0][value]":""},"type":"media"}]]

I would like to use an expression function to add a column with the actual images (string converted to binary).


string2figure <- function(vcImage){
	split = strsplit(vcImage, split = '-')
	split = unlist (split)
	string2figure = as.raw(as.hexmode(split))
	string2figure
}

output <- string2figure(vcImage = input1)

The function type is set to "Column function", the return type is set to "Binary".

I added a calculated column using my expression function: string2figure([vcImage]). 

It works fine, but just for the first row.  How can I get it applied to all rows? If expression functions are not a good way in this scenario, what would be the best path? 

Any help is much appreciated. 

Thanks and best,

Thorsten

2 Comments

Exellent!  Thank you!

thorsten.saeger - Mar 09, 2018 - 1:21pm ::

Use Insert>Caculated Column with the expression

TERR_Binary("output <- I(lapply(strsplit(input1, '-'), function(x)as.raw(as.hexmode(x))))",[vcImage])

and name the new column as you wish.  Displaying the updated data table in a 'Table' visualization should show a plot for each line.

The "I" (capital "i") function must be there for technical reasons - it does make the expression a bit uglier.

 

wdunlap - Mar 09, 2018 - 12:49pm ::
+ Add a Comment

(1) Answer

Login