Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
ArcPy and ArcGIS

You're reading from   ArcPy and ArcGIS Automating ArcGIS for Desktop and ArcGIS Online with Python

Arrow left icon
Product type Paperback
Published in Jun 2017
Publisher Packt
ISBN-13 9781787282513
Length 272 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Silas Toms Silas Toms
Author Profile Icon Silas Toms
Silas Toms
Dara OBeirne Dara OBeirne
Author Profile Icon Dara OBeirne
Dara OBeirne
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Introduction to Python for ArcGIS FREE CHAPTER 2. Creating the First Python Script 3. ArcPy Cursors - Search, Insert, and Update 4. ArcPy Geometry Objects and Cursors 5. Creating a Script Tool 6. The arcpy.mapping Module 7. Advanced Analysis Topics 8. Introduction to ArcGIS Online 9. ArcPy and ArcGIS Online 10. ArcREST Python Package 11. ArcPy and ArcGIS Pro 12. ArcGIS API for Python

Important Python modules

Modules, or code libraries that can be called by a script to increase its programming potential, are either built into Python, or are created by third parties, and added later to Python. Most of these are written in Python, but a number of them are also written in other programming languages, and then "wrapped" in Python to make them available within Python scripts. Wrappers are also used to make other software available to Python, such as the tools built into Microsoft Excel.

The OS (operating system) module

The os module, part of the standard library, is very useful for a number of regular operations within Python. The most used part of the os module is the os.path method, which allows the script to control file paths, and to divide them into directory paths and base paths. There is also a useful method, os.walk, which will "walk" a directory and return all files within the folders and the subfolders.

The sys (Python system) module

The sys module, part of the standard library, refers to the Python installation itself. It has a number of methods that will get information about the version of Python installed, as well as information about the script, and any "arguments" supplied to the script, using the sys.argv method. The sys.path method is very useful for appending the Python file path; practically, this means that folders containing scripts can be referenced by other scripts to make the functions they contain importable.

The CSV, XLRD, and XLWT modules

The csv, xlrd, and xlwt modules are used to read and write data spreadsheets. They can be very useful for extracting data from the spreadsheets and converting them into data for GIS analysis, or for writing out analysis results as spreadsheets when an analysis is complete. The csv module (which creates text file spreadsheets using text delimiters like commas) is a built-in module, while xlrd and xlwt (which read and write Excel files respectively) are not part of the standard library, but are installed along with ArcGIS and Python 2.7.

Commonly used built-in functions

There are a number of built-in functions that we will use throughout the book. The main ones are listed as follows:

  • str: The string function is used to convert any other type of data into a string.
  • int: The integer function is used to convert a string or float into an integer. To avoid an error, any string passed to the integer function must be a number such as '1'.
  • float: The float function is used to convert a string or an integer into a float, much like the integer function.

Standard library modules

Commonly used standard library modules that must be imported are as follows:

  • datetime: The datetime module has date and time information, and can convert date data formats
  • math: The math module is for higher level math functions, such as getting a value for Pi or squaring a number
  • string: The string module is used for string manipulations
  • csv: The csv module is used for creating, accessing, and editing text spreadsheets.

Check out https://docs.python.org/2/library/ for a complete list of the built-in modules.

You have been reading a chapter from
ArcPy and ArcGIS - Second Edition
Published in: Jun 2017
Publisher: Packt
ISBN-13: 9781787282513
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image