Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
ArcPy and ArcGIS: Geospatial Analysis with Python

You're reading from   ArcPy and ArcGIS: Geospatial Analysis with Python Use the ArcPy module to automate the analysis and mapping of geospatial data in ArcGIS

Arrow left icon
Product type Paperback
Published in Feb 2015
Publisher
ISBN-13 9781783988662
Length 224 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Toc

Table of Contents (14) Chapters Close

Preface 1. Introduction to Python for ArcGIS FREE CHAPTER 2. Configuring the Python Environment 3. Creating the First Python Script 4. Complex ArcPy Scripts and Generalizing Functions 5. ArcPy Cursors – Search, Insert, and Update 6. Working with ArcPy Geometry Objects 7. Creating a Script Tool 8. Introduction to ArcPy.Mapping 9. More ArcPy.Mapping Techniques 10. Advanced Geometry Object Methods 11. Network Analyst and Spatial Analyst with ArcPy 12. The End of the Beginning Index

Important Python Modules for GIS Analysis

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. Modules are also used to make other programs available to Python, such as the tools built in Microsoft Word.

The ArcPy module

The ArcPy module is both a wrapper module used to interact with the ArcGIS tools, which are then executed by ArcGIS in its internal code format, and a code base that allows for additional control of geospatial analyses and map production. ArcPy is used to control the tools in ArcToolbox, but the tools have not been rewritten in Python; instead, we are able to use the ArcGIS tools using ArcPy. ArcPy also gives us the ability to control ArcGIS Map Documents( MXDs) and the objects that MXDs include: legends, titles, images, layers, and the map view itself. ArcPy also has tools that are not available in ArcToolbox. The most powerful of these are the data cursors, especially the new Data Analysis Cursors that create a more Pythonic interface with GIS data. The data cursors, covered extensively in Chapters 5, ArcPy Cursors: Search, Insert and Update and Chapter 6, Working with ArcPy Geometry Objects are very useful to extract rows of data from data sources for analysis.

The ability to control geospatial analyses using ArcPy allows for the integration of ArcGIS tools into workflows that contain other powerful Python modules. Python's glue language abilities increase the usefulness of ArcGIS by reducing the need to treat geospatial data in a special manner.

The Operating System (OS) module

The OS module, part of the standard library, allows Python to access operating system functionality. A common use of the module is to use the os.path method to control file paths by dividing them into directory paths (that is, folders) and base paths (that is, files). There is also a useful method, os.walk, which will walk-through a directory and return all files within the folders and subfolders. The OS module is accessed constantly when performing GIS analysis.

The Python System (SYS) 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 (or parameters) supplied to the script, using the sys.argv method. The sys.path method is very useful to append the Python file path; practically, this means that folders containing scripts can be referenced by other scripts to make the functions they contain importable to other scripts.

The XLRD and XLWT modules

The XLRD and XLWT modules are used to read and write Excel spreadsheets, respectively. The modules can be very useful to extract data from legacy spreadsheets and convert them into usable data for GIS analysis, or to write analysis results when a geospatial analysis is completed. They are not part of the Python standard library, but are installed along with ArcGIS 10.2 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 not create 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.

Commonly used standard library modules

The following standard library modules must be imported:

  • datetime: The datetime module is used to get information about the date and time, and convert string dates into Python dates.
  • math: The math module is used for higher level math functions that are necessary at times, such as getting a value for Pi or calculating the square of a number.
  • string: The string module is used for string manipulations.
  • csv: The CSV module is used to create and edit comma-separated value type files.

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

You have been reading a chapter from
ArcPy and ArcGIS: Geospatial Analysis with Python
Published in: Feb 2015
Publisher:
ISBN-13: 9781783988662
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