Solved

Exposing attributes attributes dinamically


Hello I've been trying to work with some COVID data from my state in Brazil.

Every day the state health department releases a CSV with the data like this

where we have a feature for every city and every day with the number from covid( deaths, confirmed cases and recovery cases)

I want to create 3 shape file for each situation where the first collum is the city name and all other collumns are the dates, just like these:

 

I was able to do it with AttributeCreator and Exposer but as time goes bye the health department updates the begining of the dates from the CSV( in this example the least date is 23 feb, but now the first day is 04 jan).

I know i can use the exposer with all the days of the year but i was trying to create only the necessary collumns of date.

I saw this post (https://knowledge.safe.com/questions/21304/get-the-attributes-names-with-python.html) but how can i use this to create the correct "schema" for my shapefiles??

 

icon

Best answer by todd_davis 26 June 2020, 04:20

View original

4 replies

Userlevel 1
Badge +12

covid.fmwtThis is not something I would pass out at this standard usually, as it can certainly be better than this (more dynamic and more efficient). But It should do the job for you. It builds the the schema as a lists and uses that to define the outputs, and so new days will add as new columns.

You will no doubt want to merge existing geometries to this, as I have just set the outputs as null geometry.

Cheers,

Todd

Userlevel 4
Badge +25

The AttributePivoter should be what you need, but it crashes for me when I try to group-by Date on the columns. Apologies. I filed a case with the developers so it shouldn't happen in the future, but for now I suggest using Todd's solution.

Thanks for your help, this is gonna be really helpfull, but after checking your workspace i have some questions:

 

1 - you created a list called attribute with "name" and "data type". Why we can't see the correct schema in fme inspector but the shp goes out with the desired schema??

2 - I couldn't understand why u put the source of city to enter the listbuilder so i used another feature merger with the shp of cities to fix it.

 

 

thanks again for your support @todd_davis

Userlevel 1
Badge +12

Thanks for your help, this is gonna be really helpfull, but after checking your workspace i have some questions:

 

1 - you created a list called attribute with "name" and "data type". Why we can't see the correct schema in fme inspector but the shp goes out with the desired schema??

2 - I couldn't understand why u put the source of city to enter the listbuilder so i used another feature merger with the shp of cities to fix it.

 

 

thanks again for your support @todd_davis

Hi,

Not sure about 2, but for 1.

The list with attribute{}.name and attribute{}.fme_data_type are designed to set the schema on the output. They don't create a schema within the actual workspace. Therefore you can create dynamic schemas that are created by the data going into the workspace and not defined by the workspace itself (if that makes sense).

Cheers,

Todd

Reply