Esri Southeast User Conference - Python Presentations

07 May 2014 Update: The code created in both presentations has been included in the embedded referenced GISTs.

This coming week the annual Esri Southeast User Conference (SEUC) is being held at the Charlotte Convention Center in (no kidding) Charlotte, NC. I will be presenting two presentations on Python. Since I reference a lot of online resources, I have made the outlines available as GitHub pages.

The presentations are Python 101 and Python 201. Python 101: Using Python with ArcGIS, is geared toward those proficient with GIS, but have never seen Python before. Python 201: Crafting Python Tools, focuses on the process of prototyping a workflow and then creating and documenting a tool from this prototyped workflow. In this presentation, we will discuss a couple of best practices, and also some relevant topics to make your coding life easier I have learned the hard way.

Both presentations will be held in room 219AB. Python 101 will be held from 13:00 to 14:15 on Tue 06 May. Python 201 will be held from 10:15 to 11:30 on Wed 07 May. Please use the Esri Events Web Application to navigate the conference or one of the Events Apps for mobile devices. Both iOS and Android are available.

Since in the presentations I reference a lot of online resources, I have created two repositories with pages on GitHub to make these resources available to you both during and after the presentation. The pages for each are available at:

During the first presentation, we create a script identifying airfields based on specific criteria. The code from the first presentation is included as the first script below.

Also, during the second presentation, I use the example of exporting all the layers in a CAD feature class as discrete feature classes. In case you want to see the finished product, it is included as the second script below.

"""
name: cadToArcgis.py
father: Joel Mccune (jmccune@esri.com)
birthdate: 01 Apr 2014 (April Fool!)
purpose: Your eternal Pythonistic enlightenment...and something about
CAD to ArcGIS conversion as well.
"""
# import modules
import arcpy
# variables
#out_wksp = r'D:\spatialData\cad\cad_data.gdb'
#input_cad = r'MillerRanch.dwg Polyline'
out_wksp = arcpy.GetParameterAsText(0)
input_cad = arcpy.GetParameterAsText(1)
field = 'Layer'
# use comprehension to create set of unique values found in layer field
values = (row[0] for row in arcpy.da.SearchCursor(out_wksp, field))
# for every one of the values found in the layer field
for value in values:
# create a sql selection string
sql = """"Layer" = '{0}'""".format(value)
# reformat the output table name so ArcGIS likes it
out_name = arcpy.ValidateTableName(value, out_wksp)
# copy the feature class to the new location
arcpy.FeatureClassToFeatureClass_conversion (in_features=input_cad,
out_path=out_wksp,
out_name=out_name,
where_clause=sql)
"""
name: Luke
father: Darth
date: May 04, 2014
purpose: Overcome the dark side.
"""
# import modules
import arcpy
import os.path
# environment settings
arcpy.env.workspace = r'D:\seuc2014\spatial_data\output_gdb.gdb'
arcpy.env.overwriteOutput = True
# setting variables
in_dmz = r'D:\seuc2014\spatial_data\korea.gdb\dmz'
in_dmz = arcpy.GetParameterAsText(0)
in_airfields = r'D:\seuc2014\spatial_data\korea.gdb\Airfields'
out_wksp = r'D:\seuc2014\spatial_data\output_gdb.gdb'
os.path.join(out_wksp, 'target_fc')
# buffering dmz by 25 miles
dmz_25mi = arcpy.Buffer_analysis(in_dmz,"in_memory/dmz_Buffer","25 Miles","FULL","ROUND","NONE").getOutput(0)
# clipping out airfields
airfield_25mi = arcpy.Clip_analysis(in_airfields, dmz_25mi, "in_memory/Airfields_Clip").getOutput(0)
# create output airfilds with heavy lift capability
airfield_25mi_hl = arcpy.Select_analysis(airfield_25mi, 'hot_airfields2',"Length >= 3000").getOutput(0)

If you are planning on attending the Esri Southeast User Conference and are interested in Python, please attend my sessions. Also, please take advantage of the Events Applications to make navigating the conference easier.