Book Image

ArcPy and ArcGIS: Geospatial Analysis with Python

Book Image

ArcPy and ArcGIS: Geospatial Analysis with Python

Overview of this book

Table of Contents (19 chapters)
ArcPy and ArcGIS – Geospatial Analysis with Python
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Adding the CSV module to the script


For this script, we will use the CSV module, a useful module to create Comma Separated Value spreadsheets. Its simple syntax will make it a useful tool to create script outputs. It should be noted that ArcGIS for Desktop also installs the xlrd and xlwt modules, used to read or generate Excel spreadsheets respectively, when it is installed.

Just below the import arcPy line, add import csv. This will allow us to use the csv module to create the spreadsheet:

# Import arcpy module
import arcpy
import csv

The next adjustment is made to the Intersect tool. Notice that the two paths included in the input string are also defined as variables in the variable section. Remove the file paths from the input strings and replace them with numbered placeholder tokens, and then add the format function and supply the variables as placeholders:

# Process: Intersect
arcpy.Intersect_analysis("{0} #;{1}#".format( ..............  Inbound71_400ft_buffer,CensusBlocks2010),
    ...