Python Scripts

Automated Buffer

This script creates a new layer our of a selection and then buffers the new layer. Great to automate several buffers at once, or for very large datasets that would take a long time to process (ArcGIS).

        
       

#Jonathan Engelbert, 05/30/2017



import arcpy
from arcpy import env
env.workspace = #enter workspace path here

sql1 = #enter SQL expression here

arcpy.Select_analysis(#"layer to be selected", "path and name of the file as output", sql1)
arcpy.Buffer_analysis(#"path and name layer to be buffered", "path and name of the file as output, "buffer EX: 2 MILE")

input("EXIT") #Keeping this here so user can actually read the output before python closes it out.


      
     
    
      

Search Cursor Iteration

Looks through a shapefile, sorts and prints formatted information after iteration (ArcGIS).

        
       

import arcpy
# Open a searchcursor
# Input: C:/Data/Counties.shp
# Fields: NAME; STATE_NAME; POP2000
# Sort fields: STATE_NAME A; POP2000 D
rows = arcpy.SearchCursor("c:/data/counties.shp",
                            fields="NAME; STATE_NAME; POP2000",
                            sort_fields="STATE_NAME A; POP2000 D")

# Iterate through the rows in the cursor and prints out formated information. In this example case, it returns state name, county and population of each.

for row in rows:
    print("State: {0}, County: {1}, Population: {2}".format(
      row.getValue("STATE_NAME"),   
      row.getValue("NAME"),
      row.getValue("POP2000")))