Python 4 Arc

2,424 views

Published on

Python for ArcGIS geoprocessing pre ArcGIS10

Published in: Technology, Education
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,424
On SlideShare
0
From Embeds
0
Number of Embeds
23
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Python 4 Arc

  1. 1. Python & ArcGIS Geoprocessing
  2. 2. Presentation Scope <ul><li>Requirements. </li></ul><ul><li>Python programming language & COM. </li></ul><ul><li>ArcGIS and Scripting (Geoprocessing). </li></ul><ul><li>Using the Geoprocessor Object. </li></ul><ul><li>Some Examples. </li></ul>
  3. 3. Requirements <ul><li>Knowledge of a programming language, preferably python. </li></ul><ul><li>Some knowledge of ArcObjects / Concept of OO. </li></ul><ul><li>Knowledge of Object Model Diagrams (not essential). </li></ul><ul><li>Software Requirements: </li></ul><ul><ul><li>Python comes installed with ArcGIS. </li></ul></ul><ul><ul><li>If required can be installed. </li></ul></ul><ul><ul><li>Win32com client needed if not installed on the machine. (COM) </li></ul></ul><ul><li>Potential problems associated with Python and ArcGIS installation: </li></ul><ul><ul><li>http:// support.esri.com/index.cfm?fa = knowledgebase.techarticles.articleShow&d =31900 </li></ul></ul>
  4. 4. Python Programming Language <ul><li>Python is platform independent, object Oriented language. </li></ul><ul><li>It is easy to learn. </li></ul><ul><li>Two good websites/Python references exists at: </li></ul><ul><ul><li>http://www.diveintopython.org/ </li></ul></ul><ul><ul><li>http://www.python.org </li></ul></ul><ul><li>Before proceeding, do ensure you have considerable knowledge of Python. </li></ul><ul><li>ArcGIS 9.2 ships with Python 2.4.1. </li></ul>
  5. 5. Component Object Model <ul><li>COM is a protocol that connects one software component with another. </li></ul><ul><li>These software components under COM are called objects. </li></ul><ul><li>Different types of objects exists which are used for variety of purposes. </li></ul><ul><li>So which object is used for Python/Geoprocessing(Scripting)? </li></ul><ul><ul><li>Geoprocessor object exposes ArcGIS toolbox (geoprocessing functions) to Python. </li></ul></ul><ul><ul><li>This object provides a single access point to the toolbox. </li></ul></ul><ul><ul><li>It has methods and properties like any other object, using which powerful things can be done. </li></ul></ul>Geoprocessor Object So much can be done
  6. 6. Geoprocessing (What is it?) <ul><li>In simple words, it is the processing of geographic information to create new useful information (example: used for analysis). </li></ul><ul><li>The fundamental purpose of geoprocessing is to allow you to automate your GIS tasks </li></ul><ul><li>So how would you want to process geographic information? </li></ul><ul><li>Consider the following: </li></ul><ul><ul><li>Suppose you have few ASCII files and want to convert them all into a single polygon shapefile. You might also be interested in obtaining a polyline shapefile from the generated polygon. </li></ul></ul><ul><ul><li>Some of you may point out, it can be done manually using the toolboxes in ArcMap . True . You can process the ASCII files for a specific purpose (like generating the polygon feature). </li></ul></ul><ul><ul><li>But, it does require you to use number of geoprocessing functions (in a specific sequence) and therefore a number of steps must be performed to obtain the final polygon and polyline shapefile. See below for all the steps involved </li></ul></ul>
  7. 7. Manual Geoprocessing <ul><ul><li>Steps: </li></ul></ul><ul><ul><ul><li>Open ArcToolbox. </li></ul></ul></ul><ul><ul><ul><li>ArcToolbox / Conversion Tools / To Raster / ASCII to Raster. </li></ul></ul></ul><ul><ul><ul><li>Repeat this process to convert all your ASCII (*.asc) files to Rasters. </li></ul></ul></ul><ul><ul><ul><li>Merge all these raster files into one raster using ArcToolbox / Data Management Tools / Raster / Mosaic. </li></ul></ul></ul><ul><ul><ul><li>When the process has completed, one of the rasters will be the merged version of all the rasters. Remove all but the merged raster from the map. </li></ul></ul></ul><ul><ul><ul><li>ArcToolbox / Spatial Analyst Tools / Reclass / Reclassify. </li></ul></ul></ul><ul><ul><ul><li>Click Classify… and set the number of classes to 1. </li></ul></ul></ul><ul><ul><ul><li>The reclassified raster is added to the map. </li></ul></ul></ul><ul><ul><ul><li>ArcToolbox / Conversion Tools / From Raster / Raster To Polygon </li></ul></ul></ul><ul><ul><ul><li>When the process is complete, the polygon will be added to the map. </li></ul></ul></ul><ul><ul><li>Now consider, the above operation needs to be performed on daily or weekly basis on ASCII files corresponding to different areas. Or even better lets say you are going on vacation but want the process explained in the previous slide to be carried out while you are off. </li></ul></ul><ul><ul><li>Someone will have to do all of this processing manually…..waste of time ??? </li></ul></ul><ul><ul><li>It would be great if all this processing can be done automatically or can be scheduled to be carried out while you are away. </li></ul></ul>
  8. 8. Scripting to the rescue <ul><ul><li>This is where scripting plays an important role. </li></ul></ul><ul><ul><li>A script will need to be programmed once to automate the above mentioned procedure. </li></ul></ul><ul><ul><li>The script can be run for creating the polygon and polyline shapefile and can be reused whenever such output is required. </li></ul></ul><ul><ul><li>Imagine the amount of effort and time saved! </li></ul></ul>
  9. 9. Take a break! <ul><li>Make sure you have understood the above scenario and acknowledge the need for scripting. </li></ul><ul><li>BUT!!!! Scripting is not applicable in all scenarios. Writing scripts can be time consuming process, so if scripting is not necessary don’t do it. </li></ul>
  10. 10. Geoprocessor Object (Recep) <ul><li>Remember </li></ul><ul><ul><li>Geoprocessor object is an object that provides single access point to ArcGIS tool Box. </li></ul></ul><ul><ul><li>It has methods and properties. Interation with the Geoprocessor is through these methods and objects. Example: createObject() method to create an object. </li></ul></ul><ul><ul><li>Important: Geoprocessor Programming Model list all the properties and methods available. </li></ul></ul>
  11. 11. Geoprocessing Programming Model (Overall View) http://webhelp.esri.com/arcgisdesktop/9.2/pdf/Geoprocessor.pdf

×