Automation inArcGIS usingArcpyRui RuaGeodata As
Presentation topics In this presentation I will talk about: – How automation can be used to execute some geodatabase tasks; – Python, ArcPy and its interaction with the geodatabase; – Use cases.
What can we use automation for with geodatabases? In a general way, we use automation with geodatabases to: – Explore geodatabase content; – Simplify the execution of frequent administration tasks: • Create indexes; • Set privileges. – Implement data workflows: • conversion; • distribution;
How can automation be done? Automation of these tasks can be done using the Python programming language. Why Python? – Simple and easy to learn; – Widely adopted and well documented; – Powerfull, with many available built-in and external modules; – Fast to implement.
How can python be used with Arcgis and the geodatabase? The use of Python with Arcgis and the geodatabase is simplified by the fact that: – Python is available by default with all ArcGis 9.X and 10.X Desktop installations; – ‘Coding’ can be done using ArcGis Desktop ‘Python Window’ or one of the many development environments available: • Wingware • pyDev • or even Notepad++
How can python be used with Arcgis and the geodatabase? – All the interaction with the geodatabase, feature classes, rasters or even the mxds is done through a single python package, named ArcPy – and not with a vast library, making it easy to access the right function or geoprocessing tool. – If needed, in addition, specific modules provide a direct interaction with the databases themselves: • cx_oracle for Oracle; • pymssql for SQL Server.
What is ArcPy? This means that most of the time while scripting we will be using ArcPy, which is: – ESRIs python package for ArcGis 10 products - a set of modules, classes and functions; – ‘Upgraded’ from Arcgis version 9.X ‘arcgisscripting’. ArcPy is divided in a small number of modules, with names familiar to all ArcGis users: – Mapping (to interact with mxds); – Geostatistical analyst; – Spatial analyst.
What is arcpy main purpose then? ArcPy main purpose then is to: – provide easy programming access to all common data structures, geoprocessing tools and map documents (.mxd); – Simplify the execution of repetitive manual tasks by using scripts that are relatively fast to implement and that can be runned over and over.
Whats needed to use automation with the geodatabase? This means that to use automation with the geodatabase we need: – Good understanding of geodatabases; – Learn general python concepts and the language itself; – Become familiar with the ArcPy package. An easy way to start is to use both: – Geoprocessing tools help; – ArcPy page.
Use cases : To demonstrate how ArcPy interacts with the geodatabase, we’ll look into some examples where we use: – functions to explore the geodatabase; – geoprocessing tools to automate administrative tasks; – Both functions and geoprocessing tools to implement a ‘data distribution’ workflow.
Use case #1 - explore the geodatabase : In the first case we will see that ArcPy can be used to explore geodatabase objects and the data itself. It has its own functions to List: – Datasets; – Feature class or tables; – Fields; – or Rasters.
Use case #1 - explore the geodatabase : It also has some specific functions to: – ‘Describe’ the data, as the ones used to: • Get a feature class spatial reference; • or to Check if its versioned; – Read and Write data, allowing us to: • Get attribute values; • Update or insert features.
Use case #2 – administrative tasks: In this second example we will see how Arcpy can be used to run administrative tasks on datasets or feature classes. This can be done by using standard geoprocessing tools, as we know them in ArcToolbox: – Create or remove indexes; – Set privileges;
Use case #3 – automate workflow In this third example we will see how ArcPy can be used to make some operational workflows easyer to manage. As an example problem: – suppose we need to provide our operational teams with the most updated GIS data each time they go out to the field; – Consider that after their job is done, while still in the field, they will update the spatial data related to the job they executed; – In the end we want this new data in our main geodatabase.
Use case #3 – automate workflow One possible workflow could be to: 1. Make a python script to create a geodatabase on the team portable device and a ‘check-out’ replica between the main (parent) and the team (child) geodatabase, providing them with the data; Replicate Main data Team geodatabase geodatabase (Parent) (Child)
Use case #3 – automate workflow 2. Create another python script to ‘Synchronize changes’ between the geodatabases, updating the data, after the job is completed; Synchronize Main data Team geodatabase geodatabase (Parent) (Child)
Use case #3 – automate workflow 3. To make the process simple to our users, we can also create a custom toolbox with tools to run the scripts that check out and then check in the data.
Additional resources Python concepts and language – Google python class http://code.google.com/edu/languages/google-python-class/ – Dive into python www.diveintopython.net/ Arcpy – Visit ArcGis help library, and under Professional Library -> Geoprocessing > The Arcpy site package http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html# /Welcome_to_the_ArcGIS_Help_Library/00r90000001n00000 0/