Download presentation
Presentation is loading. Please wait.
Published byRosalind Harrell Modified over 9 years ago
1
Introduction to ArcPy
2
Topics What is ArcPy? Accessing geoprocessing tools using ArcPy Writing scripts using ArcPy
3
What is ArcPy? ArcPy was introduced with ArcGIS10 It’s Python site package With ArcPy, you’ve access to the – Geoprocessing tools – Extensions – Functions & classes
4
Access to Geoprocessing Tools ArcPy provides access to all geoprocessing tools - Based on license level Tools return an object Tools can also produce messages -- Object & messages can be manipulated from Python script
5
ArcPy Functions Functions perform a specific task as a part of larger program All geoprocessing tools are functions -- Union, Buffer, Clip etc. But not all functions are geoprocessing tools -- List datasets, describe dataset, create cursor
6
ArcPy Classes Classes provide a framework for creating object - referred to as an instance Examples of classes - SpatialReference, Extent etc. Classes have methods & properties -- Spatialreference.name -Spatialreference.type
7
ArcPy Modules Modules are Python libraries containing functions and classes 3 modules --Mapping modules: arcpy.mapping - Spatial Analyst module: arcpy.sa - Geostatistical module: arcpy.ga Example: -- arcpy.sa.Slope is same as using the Slope tool from Spatial Analyst toolbox
8
How to use ArcPy You have to import the ArcPy package before using it Simply type “import arcpy” in Python Window in ArcGIS
9
How to use a tool? Two ways to call a tool Example: arcpy.Buffer_analysis() Example: arcpy.analysis.Buffer()
10
Tool Syntax Each tool needs specific parameters to run correctly Buffer_analysis (in_features, out_feature_class, buffer_distance_or_field, {line_side}, {line_end_type}, {dissolve_option}, {dissolve_field}) Buffer tool needs 3 required parameters: 1.Input features 2.Out feature class 3.Buffer distance There are a number of optional parameters too!!
11
Environment Setting Set your workspace pathname for reading input & writing output file: arcpy.env.workspace = “C:\\GIS222” arcpy.env.workspace = “C:\\Test.gdb” # Read and write files from GIS222 folder # Read and write files from Test.gdb arcpy.env.overwriteOutput = 1 # Will overwrite the output file
12
Let’s try it! a.Run buffer in Python Window b.Write a script to run buffer in PythinWin
13
Using List Functions
14
Topics How to get a list of data layers? Iterate through the list
15
Getting a list Getting the list of available data is often the first step of many tasks ArcPy provides functions for getting − Lists of fields − Lists of datasets − List of feature classes − List of Files − List of Tables − And more
16
Important Note YOU MUST set the workspace before calling any list function import arcpy arcpy.env.workspace = "C:\\temp" fcs = arcpy.ListFeatureClasses()
17
Iterating through the list Python ‘for’ loop can be used to loop through your list import arcpy arcpy.env.workspace = “C:\\Auburn.gdb” for fc in arcpy.ListFeatureClasses(): print fc
18
Other List Methods ListDatasets –Lists all datasets from a workspace –Feature, TIN, Raster, or CAD ListRasters –Lists all rasters in a workspace –PNG, TIFF, JPG, BMP, GIF, IMG, GRID, others ListFields –Lists the fields in a feature class, shapefile, or table in a specified dataset ListTables –Lists all tables in the workspace ListWorkspaces –Lists workspaces within a workspace –Folders, file geodatabases, personal geodatabases
19
Let’s try it!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.