samedi 28 février 2015

How do I use only part of an inline variable substitution string in model builder?


I am using an inline variable substiution to alter a field name. I do this within an iteration model in model builder. The inline variable is the name of the feature class which I use as my input for each iteration. When I am altering the field name I would like to only use the first part of the inline variable. To explain this a bit better, here is the name structure of my feature classes:



  • SA_05_Walk_CBR

  • SA_10_Walk_CBR

  • SA_05_Bike_CBR

  • SA_10_Bike_CBR

  • SA_05_Driv_CBR

  • SA_10_Driv_CBR

  • SA_05_Walk_PJC

  • SA_10_Walk_PJC

  • SA_05_Bike_PJC

  • SA_10_Bike_PJC

  • SA_05_Driv_PJC

  • SA_10_DRIV_PJC

  • etc.


(Note that all feature class names have the exact same amount of characters for each part of the names)


Within my iterator, these feature class names represent my inline variable substitution string (called "count_field" in my model, see picture).


When I use the iterator, I join all the SA_xx_xxxx with a point feature class where I use the last three letters of the feature class name as a wilcard (e.g. _CBR). For my next iteration I do the exact same thing but then using "_PJC" as my new wildcard. These iterations work fine without any problems and it is also the reason why my feature classes need to end with "*_xxx".


Next in my iteration, I alter a certain field name so that they can be differentiated within the table of the feature class. Currently I use this in-line variable subsitution to rename the field (e.g. "SJ_Count_%count_field%"). Also this process works fine. Here is a picture of the alter field window (Please ignore the explanation mark; this picture is pure for a demo):


alter field window


(Please ignore the explanation mark; this picture is pure for a demo)


The thing what I want to do, however,is that it only uses part of the inline variable to alter my field name. The last 4 letters of my inline variable (e.g. "_CBR") can be removed within my new field name. So a field name would be called, for example, "SJ_Count_SA_05_Bike"


I have tried in renaming my field name again but I haven't found a way to remove the last 4 characters through an iteration. Anyone any ideas how I could do this in an efficient way? Using python within the alter field tool does not seem to be an option (as seen from alter field tool window picture). Here is a picture of my model:


join and alter field model through an iteration in model builder





Aucun commentaire:

Enregistrer un commentaire