1 / 18

Introduction to ArcPy

Introduction to ArcPy. Topics. What is ArcPy ? Accessing geoprocessing tools using ArcPy Writing scripts using ArcPy. What is ArcPy ?. ArcPy was introduced with ArcGIS10 It’s Python site package With ArcPy , you’ve access to the Geoprocessing tools Extensions

damian
Download Presentation

Introduction to ArcPy

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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. 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

  5. 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

  6. 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

  7. How to use ArcPy • You have to import the ArcPy package before using it • Simply type “import arcpy” in Python Window in ArcGIS

  8. How to use a tool? Two ways to call a tool Example: arcpy.Buffer_analysis() Example: arcpy.analysis.Buffer()

  9. 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: Input features Out feature class Buffer distance There are a number of optional parameters too!!

  10. Environment Setting Set your workspace pathname for reading input & writing output file: arcpy.env.workspace = “C:\\GIS222” # Read and write files from GIS222 folder arcpy.env.workspace = “C:\\Test.gdb” # Read and write files from Test.gdb arcpy.env.overwriteOutput = 1 # Will overwrite the output file

  11. Let’s try it! Run buffer in Python Window Write a script to run buffer in PythinWin

  12. Using List Functions

  13. Topics • How to get a list of data layers? • Iterate through the list

  14. 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

  15. Important Note YOU MUST set the workspace before calling any list function import arcpy arcpy.env.workspace = "C:\\temp" fcs = arcpy.ListFeatureClasses()

  16. 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

  17. 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

  18. Let’s try it!

More Related