Question

Creating attribute values from variable "fme_basename" strings

  • 10 February 2015
  • 2 replies
  • 7 views

Hi everyone,

 

 

Fairly new to FME and having some problems trying to get what I want.

 

 

Trying to create polygons from raster extents using the RasterExtentsCoercer tool. I also need to write variable attributes into the resulting shapefile depending on the basename. i.e. the raster files are in a very specific naming convension "mmm_sss_ttt_pp_yyyymmddthhmmss_oooooo_dddddd_nnn.eee". Each part of the string relates to key information that needs to be included in the shapefile. How do I extract this and get it to write to each of the attribute columns?

 

 

e.g.

 

SWATH = sss

 

PRODUCT_TY = ttt

 

POLAR = pp

 

DATE = yyyymmdd

 

TIME = hhmmss

 

etc.

 

 

I've done this kind of string extraction work before in excel but never in FME so any suggestions would be greatly appreciated.

 

 

Many Thanks in advance!

2 replies

Badge +3
If the naming convention is always the same pattern.

 

 

You can either use regexp in a creator or use a stringsearcher with regexp.

 

A simple regexp like

 

(\\w{3})_(\\w{3})_(\\w{3})_(\\w{2})_(\\w{15})_(\\w{6})_(\\w{6})_([\\w\\.]+)

 

If you use stringsearcher you then have to expose _matched_parts{0} to {7} for all 8 captures and then rename them. Probalby want to reformat the datestring too. (there is a DateFormatter transformer)

 

 

Or a seriesSubstringExtractors.
Userlevel 2
Badge +17
Hi,

 

 

It's also possible to use the AttributeSplitter first, but I agree that the StringSearcher would be a good solution.

 

 

In addition, since regular expression is very flexible, there can be many variations depending on the format specification and/or your requirement.

 

e.g.

 

You can modify the expression, so that it will split date and time simultaneously:

 

(\\w{3})_(\\w{3})_(\\w{3})_(\\w{2})_(\\w{8})t(\\w{6})_(\\w{6})_(\\w{6})_([\\w\\.]+)

 

If you need to split the final part into "nnn" and "eee", "([\\w\\.]+)" can be replaced with "(\\w{3})\\.(\\w{3})".

 

If a part may contain some symbol such as brackets, you can use "." (dot: any character) instead of "\\w" (alnum: alphabet character, digit or under score).

 

and so on.

 

 

Takashi

Reply