Question

Creating dynamic attributes per "fme_basename"


Badge
Hi guys!

 

 

I'm finding it quite difficult to figure out how to dynamically produce attributes per my "fme_basename". So let me explain what I have, and what I want.

 

 

My source is a folder with multiple undetermined shape files in. My output is a .xls file that simply lists the attributes present for each shapefile within my source. So in other words, my writer fans out by "fme_basename". Everything works fine, but instead of each shapefile being represented by a new tab, I'd like for them all to be on one page, in other words, an attribute created for each shapefile found. The intent of the entire workspace is just to summarise all shapefiles for the user, so that they can ensure all fields that should be present are, for each shape file.

 

 

So what I have is:

 

 

"ATTRIBUTES" (The field I created that lists all present fields)

 

Type

 

Name

 

level

 

etc

 

[Roadnetwork] (This is the tab in the xls)

 

 

This is present for each tab generated, where each tab is named accodring to the shape file, such as Roadnetwork.shp, Landuse.shp, or WaterArea.shp

 

 

What I want:

 

 

Roadnetwork      Landuse    WaterArea

 

Type                       Type            Type

 

Name                    Code           Name

 

level                       Hight           Depth

 

etc...

 

[Workspace]

 

 

So in short, I wont what is now represented by tabs to become attributes instead. However, keep in mind, the source will always be a folder, and the shape files inside can be anything. Do it need to be purely dynamic.

 

 

Thanks in advance, especially for enduring my crude graphical representation above :)

12 replies

Badge +3
Hi,

 

 

You can use a fiel/directory reader set to the directory of the shape file names.

 

Use substringsearcher (0,-5) to remove the .shp extension from path_filename.

 

 

You can use a schemareader (any format) dynamicaly  read the schema for eacht shapefile. Expose fme_feature_type. Expose attribute{0}.name

 

 

Use featuremerger to merge on path_filename and result of substringsearch.

 

Sorter by path_filename.
Badge +3
Hi,

 

 

Sorry, you should merge on result of substringsearch and fme_basename.

 

 

Exposure of fme_feature_type is not nescesary.

 

 

Badge
Hi Gio,

 

 

I have already accomplished what your suggestion does in a very similair fashion. In essence, I already have the output I want, including the retrieval of the shapefile names and all that.

 

 

The thing I'm struggling with is to create a new attribute for each shape file as opposed to creating a new tab for each (via the Fan out option in the writer), which I've already succesfully done.

 

 

I really just want to switch to having a single tab xls output, with each shapefile having it's own column in this tab, as opposed to each shapefile having it's own tab.

 

 

Does that make any sense?
Badge +3
Hi Robbie B.,

 

 

You can create attributes dynamicaly, but you cannot expose them dynamicaly.

 

 

You need to use python or tcl to create the schema needed to write the excel.

 

This involves a workspacecaller.

 

 

In this case 1 workspace would do what id did (and you already did) then use python to create schema. When this is done a workspacecaller to call the one that eventually builds (in your case) the excel with filenames as attributes and original file-attributes as its value.

 

 

There are couple of examples to do this the knowledge base and this forum. Takashi has example python script in his space or on his blog.
Badge
Ok, thanks a lot for the answer!
Badge
Hi

 

My initial suggestion is to use the Schema Format Reader to read each of the Shape files in turn. That should produce attributes that define the attribute schema and which you can write out as records to an Excel spreadsheet.

 

 

The only tricky part is how you handle the fact that some datasets may have (for example) four attributes while others have five. I think you'll just have to hard code a maximum number of attributes where some will end up being empty records.

 

 

Hope this helps

 

 

Mark

 

 

Mark Ireland

 

Product Evangelist

 

Safe Software Inc
Badge +3
Hi,

 

 

I managed to make a workspace that writes it to a csv (wich u can import in excel with exceltool)

 

 

 

 

IT produces

 

 

 

U could use a workspace combo to prevent having to manualy import it in excel of course.

 

 

 

This can also be done with dynamically created attributes btw.

 

Badge
Thanks so much Gio, I'll give it a go and see if I can get it to work!
Badge +3
Me again...

 

 

the first line in the csv pic based on the data i used is the shapefiles it found in the directory (path/filereader).

 

The group by in the 2 listbuilders take care of separating these to 1 line for shapefilenames and rest for their schemas (schemareader). Ordering is inherit to this workspace.

 

The readers are the same as my first post. (i just used a directory with more diverse shapefiles)
Badge +3
Badge +3
Hi,

 

 

To complete the proces...

 

 

Run the script once.

 

Then create a csv to xlsx writer. When done save this as a workspace.

 

 

Add following bit to previous workspace, in place of the csv writer.

 

 

 

The workspacerunner calls the csv to xlsx writer.

 

 

Remove the previously created workspaces and run this.

 

(it will create the csv and subsequently the excellfile).

 

 

If u would call this again trough another workspacerunner, u would finally have actual attributes (without having to manually expose anything)
Badge +3
btw

 

if u run it on a different directory, u must change output names (in filewriter and workspacerunner), else it will be limited to nr. of shapefiles of the first directory u read.

 

Reply