Arc: Getting Layers Dr Andy Evans.

Slides:



Advertisements
Similar presentations
Programming for Geographical Information Analysis: Advanced Skills Lecture 2: ArcObjects Framework Dr Andy Evans.
Advertisements

Internal Documentation Conventions. Kinds of comments javadoc (“doc”) comments describe the user interface: –What the classes, interfaces, fields and.
Computer Science II Recursion Professor: Evan Korth New York University.
Games and Simulations O-O Programming in Java The Walker School
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
Programming for Geographical Information Analysis: Advanced Skills Lecture 4: Arc Data Editing Addin Programming Dr Andy Evans.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
Adv_GISArcObjects - 11 VBA and ArcObjects Programming Week 1 Spring 2008 Advanced GIS.
Arc: AddIns Dr Andy Evans. Java Direct access to ArcObjects Framework inside and outside Arc. Ability to add components to the GUI. Ability to communicate.
Introduction to ArcGIS for Environmental Scientists Module 1 – Data Visualization Chapter 3 – Symbology and Labeling.
Arc: Accessing the Framework Dr Andy Evans. Code The code that goes in the addIn is then code to work with the ArcObjects framework. Ask App for Document.
23-Oct-15 Abstract Data Types. 2 Data types A data type is characterized by: a set of values a data representation, which is common to all these values,
Linked List. Iterators Operation to find a link, deleting, and inserting before or after a specified link, also involve searching through the list to.
1 Module 1 Highlights Learning your way around. 2 Course Stuff… There are now 45 of you! So I have to change some things 1.Each week when you hand in.
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface Creating a Multiple-Form Interface.
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
Arc: Events Dr Andy Evans. Event communication Arc is, plainly, set up for Event Based Programming. You can register listeners with most GUI components.
Chapter 11 Navigating Object Model Diagrams Week 6, 2008 Spring.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
CS2102: Lecture on Abstract Classes and Inheritance Kathi Fisler.
Programming for Geographical Information Analysis: Advanced Skills Lecture 3: Arc Data Framework Dr Andy Evans.
Arc: Communications between Addins Dr Andy Evans.
COMPOSITE PATTERN NOTES. The Composite pattern l Intent Compose objects into tree structures to represent whole-part hierarchies. Composite lets clients.
Coming up Implementation vs. Interface The Truth about variables Comparing strings HashMaps.
1 CS162: Introduction to Computer Science II Abstract Data Types.
Arrays Chapter 7.
Memory Management.
Operator Overloading Introduction
Topic: Classes and Objects
Recursion Topic 5.
EECE 310: Software Engineering
Introduction to Recursion
Getting to Know ArcGIS Chapter 3 Interacting with maps
Foundations of Programming: Arrays
JAVA COLLECTIONS LIBRARY
Development of Linear Measure Tool using Application Framework
Chapter 4: Writing Classes
Repeating code We could repeat code we need more than once: i = 1 print (i) i += 1 print (i) #… stop when i == 9 But each line means an extra line we might.
Introduction to ArcGIS
Linked list insertion Head. Linked list insertion Head.
Enterprise Content Management, Shared Services, & Contract Management
CMPE212 – Stuff… Exercises 4, 5 and 6 are all fair game now.
Design by Contract Fall 2016 Version.
Some Basics for Problem Analysis and Solutions
CS2102: Lecture on Abstract Classes and Inheritance
Introduction to Classes
One-Dimensional Array Introduction Lesson xx
Lecture 4 An example for changing a layer’s Name
Subprograms and Programmer Defined Data Type
Writing Methods AP Computer Science A.
Arrays versus ArrayList
Chapter 9 Objects and Classes
Coding Concepts (Data Structures)
Coding Concepts (Basics)
Parameter Passing in Java
Barb Ericson Georgia Institute of Technology Oct 2005
CS2110: Software Development Methods
Workshop for Programming And Systems Management Teachers
Mastering Memory Modes
How to write good code Part 2
Data Structures & Algorithms
Programming with inheritance Based on slides by Alyssa Harding
Creating and Modifying Text part 3
Managing 2D Arrays Simple Dynamic Allocation
Assignment due Write a program the generates a random integer expression, presents the two operands and the result to the user, and asks the user to tell.
slides created by Ethan Apter
Week 2 - Friday CS222.
Introduction to Java Collection
Introduction to Computer Science and Object-Oriented Programming
Presentation transcript:

Arc: Getting Layers Dr Andy Evans

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.

