Taking advantage of Python in ArcGIS

May 12, 2011 by  
Filed under Programming

Python is the next big programming language for ArcGIS. With the addition of the ArcPy module in ArcGIS 10 there is so much more that can be done with Python. In previous version of ArcGIS VBA made is easy to customize the interface and basic processes. At the release of ArcGIS 10.1 VBA will no longer be supported.

So now that Python has been proven as a great tool, who do you begin.  Sure you can start with www.python.org but the is so much information is on the site you are not sure where to start.  Well, there is a endless source for finding code samples.  Search the ArcGIS Help Library to find the tool you would like to use.  Then scroll to near the bottom and there is a code sample to use in the Python Window or as a stand-alone script for that particular tool.

Another  method that saves a lot of time is to use ModelBuilder and create a model for the desired process.  Once you get the model working then export the model as a script (Model > Export > Script).  The output of this export provides a great starting point for expanding on the python code to get the task accomplished.

Here is a quick example from the Buffer tool help document:

Python Widnow Script
import arcpy
arcpy.env.workspace = "C:/data"
arcpy.Buffer_analysis("roads", "C:/output/majorrdsBuffered" "100 Feet", "FULL", "ROUND", "LIST", "Distance")

Stand-alone Script
# Name: Buffer.py
# Description: Find areas of suitable vegetation which exclude areas heavily impacted by major roads
# Author: ESRI

# import system modules
import arcpy
from arcpy import env

# Set environment settings
env.workspace = “C:/data/Habitat_Analysis.gdb”

# Select suitable vegetation patches from all vegetation
veg = “vegtype”
suitableVeg = “C:/output/Output.gdb/suitable_vegetation”
whereClause = “HABITAT = 1″
arcpy.Select_analysis(veg, suitableVeg, whereClause)

# Buffer areas of impact around major roads
roads = “majorrds”
roadsBuffer = “C:/output/Output.gdb/buffer_output”
distanceField = “Distance”
sideType = “FULL”
endType = “ROUND”
dissolveType = “LIST”
dissolveField = “Distance”
arcpy.Buffer_analysis(roads, roadsBuffer, distanceField, sideType, endType, dissolveType, dissolveField)

# Erase areas of impact around major roads from the suitable vegetation patches
eraseOutput = “C:/output/Output.gdb/suitable_vegetation_minus_roads”
xyTol = “1 Meters”
arcpy.Erase_analysis(suitableVeg, roadsBuffer, eraseOutput, xyTol)

Streamline Workflow with Model Builder

September 10, 2008 by  
Filed under ArcGIS, ArcToolbox, GIS Tips

There are many tasks that we preform over and over each day in ArcMap.  We go through the same routine without thought of there actually being an easier way.  These repetitious actions can actually be modeled to make like easier and more productive.  ArcGIS provides a excellent tool called Model Builder.  Model Builder is based out of ArcToolbox.  By following just a few simple steps, you can be on your way to an easier, more productive work flow.

To create a model:

1. Open ArcToolbox by clicking on the red toolbox at the top of ArcMap or ArcCatalog.

Read more

90 Second File Geodatabase

September 4, 2008 by  
Filed under ArcGIS, Data Management, Education, GIS Tips

Recently my professor challenged our class to create File Geodatabase in under 90 seconds.  For those who are new to ArcGIS, this can seem like a steep challenge.  Once you get the key steps down, it will come second nature.  These steps are important in beginning to understand how to use a geodatabase. 

Here is the test:

Setup:  Create working folder; Find Spatial Reference to Import; Find Feature Class to Import
(Clock Starts Now)
1. Create New File Geodatabase
2. Create New  Feature Dataset
3. Import Feature Class
(Clock Stops When Import Ends)

Solution:
1. Right Click Working Folder and Select New -> File Geodatabase (give logical name)
2. Right Click the Geodatabase and Select New -> Feature Dataset… (give logical name)
A. Give Logical Name
B. Import Spatial Reference Information
3. Right Click the Dataset and Select Import -> Feature Class…
A. Select Feature to Import
B. Name New Feature Class

So, I challenge you to see how fast you can complete this test.  Can you do it in under 90 seconds?  Post your results in the comments of this post.

The creative part of me decided that I should see if I could create a model to implement these steps.  Below is the model that I created.  This model takes about 5 seconds to create a File Geodatabase, Feature Dataset, and Import a Feature Class.