Arc Getting Layers Dr Andy Evans Arc Map

  • Slides: 13
Download presentation
Arc: Getting Layers Dr Andy Evans

Arc: Getting Layers Dr Andy Evans

Arc. Map IMXDocument methods Used for getting data: get. Active. View() i. e. layout

Arc. Map IMXDocument methods Used for getting data: get. Active. View() i. e. layout view or data view data. get. Focus. Map() i. e. currently selected/shown map. get. Maps() i. e. all maps. get. Selected. Item() i. e. that the user has picked. get. Selected. Layer() i. e. that the user has picked. Documents also implement IDocument, the main use of which is programmatically controlling toolbars.

Document (. mxd file) Getting data Map Attribute. Table Layer Feature FID Data 1

Document (. mxd file) Getting data Map Attribute. Table Layer Feature FID Data 1 234 2 875 234 Values

Getting a Map A Map contains all the data and features in the Data

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. *; IMx. Document mx. Document = (IMx. Document)app. get. Document(); IMap mx. Doc = mx. Document. get. Focus. Map(); Focus. Map is the one visible in data view or selected in layout view.

Getting all Maps You can also get an Object containing all the Maps. IMaps

Getting all Maps You can also get an Object containing all the Maps. IMaps maps = mx. Doc. get. Maps();

IMaps You can loop through all the IMap Interface objects in an IMaps Interface

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

Getting data It’s rare we want to get data out of a Map. It’s

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, Feature. Dataset, Image etc. ). Map Attribute. Table Layer Feature FID Data 1 234 2 875 234 Values

Getting Layers I If you know what the type of the Layers are, you

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. get. Layer. Count(); i++) { layer = map. get. Layer(i); // Do something }

Enumerations Objects containing lists of other objects. Like a 1 D array. Arc uses

Enumerations Objects containing lists of other objects. Like a 1 D 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. Arc. Object types have different Enumerations. e. g. IEnum. Layer is the Interface for a set of Layers.

Standard use of Enumerations IEnum. Something enum. Something = some. Enum. Getting. Method(); enum.

Standard use of Enumerations IEnum. Something enum. Something = some. Enum. Getting. Method(); enum. Something. reset(); Some. Class variable = enum. Something. next(); while (variable != null) { \Do stuff with variable = enum. Something. 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 IEnum. Layer enum. Layer = map.

Getting Layers II Get an Enumeration of Layers IEnum. Layer enum. Layer = map. get. Layers(null, true); enum. Layer. reset(); ILayer layer = enum. Layer. next(); while (layer != null) { \ Do something with the ILayer layer = enum. Layer. next(); }

Types of Layer Remember however that we can add many things as Layers (images,

Types of Layer Remember however that we can add many things as Layers (images, data, etc. ). Main types: IFeature. Layer IGeo. Feature. Layer IGraphics. Layer Others include more specific Feature. Layers, FDOGraphics. Layers (Annotation), Tin. Layer, Raster. Layer, and Coverage. Annotation. Layer. If we don’t know the layers in the document we may need to check for a specific type.

The instanceof keyword You can check whether an object implements an Interface using Java’s

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 Arc. Map's tree of contents, you can test whether it’s a Geo. Feature. Layer, thus… // Assuming we’ve got an enumeration of Layers. IGeo. Feature. Layer feat. Layer = null; ILayer layer = enum. Layer. next(); while (layer != null) { if (layer instanceof IGeo. Feature. Layer) { feat. Layer = (IGeo. Feature. Layer) layer; //Do something with feat. Layer } layer = enum. Layer. next(); }