scripting arcgis

Upload: ravindhar-black

Post on 07-Apr-2018

239 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/6/2019 Scripting Arcgis

    1/27

    Scripting/Automating/Scripting/Automating/

    Customizing ArcGISCustomizing ArcGIS

    And other ways of streamliningAnd other ways of streamliningyour workflowyour workflow

    Tom SchwartzmanTom Schwartzman

    ESRI BostonESRI Boston

    July 13, 2005July 13, 2005

  • 8/6/2019 Scripting Arcgis

    2/27

    GoalsGoals

    Learn about:Learn about:

    Geoprocessing (automation)Geoprocessing (automation)

    Scripting (automation)Scripting (automation)

    CustomizingCustomizing

  • 8/6/2019 Scripting Arcgis

    3/27

    ExpectationsExpectations

    WeWere not going write code todayre not going write code today

    We will look at some samples andWe will look at some samples and

    learn how to install themlearn how to install them

    This is basic/intermediate userThis is basic/intermediate user--levellevel

  • 8/6/2019 Scripting Arcgis

    4/27

    Geoprocessing FrameworkGeoprocessing Framework ToolsTools CommandsCommands ModelsModels ScriptsScripts Analysis platformAnalysis platform FlexibleFlexible ExtendableExtendable

  • 8/6/2019 Scripting Arcgis

    5/27

    ArcToolboxArcToolbox

    AA dockabledockable window in ArcMap andwindow in ArcMap and

    ArcCatalogArcCatalog

  • 8/6/2019 Scripting Arcgis

    6/27

    ArcToolboxArcToolbox

    Can create your own toolboxesCan create your own toolboxes

    Store on disk or in a geodatabaseStore on disk or in a geodatabase

    Holds tools and modelsHolds tools and models

    Can be shared with othersCan be shared with others

  • 8/6/2019 Scripting Arcgis

    7/27

    The Command LineThe Command Line

    ItIts back, and hass back, and hasintellisenseintellisense

  • 8/6/2019 Scripting Arcgis

    8/27

    Using ModelbuilderUsing Modelbuilder Models are created inModels are created in

    the Modelbuilder windowthe Modelbuilder window

    Color coded by objectColor coded by objecttypetype DataData ToolTool

    ResultResult Models can be convertedModels can be converted

    to scriptsto scripts PythonPython

    vbScriptvbScript JscriptJscript

    Run processes in batchRun processes in batch

  • 8/6/2019 Scripting Arcgis

    9/27

    Modelbuilder FunctionalityModelbuilder Functionality Models can be made flexible with parameters thatModels can be made flexible with parameters that

    can be input at run timecan be input at run time Variables can hold user defined constantsVariables can hold user defined constants Tests of conditions can be used for branchingTests of conditions can be used for branching Preconditions can be set on processesPreconditions can be set on processes Models can call other ModelsModels can call other Models

  • 8/6/2019 Scripting Arcgis

    10/27

    Adding DataAdding Data Add featureAdd feature

    classes toclasses to

    modelmodel Drag andDrag andDropDrop

    Add from fileAdd from filesystemsystem

    Add LayerAdd Layerfrom ArcMapfrom ArcMap

  • 8/6/2019 Scripting Arcgis

    11/27

    Adding ToolsAdding Tools Add tools toAdd tools to

    modelmodel

    Drag andDrag andDrop fromDrop fromToolboxToolbox

    ConnectConnectpiecespieces

  • 8/6/2019 Scripting Arcgis

    12/27

    Model ParametersModel Parameters Data and variablesData and variables

    can be used ascan be used as

    model parametersmodel parameters Data to be input atData to be input atrun timerun time

    Data to be outputData to be outputat the end toat the end to

    another destinationanother destination

  • 8/6/2019 Scripting Arcgis

    13/27

    Variables and PreconditionsVariables and Preconditions Variables hold constantVariables hold constant

    values, or can be set asvalues, or can be set asparametersparameters

    Preconditions determinePreconditions determinethe order of execution forthe order of execution forprocessesprocesses Drawn in diagram with aDrawn in diagram with a

    dashed linedashed line

  • 8/6/2019 Scripting Arcgis

    14/27

    Export from ModelbuilderExport from Modelbuilder Models can beModels can be

    converted to scriptsconverted to scripts

    PythonPython vbScriptvbScript JscriptJscript

    Scripts cannot thenScripts cannot then

    be exported back tobe exported back tomodelsmodels Modified Script canModified Script can

    then be added as athen be added as aScript Tool in aScript Tool in atoolboxtoolbox

  • 8/6/2019 Scripting Arcgis

    15/27

    Introduction to PythonIntroduction to Python Free and powerful scripting languageFree and powerful scripting language

    Interactive execution window:Interactive execution window: PythonWinPythonWin Basic development environment: IDLEBasic development environment: IDLE

    Widely accepted scripting languageWidely accepted scripting language Can do many tasks in addition to working with theCan do many tasks in addition to working with the

    geoprocessing (geoprocessing (gpgp) framework) framework Python PagePython Page http://http://www.python.orgwww.python.org

    Microsoft PageMicrosoft Pagehttp://www.microsoft.com/technet/scriptcenter/schttp://www.microsoft.com/technet/scriptcenter/scripts/python/default.mspxripts/python/default.mspx contains list of Windowscontains list of Windowssamples scriptssamples scripts

    Easy to learn, simple syntaxEasy to learn, simple syntax

    Lots of good books out thereLots of good books out there OOReilly Press: Learning PythonReilly Press: Learning Python good for beginnersgood for beginners OOReilly Press: Programming PythonReilly Press: Programming Python good referencegood reference

  • 8/6/2019 Scripting Arcgis

    16/27

    The Python scripting languageThe Python scripting language What is Python?What is Python?

    An openAn open--source, objectsource, object--oriented, scriptingoriented, scriptinglanguagelanguage

    Can view and modify source codeCan view and modify source code

    Easy to useEasy to use

    Why use Python?Why use Python? Offers IDEs with debugging toolsOffers IDEs with debugging tools

    Modular, can be broken apartModular, can be broken apart

    Cross platformCross platform

    Ability to compile scriptsAbility to compile scripts

    Installed with ArcGIS 9 and ESRI samplesInstalled with ArcGIS 9 and ESRI samples

    providedprovided

    Python

    script

    Python

    script

  • 8/6/2019 Scripting Arcgis

    17/27

    Writing Python ScriptsWriting Python Scripts Python scripts canPython scripts can

    be written inbe written inNotepad, or anyNotepad, or any

    text editor, free,text editor, free,shareware, or paidshareware, or paid TextPadTextPad UltraEditUltraEdit KomodoKomodo

    PythonWinPythonWin andandIDLE come with theIDLE come with theinstallationinstallation Environments toEnvironments to

    write, save, run, andwrite, save, run, and

    debug codedebug code

    Samples useSamples usePythonWinPythonWin

  • 8/6/2019 Scripting Arcgis

    18/27

    User Interface CustomizationUser Interface Customization Toolbars andToolbars and

    some windowssome windowsareare dockabledockable

    Double clickDouble click

    title to autotitle to auto--dock/undockdock/undock

    Hold CTRL keyHold CTRL key

    down to avoiddown to avoidautoauto--dockingdocking

  • 8/6/2019 Scripting Arcgis

    19/27

    ToolbarsToolbars Change locations of buttons/tools,Change locations of buttons/tools,

    delete/add buttons/toolsdelete/add buttons/tools

    Create your own toolbar with your choiceCreate your own toolbar with your choice

    of buttons/toolsof buttons/tools

    Available by usingAvailable by usingCustomizeCustomizedialogdialog

    ToolsTools

    CustomizeCustomize DoubleDouble--click in empty area of toolbarclick in empty area of toolbar

    RightRight--click and chooseclick and chooseCustomizeCustomize

  • 8/6/2019 Scripting Arcgis

    20/27

  • 8/6/2019 Scripting Arcgis

    21/27

    ToolbarsToolbars

    Lots of useful buttons/tools exist butLots of useful buttons/tools exist but

    are not on any toolbar.are not on any toolbar.

    Examples:Examples: Clear SelectedClear Selected

    Zoom to SelectedZoom to Selected

    Continuous ZoomContinuous Zoom

  • 8/6/2019 Scripting Arcgis

    22/27

    SamplesSamples Lots of samples out there from:Lots of samples out there from:

    ESRI (Developer Kit CD, onlineESRI (Developer Kit CD, online

    http://http://edn.esri.comedn.esri.com))

    Users (Users (http://arcscripts.esri.comhttp://arcscripts.esri.com))

    Some are VBA scripts (pasted intoSome are VBA scripts (pasted into

    VBA editor in ArcMap) and run from aVBA editor in ArcMap) and run from a

    buttonbutton--clickclick

  • 8/6/2019 Scripting Arcgis

    23/27

    SamplesSamples Some are simply added usingSome are simply added usingAddAdd

    from filefrom filein the Customize Dialogin the Customize Dialog

  • 8/6/2019 Scripting Arcgis

    24/27

    SamplesSamples Some come with an installer of some sortSome come with an installer of some sort

    (batch file, exe, etc)(batch file, exe, etc) And some need more help gettingAnd some need more help getting

    registeredregistered..

    Regsvr32.exe to register the compiled .Regsvr32.exe to register the compiled .dlldll withwiththe systemthe system

    Categories.exeCategories.exe to tell ArcGIS what part of theto tell ArcGIS what part of the

    system it belongs in (e.g. sketch tool,system it belongs in (e.g. sketch tool,

    rendererrenderer, etc), etc)

    Hopefully this is documented with theHopefully this is documented with the

    sample!sample!

  • 8/6/2019 Scripting Arcgis

    25/27

    TemplatesTemplates Predefined map layouts that can bePredefined map layouts that can be

    imported into your current docimported into your current doc

    Your layout will change to match theYour layout will change to match thetemplatetemplate

    You may lose/gain elements (legend,You may lose/gain elements (legend,

    north arrow, etc)north arrow, etc) You wonYou wont lose datat lose data

  • 8/6/2019 Scripting Arcgis

    26/27

    TrainingTraining Instructor Led:Instructor Led:

    Intro to ArcObjects: Aug 15Intro to ArcObjects: Aug 15--1919 Intro to Python: Sep 8Intro to Python: Sep 8--99

    Virtual Campus:Virtual Campus: Customizing ArcGIS 9Customizing ArcGIS 9 Customizing ArcMapCustomizing ArcMap

    Exploring VBAExploring VBA

    Working with Forms in VBAWorking with Forms in VBA

    Working with Variables and Functions in VBAWorking with Variables and Functions in VBA

  • 8/6/2019 Scripting Arcgis

    27/27