I use the next tcl script for a similar problem.
The only difference is that I promote the list data to regular 
attributes. The proc has two modes: if the parameter CONCAT is 0, 
then if the value of "fieldname" occurs more than once, it creates 
attributes appendend with an index. If CONCAT is another character 
(or string), it creates the attribute only once, but all the values 
are concatenated with the CONCAT character.

so: 
    somelist{0}.fieldname = 'kind'
    somelist{0}.fieldvalue = 'paved'
    somelist{1}.fieldname = 'kind'
    somelist{1}.fieldvalue = 'other'

list2attr 0 : will give attributes kind='paved'
                                   kind1='other'
list2attr | : will give one attribute: kind='paved|other|'

This proc can easily be adjusted to output a list in stead of regular 
attributes.

Harm Olthof

============
catch {file delete "D:/tmp/fieldname2attributes.log"}
  
proc list2attr {CONCAT {DEBUG 0}} {
  global FME_Attributes
  set teller 0
  
 if {$DEBUG} {
     set F [open "D:/tmp/fieldname2attributes.txt" a+]
     puts $F "[array names FME_Attributes *]\n\n"
 }
 
 foreach {fieldname} [array names FME_Attributes 
somelist\{*\}.fieldname] {
    if {$DEBUG} {puts $F "fieldname: $fieldname : $FME_Attributes
($fieldname)"}
    if [regsub  {(somelist\{)(\d*)(\}.fieldname)} $fieldname "\\2" 
idx] {
     if {$DEBUG} {
         puts $F "idx : $idx $fieldname $FME_Attributes(somelist
{$idx}.fieldvalue)"
         puts $F "$FME_Attributes($fieldname) $FME_Attributes(somelist
{$idx}.fieldvalue)"
     }
     if {[FME_AttributeExists $FME_Attributes($fieldname)]} {
        if {$DEBUG} {puts $F "fieldname bestaat al($FME_Attributes
($fieldname)): [FME_AttributeExists $FME_Attributes($fieldname)] : 
$FME_Attributes($FME_Attributes($fieldname))"}
        if {$DEBUG} {puts $F "attr: [array names FME_Attributes 
$FME_Attributes($fieldname)]"}

        if {$CONCAT==0} {
            set newidx 1
            foreach i [array names FME_Attributes ${fieldname}*] {
                regsub "($fieldname)(\d*)" $i "\\2" volgnr
                if {[string is digit $volgnr]} {
                    if {$volgnr>$newidx} {set newidx $volgnr}
                }
             incr newidx
            }
            FME_SetAttribute "$FME_Attributes($fieldname)
${newidx}" "$FME_Attributes(somelist{$idx}.fieldvalue)"
         } {
            FME_SetAttribute $FME_Attributes
($fieldname) "$FME_Attributes($FME_Attributes($fieldname))${CONCAT}
$FME_Attributes(somelist{$idx}.fieldvalue)"
         }
         
     } { 
         FME_SetAttribute $FME_Attributes($fieldname) "$FME_Attributes
(somelist{$idx}.fieldvalue)"
     }
    } { # no error catching, just return something
      return -1
    }
 }
 


