Arcmap field calculator code#
The “newName(0)” in the “SchoolName =” box then runs the code for each record in the table (or only on selected records if there are any) and puts the extracted text in that field when I click OK.
Take what’s to the left of the colon and refer to it as “newName”. Take the value in the “Name” attribute field (from the WalkingZones layer) and split the text at the colon character. I’ve set it up this way:Īllow me to translate. We can type our code in the Pre-Logic box and then actually run it on the SchoolName attribute in that box. We’ve got two new boxes now: “Pre-Logic Script Code” and “SchoolName =”. Python users, note that you can tick the Python parser to use commands in that scripting language. This allows us to write a small snippet of Visual Basic (VB) code to do the job. Here’s one way to remove the “0 – 500” bit. Normally, we use the Field Calculator to calculate or add values to fields but we can also use it to extract text or concatenate (link together) multiple attributes. Next, right-click on the new field name and choose the Field Calculator: As a first step, I’ll add a new text attribute to my walking zones layer I’ll call it SchoolName: I’d like to extract everything to the left of the colon and add that text to a new field. So what’s a GIS analyst to do? This calls for a bit of field calculating. In order to do a table join, I need the school names to be exactly the same. The “0 – 500” bit came from the network analysis layer and I can’t do much about that. “Aranui High School”) but in the walking zones layer, it’s “Aranui High School : 0 – 500”. In the secondary schools layer, it’s just the school name (e.g. My aim is to summarise the number of retailers in each zone by the schools so I’d like to join the attribute table to my schools layer so I have everything in one place, only I’ve got a problem – the attribute that holds the school name is different in the two layers: In this case, I tabulated the number of retailers within each polygon. I used Network Analysis to create zones around the schools and then used a tool that joins together attributes from two layers based on where they are with respect to each other. So here’s the thing – I’ve been doing some more analysis on the proximity of tobacco retailers to secondary schools, focusing on areas within 0 – 500 m of each school in Christchurch – all things we’ve covered in earlier posts. We join our programme already in progress…
Arcmap field calculator how to#
This post demonstrates how to use the field calculator to extract text values from a field and add them to another field.