TransWikia.com

FME 2019: Generate a new PK based on a concatenation of a string and a three digit increment

Geographic Information Systems Asked by lhowarth on January 4, 2021

I’m transforming a number of geographic tables from one MCD to another, so I’m using FME (I’m new to FME).
I can map 80% of my fields with out any problem (MCD_A.fld_1 = MCD_B.fld_1) but in the in the second MCD I need to generate a new PK based on a concatenation of a string and a three digit increment something like ‘BBBSYN_’||Increm.

I’ve tried generating the value directly in the FME writer (Feature Type -> User Attributes -> Value -> text Editor (see below) using @Count() – but this only generates simple increments ‘1’,’2′,’3′ – I need ‘001’, ‘002’ etc. Also I already use @Count in another field and FME seems to confuse them both, i.e. in fld_1 and fld_2 of the same feature, count results in fld_1 = 1 and fld_2 = 2, not ideal.

enter image description here

I’ve looked through the safe website and the youtube channel – which is full of useful stuff but it’s like finding a needle in a haystack – I also found this on SE : How to create autoincrementing primary key with dynamic writer in FME

Which looked like it would solve at least part of the problem – but it’s a couple of years old and I don’t have same options available in my feature type dialog box (I can’t set type to identity or index to primary key for example) – I’m using FME 2019 and this post is over two years old so i’m guessing they’re not using FME 2019…

This is probably incredibly easy (it really should be…), but I can’t find the right function ?

2 Answers

Congrats on getting this going. Yes, the @Count() function can take an optional “counter name” argument so that you can insulate one @Count invocation from another...should you want to.

But another way is to assign counts earlier and stash into an attribute. However, it seems that your line here:

string_@Format(%03d,@Value(_count())

Has an extra set of () on it — _count is an attribute and shouldn’t have () after it.

string_@Format(%03d,@Value(_count))

Above is what I think you’re looking for. Now that I fix that, I think the original actually had unbalanced () too. Probably just a typo but worth noting here in case future generations come looking.

Answered by Dale Lutz on January 4, 2021

OK so I found an answer on the FME forum in the end and I thought I'd share it here:

Basically in the field type dialog box in the field value I added:

string_@Format(%03d,@Count())

This will left-pad the count with zeroes to 3 characters. To distinguish this count from previous count I just added 1 into the Count parameter ('Count(1)'). But in the end used a Counter to generate my numbers separately and just recovered the value, like below:

string_@Format(%03d,@Value(_count())

https://community.safe.com/s/question/0D54Q0000875KxTSAU/generating-a-new-primary-key-based-on-a-concatenation-of-a-string-and-a-three-digit-increment

Answered by lhowarth on January 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP