Lecture 10 Accessing tools and environment setting in Scripts

Slides:



Advertisements
Similar presentations
Geoprocessing; Useful Tools You Should Know in ArcToolbox Unlock the hidden secrets of ArcToolbox to discover tools that make your work easier and analysis.
Advertisements

Why python? Automate processes Batch programming Faster Open source Easy recognition of errors Good for data management What is python? Scripting programming.
Introduction to Python. Python is a high-level programming language Open source and community driven “Batteries Included” – a standard distribution includes.
Introducing ArcGIS Desktop
Introduction to GIS and ArcGIS How a GIS works Introduction to ArcGIS The ArcGIS Interface.
Geography 465 Working with ArcGIS Tools and Environment Settings.
Python & ModelBuilder. Overview Python/ModelBuilder Concepts – The Geoprocessor – Checking some environment variables – Providing feedback from your model/script.
ModelBuilder In ArcGIS 9.x By Tim Weigel GEOG 407/607 April 3 rd, 2006.
Spatial Analysis, Geoprocessing,
What Geoprocessing? Geoprocessing is the processing of geographic information. Commonly used to describe a process when geographic objects are manipulated.
ModelBuilder at ArcGIS 9.2 Lyna Wiggins Rutgers University May 2008.
Geography 465 Analytic Cartography: Getting Started with Python Scripting.
Introduction to GIS Programming By Jun Liang Department of Geography UNC-CH.
Geography 465 GIS Database Programming Getting Started with GIS Database Programming.
Habitat Analysis in ArcGIS Use of Spatial Analysis to characterize used resources Thomas Bonnot
Python & ModelBuilder. Continuing Education Python and ModelBuilder Overview Python/ModelBuilder Concepts –The Geoprocessor –Checking some environment.
Esri International User Conference | San Diego, CA Technical Workshops | Python – Getting Started Drew Flater, Ghislain Prince July 12 - July 14, 2011.
2006 GIS Jam: ArcGIS Python Scripting
Introduction to InVEST ArcGIS Tool Nasser Olwero GMP, Bangkok April
Writing Geoprocessing Scripts With ArcGIS Lecture 9.
Extending Python Doing more than just interfacing with the geoprocessor Free example utility for NZ Projections Kim Ollivier.
Introduction to Spatial Analysis and Spatial Modeling
Copyright © 2002, 2003, 2004 ESRI. All rights reserved. What's New in ArcGIS 9 Introduction to Geoprocessing in ArcGIS 9 Jason Grootens ESRI-Minneapolis.
Introduction to Python John Reiser May 5 th, 2010.
An Introduction to Visual Basic
Network Analysis with Python
Overview Cursors arcpy.da module Geometrys Arrays SpatialReferences
Introduction to ArcPy. Topics What is ArcPy? Accessing geoprocessing tools using ArcPy Writing scripts using ArcPy.
Python: An Introduction
Using Describe. Topics How to use describe? Retrieving Descriptive Information about data.
ArcGIS Network Analyst: Automating Workflows with Geoprocessing
CE 525. ESRI VIDEO Thanks to Flores we get to watch another video!
Python – Part 1 Python Programming Language 1. What is Python? High-level language Interpreted – easy to test and use interactively Object-oriented Open-source.
Introduction of Geoprocessing Topic 7a 4/10/2007.
ArcGIS: ArcToolbox. Goals Develop familiarity with ArcToolbox Integrated use of the different ArcGIS components in the context of a typical GIS project.
Python, Toolboxes, Tools & Script Tools
Converting workflows from ArcSDE Command line in ArcGIS 10.3.x
Technical Workshops | Esri International User Conference San Diego, California Creating Geoprocessing Services Kevin Hibma, Scott Murray July 25, 2012.
Module 6: Geoprocessing Scripts. Processing loops and decisions.
CE 697V, Project 41 Project 4: Geoprocessing Script November 10, 2006 Kwangbae Kim.
Esri UC 2014 | Technical Workshop | Creating Geoprocessing Services Kevin Hibma.
Introduction of Geoprocessing Lecture 9. Geoprocessing  Geoprocessing is any GIS operation used to manipulate data. A typical geoprocessing operation.
Juanita Cano City of Sacramento Spring 2014 Geography 375.
@2007 Austin Troy Lecture 2: Introduction to the Architecture of ArcGIS By Weiqi Zhou University of Vermont Thanks are due to Prof. Troy, upon whose lecture.
Introduction of Geoprocessing Lecture 9 3/24/2008.
Lecture 10: Geoprocessing with Python (II) Dr. Taysir Hassan Abdel Hamid Associate Professor, Information Systems Dept., Faculty of Computers and Information.
@2007 Austin Troy Lecture 2: Introduction to the Architecture of ArcGIS By Weiqi Zhou University of Vermont Thanks are due to Prof. Troy, upon whose lecture.
Development Environment
Introduction to InVEST ArcGIS Tool
Introduction Presenter: James Zollweg, Ph.D.
Tech Support Tips and Tricks: ArcGIS for Desktop
PYTHON: AN INTRODUCTION
Introduction to ArcGIS
Lab1 Instruction Georeferencing a raster
Lecture 9 Using Python for Geoprocessing
Writing Geoprocessing Scripts With ArcGIS
Geospatial Metadata, Standards and Infrastructure
Programming for Geographical Information Analysis: Advanced Skills
Writing Geoprocessing Scripts With ArcGIS
Python Mr. Husch.
Lecture 5 Geocoding in ArcGIS
Programming for Geographical Information Analysis: Advanced Skills
Geography 465 Managing Custom Python Script Tools
Geography 465 GIS Database Programming
Visual Basic CSC
Network Analysis using Python
PYTHON: BUILDING GEOPROCESSING TOOLS
Network Analyst – Automating Workflows with Geoprocessing
Programming Arc.
Clip & Convert to ASCII Program Kelly Knapp Spring 2010
Presentation transcript:

Lecture 10 Accessing tools and environment setting in Scripts Accessing the Geoprocessor from Python Geoprocessor can be used in many languages: Perl, VBScript, Jscript, Python, VBA, VB, C#, and so on – any COM compliant language. Recall how to use python to access geoprocessor: import arcgisscripting gp = arcgisscripting.create() 2018/11/16 Jun Liang, Geography @ UNC

Previous win32.com compatibility test Following code is from Tim. It can be used to test if win32com object exist or not, then initialize gp accordingly. Alternatively, win32com extension can be found and installed from python.org. With this extension, both win32com scripts and arcgisscripting scripts should work. try: #Using ArcGIS v9.2 import arcgisscripting gp = arcgisscripting.create() print "Using arcgisscripting module" except ImportError: #Using older version that 9.2 import win32com.client gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1") print "Using win32com.client module" 2018/11/16 Jun Liang, Geography @ UNC

Syntax for properties and Methods To assign a value to a property: Object.Property = Value gp.workspace = “C:\” To get the value of a property Object.Property To use a method Object.Method(arg1, arg2,…) Note: Please use ArcGIS Desktop Help to find syntax for methods – Contents->Geoprocessing->Geoprocessing tool reference 2018/11/16 Jun Liang, Geography @ UNC

Jun Liang, Geography @ UNC Toolbox aliases Since different toolset may contain similar methods with same name, you will need to use suffix to label each method, or define a toolset before you call that method. gp.Buffer_analysis() gp.Select_analysis(…) gp.Clip_analysis(…) 2018/11/16 Jun Liang, Geography @ UNC

Jun Liang, Geography @ UNC More tool examples Clip_management(in_rast, recangle, out_raster) Union_analysis(in_features, out_features, join_attributes, cluster_tolerance, gaps) Select_analysis(in_features,out_features,whereclause) 2018/11/16 Jun Liang, Geography @ UNC

Jun Liang, Geography @ UNC Accessing Toolboxes For non-system toolboxes: gp.AddToolBox(“d:\Arctools\MarketTools.tbx”) gp.MarketDelineation() gp.RemoveToolbox(“d:\Arctools\MarketTools.tbx”) 2018/11/16 Jun Liang, Geography @ UNC

Accessing Toolboxes (Cont.) 2018/11/16 Jun Liang, Geography @ UNC

Accessing Toolboxes (Cont.) To find help for a geoprocessor method/property: - Writing geoprocessing scripts->Scripting Object->IGPDispatch->A particular Method 2018/11/16 Jun Liang, Geography @ UNC

Accessing Toolboxes (Cont.) Exercises: Find the usage of “gp.Exists” and use it to test if a dataset is available in your storage space. Check the usage of “addxy” under Data Management Toolbox and apply it to point feature class. 2018/11/16 Jun Liang, Geography @ UNC

Geoprocessor Programming Model From Geoprocessor you can get other objects – similar to pxDocument, from which you can get map, layer, etc. Each box represents an object. 2018/11/16 Jun Liang, Geography @ UNC

Jun Liang, Geography @ UNC The Describe Object To get help for describe object, you can find it in two places – geoprocessor.pdf ArcGIS online help The describe method for gp (geoprocessor object) will return an object, based on the input value. And data type of the output object can be used for script flow control. 2018/11/16 Jun Liang, Geography @ UNC

The Describe Object (Cont.) From ArcGIS Online Help, We can get: Describe Method Similar to the ArcINFO Describe command, it details such properties as type, name, spatial reference, domains, versioning, etc., for DataElements such as FeatureClasses, Tables, GeoDatasets, CoverageFeatureClasses, Datasets, RelationshipClasses, Files, Layers, Workspaces, as well as GP objects such as TableViews, and FeatureLayers. Syntax object.Describe(inputValue) as Object Part Description Object The instantiated geoprocessing object. inputValue The name of the DataElement, or GPObject, to be described. If the workspace is not set you must include the path as well as the name. 2018/11/16 Jun Liang, Geography @ UNC

The Describe Object (Cont.) Objects FeatureClass, Coverage FeatureClass,Layer,Table , Dataset ,TableView , Workspace, Coverage, Relationship Class ,Raster Catalog , Raster Dataset Raster Band Examples import arcgisscripting gp = arcgisscripting.create() gp.workspace = “s:/data/python/mdb/Tongass.mdb" fc = “stands” dsc = gp.describe(fc) print "Describing:", fc print "FeatureType:" print dsc.FeatureType print "TopologyName:" print dsc.TopologyName …… 2018/11/16 Jun Liang, Geography @ UNC

Jun Liang, Geography @ UNC 2018/11/16 Jun Liang, Geography @ UNC

The Describe Object (Cont.) All describe objects can use the Describe Object Properties. It can be used to check its datatype and then perform datatype related process: if dscfc1.datatype == “FeatureClass”” … elif dscfc1.datatype == “”Table” else: 2018/11/16 Jun Liang, Geography @ UNC

The Describe Object (Cont.) Dataset properties Import arcgisscripting gp = arcgisscripting.create() gp.workspace = "k:/data/python/mdb/Tongass.mdb" fc1 = “stands” Dscfc1 = gp.Describe(fc1) Print Dscfc1.DatasetType fc2 = “NestsF” Dscfc2 = gp.Describe(fc2) Print Dscf2.DatasetType If dscfc2.DatasetType == “FeatureDataset”: 2018/11/16 Jun Liang, Geography @ UNC