Getting data Document (.mxd file) Map AttributeTable Layer Feature FID Data 1 234 2 875 Layer The above diagram shows you the rough ways in which we can reach data. There is, in Arc, more than one way of doing most things. Feature 234 Values

Getting a Map A Map contains all the data and features in the Data View or each Layout View frame. import com.esri.arcgis.carto.*; IMxDocument mxDocument = (IMxDocument)app.getDocument(); IMap mxDoc = mxDocument.getFocusMap(); FocusMap is the one visible in data view or selected in layout view. The first thing we need is a copy of the Map/s open in ArcMaps. Each Document can have several Maps. The example above gets the Map the user is obviously interested in.

Getting all Maps You can also get an Object containing all the Maps. IMaps maps = mxDoc.getMaps(); However, you can also get all the Maps open in ArcMap. They are returned Encapsulated inside an IMap defined Object.

IMaps You can loop through all the IMap Interface objects in an IMaps Interface object using its .getCount and .getItem methods. IMap map = null; for (int i = 0; i < maps.getCount; i++) { map = maps.getItem(i) } Other IMaps methods include… add(IMap), create(), remove(IMap), removeAt(index), Reset [Remove all].

Getting data It’s rare we want to get data out of a Map. It’s more usual to get data from a Layer ~ (a Coverage, FeatureDataset, Image etc.). Map AttributeTable FID Data 1 234 2 875 Layer Feature 234 Values

Getting Layers I If you know what the type of the Layers are, you can get them thus… // Assuming we've got a IMap object "map". ILayer layer = null; for (int i=0; i < map.getLayerCount(); i++) { layer = map.getLayer(i); // Do something } A Layer is a complete dataset – they are represented by the datasets shown with their own symbology in the Content Tree.

Enumerations Objects containing lists of other objects. Like a 1D array. Arc uses them to return arrays of data to you. Have a next method to get the next object. Also a reset method to return to the start. ArcObject types have different Enumerations. e.g. IEnumLayer is the Interface for a set of Layers. In order to understand the other ways of getting Layers, we need to understand Enumerations. These are a generic computing pattern.

Standard use of Enumerations IEnumSomething enumSomething = someEnumGettingMethod(); enumSomething.reset(); SomeClass variable = enumSomething.next(); while (variable != null) { \\Do stuff with variable variable = enumSomething.next(); } Note we get the first variable first, then do something with it, before getting the next and checking whether it is null.

Getting Layers II Get an Enumeration of Layers IEnumLayer enumLayer = map.getLayers(null,true); enumLayer.reset(); ILayer layer = enumLayer.next(); while (layer != null) { \\ Do something with the ILayer layer = enumLayer.next(); } enumLayer.reset() sets the enumeration to the first record.

Types of Layer Remember however that we can add many things as Layers (images, data, etc.). Main types: IFeatureLayer IGeoFeatureLayer IGraphicsLayer Others include more specific FeatureLayers, FDOGraphicsLayers (Annotation), TinLayer, RasterLayer, and CoverageAnnotationLayer. If we don’t know the layers in the document we may need to check for a specific type. Obviously, we wouldn’t want to try and get the x-y coordinates out of an image of someone’s face, for example.

The instanceof keyword You can check whether an object implements an Interface using Java’s instanceof keyword. For example, if the user’s selected something in ArcMap's tree of contents, you can test whether it’s a GeoFeatureLayer, thus… // Assuming we’ve got an enumeration of Layers. IGeoFeatureLayer featLayer = null; ILayer layer = enumLayer.next(); while (layer != null) { if (layer instanceof IGeoFeatureLayer) { featLayer = (IGeoFeatureLayer) layer; //Do something with featLayer } layer = enumLayer.next(); In actually fact, the “null” in getLayers (back two slides) can be replaced by a code encapsulated in an object that sets a filter, such that getLayers returns only layers of a specified type. The way above is slightly less efficient, but easier to understand. See the getLayers API docs for details. The list of codes isn’t easy to find (http://support.esri.com/en/knowledgebase/techarticles/detail/31115), so here are some: IDataLayer {6CA416B1-E160-11D2-9F4E-00C04F6BC78E} IGeoFeatureLayer {E156D7E5-22AF-11D3-9F99-00C04F6BC78E} IGraphicsLayer {34B2EF81-F4AC-11D1-A245-080009B6F22B} IFDOGraphicsLayer {34B2EF85-F4AC-11D1-A245-080009B6F22B} ICoverageAnnotationLayer {0C22A4C7-DAFD-11D2-9F46-00C04F6BC78E} IGroupLayer {EDAD6644-1810-11D1-86AE-0000F8751720}