Introduction to ArcGIS Desktop and ArcGIS Engine Development

Document Sample
Introduction to ArcGIS Desktop and ArcGIS Engine Development Powered By Docstoc
					Introduction to ArcGIS Desktop and ArcGIS Engine
                   Development


                   Mike Rudden
                  Innes Mackenzie




                                         ESRI Developer Summit 2008   1
Schedule

• 4 hour session
  – 1 official break


• Please ask questions at any time


• Please complete the session survey – we take your
  feedback seriously




                                               ESRI Developer Summit 2008   2
Session Objectives

• Gain an understanding of ArcObjects and how they
  can be used to customize ArcGIS Desktop or to build
  an ArcGIS Engine application


• Some specific aims:
  – Write ArcObjects code to access a file geodatabase feature
    class and add it to a map as a layer
  – Build a simple ArcGIS Engine MapControl application
  – Create a custom command that will work in both ArcGIS
    Desktop and ArcGIS Engine




                                                          ESRI Developer Summit 2008   3
                                    Object
             Understanding          Model
              ArcObjects           Diagrams
Product
Overview                                         Developer
                                                 Resources




  Custom                                      Development
Components                                    Environments
               Engine
              Controls         Desktop
                Apps         Customization
                                Using
                                 VBA

                                                   ESRI Developer Summit 2008   4
ArcGIS Desktop: for GIS users
• ArcMap, ArcCatalog, ArcScene, ArcGlobe   Windows
                                           Windows




• License Levels
 – ArcView
 – ArcEditor
 – ArcInfo
                                            ESRI Developer Summit 2008   5
ArcGIS Desktop: for developers

• ArcGIS Desktop is built using ArcObjects

• All ArcGIS Desktop applications can be customized
  using ArcObjects

• Embedded Visual Basic for Applications (VBA)

• ArcGIS Desktop Developer kit
  – Developer help system
    and samples
  – API’s for COM & .NET
  – Developer Tools
  – VB6 Addins
  – IDE integration
    into Visual Studio .NET
                                                 ESRI Developer Summit 2008   6
ArcGIS Engine: for developers

• Deployment: ArcGIS Engine Runtime
 – 2 levels of product licensing available:
    – Standard Runtime = ArcView              Windows, Solaris, Linux (Intel)
                                              Windows, Solaris, Linux (Intel)
    – Geodatabase Update = ArcEditor
    – + extensions - 3D Analyst, Network Analyst…


• Development: ArcGIS Engine Developer kit
 – ArcGIS Engine Runtime
 – Developer help system
   and samples
 – API’s for COM , .NET, Java, C++
 – Visual development components
 – IDE integration into Visual Studio .NET
                                                                 ESRI Developer Summit 2008   7
What you can do with ArcGIS Engine…




                                Non-visual

 Standalone
                                  Embedded
                                  applications



                                        Develper Summit 2008   8
Why Customize?

 • ArcGIS Desktop: Specialize the applications

 • ArcGIS Engine: Add GIS functionality to an application

 • Add functionality to
   – Manage data
   – Editing
   – Analysis
   – Symbolization
   – Layout and output …

 • Streamline work flow



Demo
                                                 ESRI Developer Summit 2008   9
The ArcGIS System
Applications     ArcGIS                ArcGIS          ArcGIS              Web                     ArcGIS
                 Desktop               Engine          Explorer          Mapping                   Mobile
                                                                        Application



               Desktop            Engine
               Developer Kit      Developer Kit      API                API                   SDK
                .NET   COM         .NET   COM         .NET               .NET     Java         .NET
                                      C++    Java

                    ArcObjects              ArcGIS    Server                        ArcGIS Online
                                            Server    Developer Kit
Services
                                                       .NET      COM              ArcWeb Services
                                                             Java
                                                                            API
                                                          ArcSDE                REST     J2ME         JavaScript
                                                        technology
                                                                            OpenLS       SOAP
                 Desktop




                                                                                                                 ArcSDE
Data                       Personal
(Geodatabase)               for MS           File
                                             File            Personal   Workgroup        Enterprise
                            Access

                                                                                            ESRI Developer Summit 2008    10
                                    Object
             Understanding          Model
              ArcObjects           Diagrams
Product
Overview                                         Developer
                                                 Resources




  Custom                                      Development
Components                                    Environments
               Engine
              Controls         Desktop
                Apps         Customization
                                Using
                                 VBA

                                                   ESRI Developer Summit 2008   11
ArcGIS & ArcObjects

• ArcObjects are
  software components

• ArcObjects is not a
  product, by itself

• ArcGIS is built using
  ArcObjects

• Developers use
  ArcObjects to
  customize or build
  applications

                          ESRI Developer Summit 2008   12
How ESRI Builds ArcObjects
                                      C++ source code
                                       Class Libraries
                                        Binary DLLs
                                     ArcGIS\bin directory

                                 C++ type information
                                    Type Libraries
               Build Process           OLB files
                                 ArcGIS\com directory

                                          COM API




          .NET API        JAVA API             C++ API

                                                   ESRI Developer Summit 2008   13
ArcGIS Products share ArcObjects




         ArcGIS Desktop    ArcGIS Engine

                                           ESRI Developer Summit 2008   14
ArcObjects libraries
• Logical groupings of functionality
• Product, extensions and license determine availability

                      Controls

                       Carto


                 Geodatabase, Carto


             Geodatabase, DataSourcesFile

              Geometry, Display, System


Demo                                           More …
                                                  ESRI Developer Summit 2008   15
ArcObjects Classes

• Grouped into over 70 libraries
• Over 3,400 ArcObjects classes
• Over 21,00 properties and methods



Map
                                         Geometry

                                          Point
Layer

                                        Polygon

  Carto



                                      ESRI Developer Summit 2008   16
ArcObjects Classes

• All ArcObjects are COM classes
 – Program using interfaces
 – Properties and methods never change
 – New interfaces may be added
 – Use any COM-compliant language
                                             Map
                                    IMap    Name
                                            AddLayer
                                            DeleteLayer
                              IActiveView   Extent
                                            Refresh




                                                      ESRI Developer Summit 2008   17
Working with ArcObjects COM classes
• Reference appropriate libraries:
  – COM - type libraries OLB’s
  – .NET - assemblies (PIA’s)
  – Java - jar files
  – C++ - header files (.h)

• Using ArcObjects types in .NET:
 'Without importing the namespace
 Dim activeView As ESRI.ArcGIS.Carto.IActiveView

 'Visual Basic .NET keyword > Imports
 Imports ESRI.ArcGIS.Carto
 Dim activeView As IActiveView

 //Visual C# .NET keyword > using
 using ESRI.ArcGIS.Carto;
                                               ESRI Developer Summit 2008   18
Working with ArcObjects COM classes

• Instantiate COM classes with an interface
  – Dim <variable> As <interface>
• Must create New or instantiate
  ' VB.NET
  ' Creating a new map
  Dim map As IMap = New Map

  ' Using the map from a map document
  Dim map As IMap
  map = axMapControl1.ActiveView.FocusMap

  ' Use properties/methods on IMap
  map.Name = “My map”



                                              ESRI Developer Summit 2008   19
Working with ArcObjects COM classes
                                                 Map
• Move between interfaces              IMap    Name
  – Use Query Interface in COM                 Add Layer
                                      'QI
  – Use casting in .NET                        Clear Selection
                                 IActiveView   Extent
' VB 6                                         Refresh
Dim map As IMap
Set map = axMapControl1.ActiveView.FocusMap
Dim av As IActiveView
Set av = map 'QI
av.Refresh

IActiveView av = map as IActiveView; // C#

Dim av As IActiveView = CType(map, IActiveView) 'VB .NET

Demo
                                                   ESRI Developer Summit 2008   20
Review
• What are interfaces?
  – Logical groups of properties and methods

• What does QI stand for?
  – QueryInterface

• Why would you use QI?
  – To access the properties and methods of another interface on
    the same object

• Complete the following:
    'VB .NET
                 ?         ?
    Dim map As IMap = New Map
    map.Name = “My map”


                                                         ESRI Developer Summit 2008   21
                                    Object
             Understanding          Model
              ArcObjects           Diagrams
Product
Overview                                         Developer
                                                 Resources




  Custom                                      Development
Components                                    Environments
               Engine
              Controls         Desktop
                Apps         Customization
                                Using
                                 VBA

                                                   ESRI Developer Summit 2008   22
Understanding Object Model Diagrams
• Conceptually only 1 diagram
  – Spread over many for viewing and printing purposes
• Represents the contents of type libraries




                                                         ESRI Developer Summit 2008   23
Properties, Methods and Events

• Interfaces contain properties, methods and events
• Properties:
  – Read/Write
  – Read Only
  – Write Only
  – Write (by ref)


• Methods:
  – Methods


• Events:
  – Events
                                              ESRI Developer Summit 2008   24
                                                                           -
Coclasses

• Creatable: use the New keyword
  Dim map As IMap = New Map


• Instantiable: obtain from other objects
  Dim map As IMap
  map = mapDoc.ActiveView.FocusMap




     OMD symbol:
  3D shaded rectangle


                                            ESRI Developer Summit 2008   25
Classes
• Instantiable class
  – Cannot create with New keyword
• Obtain instances from other objects
  ‘ VB.NET
  Dim newRow As IRow
  newRow = aTable.CreateRow()




  OMD symbol:
  3D unshaded
    rectangle

                                        ESRI Developer Summit 2008   26
Abstract classes
• Not creatable or instantiable
  – Can never have instances of an
    abstract class
• Define general interfaces for
  subclasses
  – Subclasses inherit interfaces




       OMD symbol:
   2D unshaded rectangle

                                     ESRI Developer Summit 2008   27
OMD relationship symbols

• UML notation:

        Is a type of

        Is composed of

        Creates a

        Multiplicity
                                *
        Association           _____

        Wormhole (not UML)

        In Conjunction with

                                      ESRI Developer Summit 2008   28
OMD Relationships: MapDocument objects
                                             ArcMap
                                             ArcMap


 MapDocument




         *
     Map
                                    ArcGIS Engine
                                    ArcGIS Engine

        *
     Layer




FeatureLayer   RasterLayer


                                      ESRI Developer Summit 2008   29
OMD Relationships: Geodatabase objects




Demo
                                         ESRI Developer Summit 2008   30
Implementation (“Type of” ) Inheritance

• Occurs when abstract classes are present
• Similar to accessing other interfaces on an object
• Access additional interfaces using a QI
 Dim topoLayer As ITopologyLayer
 topoLayer = New TopologyLayer
 'Assign topology layer properties
 topoLayer.Renderer = topoRenderer

 'Assign some general properties
 Dim aLayer As ILayer
 aLayer = CType(topoLayer, Ilayer)
 aLayer.Name = "Cadastral Topology"
 aLayer.ShowTips = False


                                                  ESRI Developer Summit 2008   31
Interface Inheritance
• Access additional interfaces without a QI
• Check right side of interface
  – If another interface is listed:
    • Can access its members on one variable
    • Do not need to QI
  Dim rasterLayer As IRasterLayer
  rasterLayer = New RasterLayer
  'Assign raster property
  rasterLayer.Raster = raster

  'Assign some general properties
  rasterLayer.Name = "My layer"
  rasterLayer.Visible = False


Demo
                                               ESRI Developer Summit 2008   32
Exercise: Add a layer to MapControl

• Using the handout provided write out the ArcObjects
  code to add a file geodatabase featureclass to a
  MapControl as a layer




Demo
                                                ESRI Developer Summit 2008   33
Pseudo Code: Add layer to the MapControl

Access the ActiveView from the MapControl

Access the FocusMap on the ActiveView

Make a new FileGDBWorkspaceFactory object

Get a Workspace from the FileGDBWorkspaceFactory

Get the FeatureClass from the Workspace

Make a new FeatureLayer object

Set the FeatureClass for the FeatureLayer

Assign the Name and ShowTips properties

Add the FeatureLayer to the FocusMap



                                            ESRI Developer Summit 2008   34
Dim activeView As IActiveView
activeView = axMapControl1.ActiveView

Dim focusMap As IMap
focusMap = ?activeView.FocusMap

Dim fileGDBWSF As IWorkspaceFactory =
                    New FileGDBWorkspaceFactory

Dim workspace As IWorkspace
workspace = fileGDBWSF. OpenFromFile("C…TemplateData.gdb",0)
                        ?

Dim fws As IFeatureWorkspace
               ?
fws = CType( workspace , IFeatureWorkspace)

Dim featClass As IFeatureClass
featClass = fws.OpenFeatureClass(“States")

Dim featLayer As IFeatureLayer = New FeatureLayer
featLayer.FeatureClass = ? featClass
featLayer.Name = “USA States"
featLayer.ShowTips = True

focusMap.AddLayer(featLayer)
                                                  ESRI Developer Summit 2008   35
Review

• What is the difference between a class and a coclass?
  – Coclass: create with New keyword or obtain from another object
  – Class: obtain instances from another object


• Describe interface inheritance?
  – No QI required, members of inherited interfaces available
    directly


• Describe Implementation “type of” inheritance
  – When abstract class is present
  – QI required: similar to accessing other interfaces on an object


                                                           ESRI Developer Summit 2008   36
                                    Object
             Understanding          Model
              ArcObjects           Diagrams
Product
Overview                                         Developer
                                                 Resources




  Custom                                      Development
Components                                    Environments
               Engine
              Controls         Desktop
                Apps         Customization
                                Using
                                 VBA

                                                   ESRI Developer Summit 2008   37
ESRI Developer Network (EDN)

• Software Library:
  – ArcGIS Engine (Developer Kit & 1 Runtime)
  – ArcGIS Dektop: ArcView or ArcEditor (optional extra)
  – ArcGIS Server
  – … many other products


• EDN website
  – http://edn.esri.com


• Technical Support & Training

             For Development and Testing Only
Demo                                                       ESRI Developer Summit 2008   38
Key Resources

 • ArcGIS Desktop & ArcGIS Engine Developer Help
   – How to Documents
   – Samples
   – Snippets (.NET)


 • ESRI Training course
   – Virtual campus or classroom course
   – http://campus.esri.com

 • ESRI Press
   – ArcGIS Engine Developer’s Guide: ArcGIS 9
   – ArcGIS Desktop Developer’s Guide: ArcGIS 9
   – Getting to know ArcObjects by Rob Burke (ArcGIS 9.x)

Demo                                                    ESRI Developer Summit 2008   39
                                    Object
             Understanding          Model
              ArcObjects           Diagrams
Product
Overview                                         Developer
                                                 Resources




  Custom                                      Development
Components                                    Environments
               Engine
              Controls         Desktop
                Apps         Customization
                                Using
                                 VBA

                                                   ESRI Developer Summit 2008   40
Supported ArcGIS Product APIs

• Desktop APIs (COM and .NET)
  – VBA – customize documents (MXD and MXT)
  – Custom components (dll’s) – commands, tools, windows,
    extensions


• Engine APIs (COM, .NET, Java and C++)
  – Build custom stand-alone applications (exe’s)
  – Embed into existing applications
  – Custom components (dll’s) – commands, tools, windows,
    extensions




                                                      ESRI Developer Summit 2008   41
Platforms – 9.2 Release
• ArcGIS Desktop
  – Windows 2000
  – Windows 2003 Server (& Terminal Server)
  – Windows XP
  – Vista (support added at 9.2 sp2)


• ArcGIS Engine
  – All windows operating systems listed above
  – Linux - Intel Red Hat – 3 & 4
  – Linux - Intel SUSE - 9
  – SUN Solaris 10
  – SUN Solaris 9


                                                 ESRI Developer Summit 2008   42
APIs and Development Environments

• COM
  – Visual Studio 6.0 (VB, VC++)
  – Visual Studio .NET (VC++)
• .NET
  – Visual Studio .NET (VB.NET, C#, VC++)
  – 9.1 PIA’s compiled against .NET 1.0
  – 9.2 PIA’s compiled against .NET 2.0
  – Visual Studio 2008 will be supported at 9.3
• C++
  – Linux/Solaris - Any as long as use a supported compiler.
  – Windows – Visual Studio 2005
• Java
  – JBuilder, Eclipse (has templates), JDK
                                                          ESRI Developer Summit 2008   43
Choosing an API and Development Environment

• Type of application
• Programming skill
• Performance
• Platform
• Deployment and distribution




                                      ESRI Developer Summit 2008   44
                                    Object
             Understanding          Model
              ArcObjects           Diagrams
Product
Overview                                         Developer
                                                 Resources




  Custom                                      Development
Components                                    Environments
               Engine
              Controls         Desktop
                Apps         Customization
                                Using
                                 VBA

                                                   ESRI Developer Summit 2008   45
Customizing ArcGIS Desktop with VBA

• Use VBA to extend ArcMap/ArcCatalog
• Create custom
  user forms,
  buttons and
  tools
• Automate
  workflows




                                        ESRI Developer Summit 2008   46
ArcObjects starting points in VBA

• These two objects are always available in VBA:
  – Application
  – MxDocument (ArcMap)



   Application - - - - - - - >




  ThisDocument - - - - - >



 Demo
                                                   ESRI Developer Summit 2008   47
Customizing the Desktop with VBA

• Advantages                       • Disadvantages
  – Free!                           – Can not write COM
  – Easy to write macros and          components
    scripts                         – Can not create extensions or
  – Easy to debug                     advanced customization
  – Easy to distribute              – Code is not a binary
  – Use all ArcObjects available




                                                          ESRI Developer Summit 2008   48
                                    Object
             Understanding          Model
              ArcObjects           Diagrams
Product
Overview                                         Developer
                                                 Resources




  Custom                                      Development
Components                                    Environments
               Engine
              Controls         Desktop
                Apps         Customization
                                Using
                                 VBA

                                                   ESRI Developer Summit 2008   49
ArcGIS Engine Controls
Design time
Design time                                           PageLayoutControl
                                                      PageLayoutControl
                                    ToolbarControls
                                    ToolbarControls


LicenseControl
LicenseControl



                                                                Run time
                                                                Run time
 TOCControl
 TOCControl




 MapControl
 MapControl




                 Other Controls:
                 Other Controls:

                 SymbologyControl
                 SymbologyControl
                 GlobeControl
                 GlobeControl
                 SceneControl
                 SceneControl
                                                           ESRI Developer Summit 2008   50
ArcGIS Engine Control Commands

• Individual user-interface components
  – Open and save map documents (.mxd, .mxt, .lyr)
  – Add Data (SDE data support with 9.2 sp2)
  – Map Navigation (2D & 3D)
  – Online Services
  – Editing
  – Page Layout
  – Ink
  … many more




                                                     ESRI Developer Summit 2008   51
Building ArcGIS Engine applications

1. Start a new project
       • Add Engine controls manually
       • Use IDE integration tools (.NET, Java)


2. License the application


3. Add controls, commands and tools




DEMO
                                                  ESRI Developer Summit 2008   52
Geoprocessing

• New Geoprocessing coarse grained framework and
  tools
• New API for .NET developers
• Run existing tools, scripts and models
• Author new tools
• Be aware of licensing level




                                            ESRI Developer Summit 2008   53
                                    Object
             Understanding          Model
              ArcObjects           Diagrams
Product
Overview                                         Developer
                                                 Resources




  Custom                                      Development
Components                                    Environments
               Engine
              Controls         Desktop
                Apps         Customization
                                Using
                                 VBA

                                                   ESRI Developer Summit 2008   54
Custom Components
• Powerful mechanism for extending functionality
• Use stand alone programming language


                                             Command
                                             Command
                     Toolbar
                     Toolbar


           Menubar
           Menubar


                                         Extension
                                         Extension




                                                 ESRI Developer Summit 2008   55
Customization Options

     Commands     Tools   Menus    Palettes    Toolbars   Editor

            Dockable windows    Propertypages     Views

                       Document persistence

                            Extensions


                   Custom features and workspaces

                      Custom layers   Renderers

                   Geodatabase class extensions

N.B. ArcGIS Engine Only, ArcGIS Desktop Only

                                                          ESRI Developer Summit 2008   56
Custom Components

• Create a COM class and implement one or more
  interfaces


                                 esriControls         IUnknown



                                ICommand
                                                 ZoomInTool




                                 yourLibrary          IUnknown



                                ICommand
                                                yourCommand




                                                        ESRI Developer Summit 2008   57
General Steps for Writing Custom Components

•   The steps are the same regardless of the
    development environment
     1. Create a project (class library > dll)
     2. Create a class
     3. Reference the ArcGIS libraries
     4. Implement an interface
     5. Compile and register


     Optional:
     6. Register in a component category (N.B windows only)




                                                      ESRI Developer Summit 2008   58
ESRI Component Categories
• Folders in the registry
• Organizes all ArcGIS components that are loaded at
  run-time
• Browsing tools
  – RegEdit.exe
  – Categories.exe (ESRI – ArcGIS Desktop only, ..\ArcGIS\bin)
• Examples:
  – ArcGIS Engine Command - - > ESRI Controls Commands
  – ArcMap Command           - - > ESRI Mx Commands
  – ArcCatalog Command       - - > ESRI Gx Commands




Demo
                                                         ESRI Developer Summit 2008   59
Commands: Implement the ICommand interface

• Commands perform an action on a button click
• OnCreate called during startup passing in a ‘hook’
  – In ArcMap the is the ArcMap application
  – In ArcGIS Engine it may be the ToolbarControl




                            ICommand
                                       MySmileCmd

Demo
                                                    ESRI Developer Summit 2008   60
Custom tools also implement ITool

• Commands that listen for
  mouse and key events
• Allows users to interact with maps
• Examples                             Default    Custom
  – Map interaction: Tracking          Sketch     sketch tool
                                       palette    in palette
  – Analysis: Select features
  – Editing tools




                                                 ESRI Developer Summit 2008   61
Custom toolbars

• Container to show commands, tools, and menus
• Implement IToolbarDef
• Example
  – Show or hide a custom set of tools




      IToolbarDef
                    MyToolbar




                                             ESRI Developer Summit 2008   62
Implementing COM extensions

• Extensions can be used to share
  data between software components


• Interfaces: IExtension, IExtensionConfig


• Type Library: esriSystem


• State of commands is
  controlled by state of
  extension                Public Class ZoomExtension
                            Public Class ZoomExtension
                              Implements IExtension
                               Implements IExtension
                              Implements IExtensionConfig
                               Implements IExtensionConfig


                                                       ESRI Developer Summit 2008   63
Review

• ArcMap and ArcGIS Engine custom commands may be
  registered in which component categories?
  – ArcMap             ESRI Mx Commands
  – ArcGIS Engine      ESRI Controls Commands


• Which interfaces must be implemented to create a
  custom tool ?
  – ICommand and ITool


• What sort of project would you create for custom
  components?
  – Class library which will be compiled into a dll

                                                      ESRI Developer Summit 2008   64
                                    Object
             Understanding          Model
              ArcObjects           Diagrams
Product
Overview                                         Developer
                                                 Resources




  Custom                                      Development
Components                                    Environments
               Engine
              Controls         Desktop
                Apps         Customization
                                Using
                                 VBA

                                                   ESRI Developer Summit 2008   65
Session Objectives

• Gain an understanding of ArcObjects and how they
  can be used to customize ArcGIS desktop or to build
  an ArcGIS engine application


• Some specific aims:
  – Write ArcObjects code to access a file geodatabase feature
    class and add it to a map as a layer
  – Build a simple ArcGIS Engine MapControl application
  – Create a custom command that will work in both ArcGIS
    Desktop and ArcGIS Engine




                                                          ESRI Developer Summit 2008   66
Developers Road Map to ArcGIS Desktop and ArcGIS Engine
–   Tuesday, March 18, 1:00pm-2:15pm

Migrating VBA/VB6 ArcObjects Applications to .NET
–   Tuesday, March 18, 1:00pm-2:15pm

Developing .NET Applications for ArcGIS Engine
–   Tuesday, March 18, 2:45pm-4:30pm

Developing Desktop Applications with Geoprocessing Framework
–   Wednesday, March 19, 10:30am-11:45am

Extending the ArcGIS Desktop Applications
–   Wednesday, March 19, 10:30am-11:45am
–   Wednesday, March 19, 2:45pm-4:00pm      Session Surveys
                                             EDN Website
Deploying Desktop Applications
–   Wednesday, March 19, 1:00pm-2:15pm
                                                    ESRI Developer Summit 2008   67