Skip to main content

The problem is that a few cell's contain to many characters, and there takes no mapping place.

I'm creating ESRI features.

Is there somebody who knows how to solve this problem?

 

I don't want to increse the cell width, so i am looking for a solution to use only the first part of the characers in a cell.

Hi

I'm not sure if I've fully understood your question, but if some of your attributes are too long to fit in the target dataset, you can use the SubstringExtractor to only use the first n characters.

David


Hi Remco,

The SubstringExtractor would indeed be the way to go. However if you want to test multiple variables, then it might be more useful to use a PythonCaller, loop through all variables and shorten those that are too long. Below you can find an example.

import fme
import fmeobjects

# Change the value beneath
maxLengthValue = 20

# Template Function interface:
def shortenValues(feature):
    
    # Retrieve all attributenames of this feature
    attributes = feature.getAllAttributeNames()
   
    # loop through all attributes
    for cAttribute in attributes:
        
        # Make sure nothin is changed on the standard (hidden) fme variables
        if cAttribute 0:4] == 'fme_':
            continue
        
        # Get the value if this attribute
        value = feature.getAttribute(cAttribute)

        # Check if the value of this attribute is too long.
        if len(str(value)) > maxLengthValue:
            feature.setAttribute(cAttribute, value/0:maxLengthValue])

The benefit of using Python over the SubstringExtractor is that you can generate a message in the log so you know a certain attribute is shortened and that you can shorten a lot of attributes with just one transformer.  

Good luck!


If you just want to check if the length of the string is too much, you could use a Tester transformer and use the function StringLength on the attribute. All failing features can be written to a Logger, Inspector or the output of your choice.

This will allow QA before writing to the ESRI database.


Reply