--- In [email protected], "Dale Lutz" <[EMAIL PROTECTED]> wrote:
>
> This is an interesting problem.
> 
> Jason's solution is the way to do it inside of a workspace without 
dipping into the world of TCL.
> 
> If there was a large amount of data, then I'd suggest exploring 
writing a Tcl proc that did this and calling it with the Tclcaller.  
The proc would look something like the Tcl that the 
ListDuplicateRemover uses, only it would be simpler, in that it would 
loop over all the elements of the list, and for each one, it would 
just do a:
> 
>       set attrName $FME_Attributes(...name of list attribute 
holding fieldname)
> 
>       set attrVal $FME_Attributes(...name of list attribute holding 
value)  
>       set FME_Attributes($attrName) $attrVal
> 
> I know I'm being sketchy here but hopefully this is enough to get 
someone going. Again, only necessary if the data volumes are a bit 
large, as the non-Tcl approach ends up using some "blocking" 
transformers that will need to pile up all the data, whereas a Tcl 
approach can deal with each feature as it goes by...
> 
> 
>  
> Dale
>  
> --------------------------------------------------------------------
--
> Dale Lutz              Safe Software Inc.                 [EMAIL PROTECTED]
> VP Development         Surrey, BC, CANADA        phone: (604) 501-
9985
>                        http://www.safe.com         fax: (604) 501-
9965
> --------------------------------------------------------------------
--
>  
> 
> > -----Original Message-----
> > From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf 
Of Jason
> > Birch
> > Sent: Tuesday, November 22, 2005 4:20 PM
> > To: [email protected]
> > Subject: RE: [fme] List format
> > 
> > In that example, I'd probably want to see the following as a 
result rather
> > than a list:
> > 
> > length = 7.3
> > kind = 'paved'
> > lanes = 2
> > 
> > Anyway...
> > 
> > I would approach this as follows:
> > 
> > - Counter to create unique attribute for each record
> > - Split the datastream (One to AttributeRemover, one to 
ListRemover)
> > - Stream 1 (AttributeRemover)
> >   - AttributeRemover (get rid of extras)
> >   - ListExploder to get separate features for each list item
> >   - AttributeCreator setting &fieldname = &fieldname
> >   - AttributeRemover (get rid of extras)
> >   - AttributeAccumulator (group by the Counter)
> >   - attach to FeatureMerger Supplier port
> > - Stream 2 (ListRemover)
> >   - ListRemover to get rid of the list (which we redefine in the 
earlier
> > step
> >   - attach to FeatureMerger Requestor port
> > - ListSorter by the list element index generated by the 
ListExploder to
> > make sure that original order is maintained
> > 
> > This leaves you with some undesirable elements in the list.  I'm 
not sure
> > how you would clean these up.  Also, the AttributeCreator does not
> > translate the &fieldname value for you, so the workspace is a bit
> > confusing unless you know what it's doing.
> > 
> > Example attached.
> > 
> > Jason
> > 
> > 
> > ________________________________
> > 
> > From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf 
Of
> > [EMAIL PROTECTED]
> > Sent: Tuesday, November 22, 2005 14:37
> > To: [email protected]
> > Subject: [fme] List format
> > 
> > 
> > 
> > Hi group,
> > 
> > I have a lot of data in this list format:
> > 
> > somelist{0}.fieldname = 'length'
> > somelist{0}.fieldvalue = 7.3
> > somelist{1}.fieldname = 'kind'
> > somelist{1}.fieldvalue = 'paved'
> > somelist{2}.fieldname = 'lanes'
> > somelist{2}.fieldvalue = 2
> > 
> > 
> > I want to convert into this list format:
> > somelist{0}.length = 7.3
> > somelist{1}.kind = 'paved'
> > somelist{2}.lanes = 2
> > 
> > In other words, I want to convert an attribute value into an 
attribute
> > name. Which is the best strategy to accomplish this task in 
Workbench
> > and/or FME functions and factories?
> > 
> > 
> > Thanks to help me,
> > 
> > Jean-François Beaudry
> > Technicien en géomatique
> > 
> > Hydro-Québec
> > Géomatique, relevés techniques et gestion des données
> > Direction - Environnement et services techniques
> > Direction principale - Expertise
> > Place Dupuis
> > 9e étage                                            Tél. : (514) 
840-3000,
> > 855, rue Sainte-Catherine Est                             poste 
4230
> > Montréal (Québec) H2L 4P5               Téléc. : (514) 840-4233
> > [EMAIL PROTECTED]   http://www.hydroquebec.com
> > <http://www.hydroquebec.com>
> > 
> > 
> > Get the maximum benefit from your FME, FME Objects, or 
SpatialDirect via
> > our Professional Services team.  Visit www.safe.com/services for 
details.
> > Yahoo! Groups Links
> > 
> > 
> > 
> >
>








Get the maximum benefit from your FME, FME Objects, or SpatialDirect via our 
Professional Services team.  Visit www.safe.com/services for details. 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/fme/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to