Skip to main content
Question

Extract separate attributes from one layer name? CAD

  • September 19, 2013
  • 9 replies
  • 40 views

Forum|alt.badge.img
Reader is Autocad and writer is FGDB. What I am trying to do is extract separate attributes from one layer name. For example Layer name is 4_SDR_21_WATERMAIM and need the 4_ in "size" field SDR_21 in "material" field and WATERMAIN in "main_type" field? Can someone please point me in the right direction for the best way to accomplish this? Thank you

9 replies

david_r
Celebrity
  • September 19, 2013
Hi,

 

 

it gets slightly complicated since the underscore "_" is used both as a delimiter and a part of the text. However, you can use a regular expression (regexp tutorial here) in the StringSearcher to extract the parts. I used the expression

 

 

([0-9]+)_([A-Z0-9]+_?[A-Z0-9]+)_(.+)

 

 

and the feature exiting the MATCHED port had the following list items:

 

 

`_matched_parts{0}' has value `4'

`_matched_parts{1}' has value `SDR_21'

`_matched_parts{2}' has value `WATERMAIM'

 

 

The regexp expression above assumes that the first part is numerical only, the second part consists of alfanumerics that may or may not contain one single underscore somewhere in between and the last part is alfanumerical only.

 

 

David

david_r
Celebrity
  • September 19, 2013
An alternative, and perhaps simpler, solution could be to use an AttributeSplitter with "_" as delimiter and then regroup the output manually using e.g. a StringConcatenator. The output for your sample value would be

 

 

`_list{0}' has value `4' `_list{1}' has value `SDR' `_list{2}' has value `21' `_list{3}' has value `WATERMAIM'

 

 

You could concatenate the attributes "SDR" and "21" using the expression "@Value(_list{1})_@Value(_list{2})"

 

 

David

Forum|alt.badge.img
  • Author
  • September 19, 2013
Because we are still in the designing phase for the cad to FGDB conversion would your suggestion be to name it differently than what is above? Or maybe with only spaces instead of underscore? I am still new to the FME program and very green to coding. checking out the web link you sent now. Thanks again for your help.   

 


david_r
Celebrity
  • September 19, 2013
Hi,

 

 

yes, if possible, I'd personally try and avoid using a delimiter character that could occur in the values, such as the "_" in your example. I recommend that you test a couple of alternatives to see what works best for you.

 

 

Common options are commas, slashes, etc, but it isn't really possible to give you a specific recommendation without knowing the details of all the software components used in your entire data chain. Testing is key.

 

 

David

Forum|alt.badge.img
  • Author
  • September 19, 2013
Looks like i have a long day ahead of me....I will convert the layer name to spaces and not "_" and test from there. Thank you again for your help

Forum|alt.badge.img
  • Author
  • September 19, 2013
I renamed the layer I am testing to  4 DR-21 WATERMAIN. Would you still use the AttributeSplitter transformer for this particular situation? I have been trying ever since and NO luck what so ever. pulling hair out!!!!

takashi
Evangelist
  • September 20, 2013
Hi,

 

 

I think the new layer name is more suitable format for applying the AttributeSplitter.

 

 

I agree with David on "Testing is key".

 

One of the great things of FME is that we can confirm the functionality of a transformer individually and also quickly. I would do test with a simple workspace like this if I were you.

 

 

Hope this helps.

 

 

Takashi

Forum|alt.badge.img
  • Author
  • September 23, 2013
I see what you are trying to do....the picture examples do so much justice for us beginners. Thank you SO much takashi (and others) for the example. I will be able to jump back on it later today after i create all the CAD linetypes and layers.

Forum|alt.badge.img
  • Author
  • September 25, 2013
Okay so i renamed the layers as follows

 

4 DR-21 PVC C-900 W and trying to get a regex expression to pull the following.

 

4

 

DR-21

 

PVC

 

C-900

 

And DROP the "W" cause I no longer need it.

 

([A-Za-z0-9_-]+) this only splits it up but does not work w/ the Attributesplitter...Please Help!

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings