Programming for Geographical Information Analysis: Advanced Skills - PowerPoint PPT Presentation

About This Presentation
Title:

Programming for Geographical Information Analysis: Advanced Skills

Description:

Title: 1. Intriduction to Java Programming for Beginners, Novices, Geographers and Complete Idiots Author: Stan Openshaw Last modified by: Linus Created Date – PowerPoint PPT presentation

Number of Views:108
Avg rating:3.0/5.0
Slides: 43
Provided by: StanO150
Category:

less

Transcript and Presenter's Notes

Title: Programming for Geographical Information Analysis: Advanced Skills


1
Programming for Geographical Information
AnalysisAdvanced Skills
  • Lecture 2 ArcObjects Framework
  • Dr Andy Evans

2
  • AddIn Architecture
  • ArcObjects Framework

3
Java
  • Direct access to ArcObjects Framework inside and
    outside Arc.
  • Ability to add components to the GUI.
  • Ability to communicate with external applications.

4
AddIns
  • Button Icon on toolbar.
  • Tool Changes mouse operations.
  • Combo box Dropdown list and editable box.
  • Toolbar For grouping AddIns.
  • Menu Dropdown and right-click.
  • Tool palette Floating container for other
    AddIns.
  • Dockable window Floating window that can be
    locked into the GUI.
  • Application extension Additional functionality
    within, e.g. Arc extensions.

5
Form
  • jar zip file, with a .esriaddin extension
  • Contains
  • config.xml metadata describing the addin
  • Java class files
  • Other resources needed e.g. data, images

6
Installing
  • File is just dropped into
  • USERPROFILE\
  • My Documents\ArcGIS\AddIns\Desktop10.2 
  • or
  • USERPROFILE\
  • Documents\ArcGIS\AddIns\Desktop10.2
  • There are easy install options for users (double
    clicking on the addin will bring up a wizard to
    walk through installing it)

7
Installing a sent AddIn
  • AddIn Manger

8
Installing a sent AddIn
  • Choose Add from file and navigate to the file.
  • Should then see it under the commands list in
    whatever Category youve created for it in the
    XML file.
  • Drag and drop from here, onto the interface.

9
Managing AddIns
  • Admin Registry Keys (regedit.exe)
  • HKEY_LOCAL_MACHINE\SOFTWARE\ESRI\Desktop10.2 \
    Settings
  • BlockAddIns
  • 0 - Load all.
  • 1 - Load signed only.
  • 2 - Load ESRI only.
  • 3 - Load from administrator folders only.
  • 4 - Do not Load any Add-Ins.
  • AddInFolders
  • AdminAddInLock - stop tampering with these.

10
Digital signing
  • See
  • http//help.arcgis.com/en/sdk/10.0/Java_AO_ADF/con
    ceptualhelp/engine/index.html/Digitally_signed_ad
    d_ins/0001000004zq000000/

11
Making an AddIn
  • Rather than writing the config.xml ourselves, and
    zipping it up manually with the java files,
    theres an Eclipse IDE plugin.
  • This does all the basic class generation for us,
    and prepares the file.
  • Details for installing the IDE and plugin on the
    website.

12
Eclipse
13
Eclipse
Project area
Editor area, currently showing config.xml, but
shown as a form, not text.
Show xml text source
14
Config.xml
15
(No Transcript)
16
(No Transcript)
17
(No Transcript)
18
(No Transcript)
19
Eclipse
  • Should check code as you write.
  • Will compile when you save the file.
  • Errors reported in problems panel
  • Note that the javadoc panel displays the javadocs
    of known classes.

20
Eclipse
  • Will autocomplete as you type. Will also suggest
    potential quick fixes if you click on hover over
    an issue.

21
Debugging
  • No System.out.println()
  • Best bet is
  • JOptionPane.showMessageDialog(null, String)
  • E.g.
  • JOptionPane.showMessageDialog(null, "Hello
    World")
  • Or for exception checking
  • catch (Exception e)
  • JOptionPane.showMessageDialog(null,
    e.getStackTrace())

22
Help coding
  • Course Code Cookbook
  • Theres no point in you struggling to find key
    bits of code on ESRIs site.
  • So, there are many useful code examples,
    stripped down to be a simple as possible, on the
    course website.
  • The quid pro quo
  • Send us useful code you get working.
  • Read and try and understand the code, dont just
    cut- and-paste it. Ask questions!

23
Help coding
  • Intro to Eclipse
  • Help -gt Welcome -gt Overview / Tutorials
  • Arc Programming pages
  • http//resources.arcgis.com/en/help/arcobjects-jav
    a/concepts/engine/
  • Java ArcObjects Developer Guide -gt
  • Developing extensions -gt
  • ArcGIS Desktop customizations using add-ins

24
Help coding
  • API
  • http//resources.arcgis.com/en/help/arcobjects-jav
    a/api/arcobjects/index.html
  • Note that the API docs are a re-write of the VB
    pages, and still contain some VB code
  • If it says This parameter is optional, it
    usually isnt.
  • If it says If you dont want this parameter,
    just pass in zero or Nothing, then pass in
    null.
  • If it gives Variant as a return type, it returns
    java.lang.Object.

25
Select the AddIn
26
If you are developing, you need to reboot Arc to
get changes to appear, but you dont need to
re-add the addIn.
27
Extensions
  • Classes that extend Arc functionality
  • Custom feature renderers
  • Custom geoprocessing tools can be added to
    ArcToolbox and ModelBuilder
  • Class extensions Change form of data
  • Plug-in data sources
  • Utility objects Combine other tools

28
Installing
  • Jar file placed in
  • ltArcGIS Install Dirgt/java/lib/ext

29
  • Programming ArcGIS
  • AddIn Architecture
  • ArcObjects Framework

30
Code
  • The code that goes in the addIn is then code to
    work with the ArcObjects framework.

The running version of Arc is accessed via
gatekeeper objects. You then request objects
from these, and subsequent objects from the
objects you get back.
Ask App for Document Ask Document for Maps Ask
Maps for a Map Ask Map for Layers Ask Layers for
Layer etc.
31
init(IApplication app)
  • Most addIns come with a init method that can be
    overridden. This is sent the application as an
    entry point for the running framework.
  • import com.esri.arcgis.framework.
  • private IApplication app
  • _at_Override
  • public void init(IApplication app)
  • this.app app

32
Document
  • You can use this to get hold of the current
    document. This is the current data and GUI.
  • import com.esri.arcgis.arcmapui.
  • IMxDocument mxDoc (IMxDocument)app.getDocume
    nt()

33
API
  • It is then just a matter of finding how to do
    stuff in the API docs
  • http//resources.arcgis.com/en/help/arcobjects-jav
    a/api/arcobjects/index.html

34
N.B.
  • The code utilises Java Annotations.
  • _at_name
  • Used as a marker for software intending to
    process the code.
  • _at_Override

35
N.B.II
  • Arc returns objects that implement multiple
    interfaces.
  • You generally cast the object to a specific
    interface when using it.
  • IMxDocument mxDoc (IMxDocument)app.getDocume
    nt()
  • There is nothing to stop you recasting it to
    another interface to use different methods in it
  • IDocument iDoc (IDocument) mxDoc
  • Infact, it is very common.

36
The COM
  • In Microsoft languages, this reassignment of
    interface labels is key.
  • It allows chunks of code to use other chunks of
    code without knowing anything other than the
    interface names.
  • It is used to hold together a great deal of the
    Component Object Model (COM) at the heart of
    Microsoft software.
  • ArcGIS is built around the COM, so this is a
    common thing to see.

37
Interfaces
  • This requires some care.
  • You might think that redefining everything as the
    right object would be sensible
  • public void init(IApplication app)
  • Application a (Application)app
  • You could then use all the methods.
  • However, while objects Arc gives you will match
    the interfaces, they may not do anything sensible.

38
Interfaces
  • For example, this works in ArcMap
  • public void init(IApplication app)
  • Application a (Application)app
  • IGxSelection selec a.getSelection()
  • JOptionPane.showMessageDialog
  • (null, selec.toString())
  • But doesnt give you anything sensible, as
    IGxSelection is an ArcCatalog class, and here the
    Application object is the ArcMap Application
    object, not the ArcCatalog one.

39
Interfaces
  • In general, better to get the interface right and
    keep the object defined by its interfaces.
  • As well as explicitly casting, just attaching the
    right label works if you are going to a less
    specific class
  • IMxDocument mxDoc app.getDocument()
  • But generally in the examples youll see an
    explicit cast because it saves looking up the
    relationship.
  • In the API Docs, in general go for the interface
    list at the top of the class.
  • Interfaces generally start I
  • Then Mx for ArcMap, Gx for ArcCatalog.

40
ArcMap IApplication methods
  • newDocument(boolean userPickTemplate?, String
    path)
  • openDocument(String optionalPath)
  • refreshWindow()
  • saveDocument(String optionalPath)

If the paths are null, the usual new, open,
and save processes occur.
41
ArcMap IMXDocument methods
  • Used for getting data
  • getActiveView() i.e. layout view or data view
    data.
  • getFocusMap() i.e. currently selected/shown
    map.
  • getMaps() i.e. all maps.
  • getSelectedItem() i.e. that the user has picked.
  • getSelectedLayer() i.e. that the user has picked.
  • Documents also implement IDocument, the main use
    of which is programmatically controlling toolbars.

42
Next Lecture
  • Getting, sorting, and searching data.
  • Practical
  • Hello World!
  • Utilising tools in Arc Addins.
Write a Comment
User Comments (0)
About PowerShow.com