3

I have a large number of raster images that need processing and eventually summing of layers. But first I need to convert "no data" values then reduce the number of decimal places in said raster. I have a simple model of the process and am using the iterative module for file input. The input filenames are some 28 characters long. The raster map calculator does not allow over 13 characters on the output. Obviously the model returns a file naming error in this situation.

I need to be able to pass the right 13 characters of the left twenty from the %Name% variable of iterative module, i.e. using field calculator language,

right(left(name, 20), 13)

Is it possible to use some of the UNIX line commands like sed or awk, or some python code of which I have no clue how to write or apply?

2

Let's take a look at it in Excel:

| 1 |             A              |           B            |    
| 2 | ABCDEFGHIJKLMNOPQRSTUVWXYZ | =RIGHT(LEFT(A1,20),13) |

Which will display HIJKLMNOPQRST

In python then, we need to slice the first 20 characters, and from that the last 13. (Note the use of negative slicing, which is needed to start from the end of the string.)

>>> from string import uppercase as s
>>> print(s[:20][-13:])
HIJKLMNOPQRST

Or the equivalent and simpler print(s[7:20]) which can be generalized as: s[left-right:right]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.