1 / 19

Using Python in the Field Calculator in ArcGIS Desktop

Using Python in the Field Calculator in ArcGIS Desktop. Seminar Overview. Python overview Python string functions Python numeric functions. Python Overview. Python. What is Python?. Programming language Object-oriented Started in early 1990s by Guido van Rossum

channer
Download Presentation

Using Python in the Field Calculator in ArcGIS Desktop

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Using Python in the Field Calculator in ArcGIS Desktop

  2. Seminar Overview • Python overview • Python string functions • Python numeric functions

  3. Python Overview

  4. Python What is Python? • Programming language • Object-oriented • Started in early 1990s by Guido van Rossum • Named after Monty Python’s Flying Circus • Free • Quick to learn • Easy to code • Easy to read • Many users (lots of help) Why Do We Love It?

  5. Python and ArcGIS Desktop Label Expression Field Calculator Python Window

  6. Python Overview • Python Syntax Basics: • Python is case sensitive! • In python, surround column(field) names with !!

  7. Simple python expressions may contain: • Column(field) names !Street_Name! • Literal text “meters” or ‘meters’ • Mathematical and string operators + - / * • Functions .upper()

  8. Working with Strings(alpha numeric values)

  9. Python Syntax: Strings • Strings are Surrounded by quotes • Double “” • Single ‘’ • Backslash (\) is a special character \n = new line \t = tab

  10. String Operators • String Concatenation + • Python checks the field type. If you are using a + with numbers, Python does math. If you are using a + with strings, the strings get concatenated. !STATUS! + “AS OF 2016” !STATUS! + \t + “2016” !VALUE! + 100

  11. Working with Functions • Lots of functions for manipulating data. column_name>.<function>(function_parameters) • Some functions don’t have parameters !street_name!.upper()

  12. String Functions • Built-in Functions • .upper() • .lower() • .title() • .capitalize • .replace(<findstr>, <replacestr>) • Many others… !Company!.upper()

  13. String Functions • !Field1!.replace(<old>,<new>) “COUNTY_NAME” = REPLACE(“COUNTY_NAME”,’County’,’’) Replaces a portion of a string

  14. Python Slicing • Used to extract a portion of a text string !Field1![start:num_characters] Zero-based “COMPANY_ABREVIATION” = !COMPANY_CODE![0:2] “UNIQUE_ID’ = !PARCEL_NUM![-5:]

  15. Working with Numeric Values

  16. Number Operators/Functions • Mathematic • *, /, +, - • Round • round(x [,n]) • x rounded to n decimal places • Truncate • math.trunc(x) • Truncates number x to an integer

  17. Number Tricks

  18. Getting Help • Help buttons on tools • Arc GIS Desktop help: • “SQL (Structured Query Language), reference” in Index • “Fundamentals of Field Calculations” • http://support.esri.com

  19. Thanks for attending!

More Related