Arc: Getting Layers - PowerPoint PPT Presentation

About This Presentation
Title:

Arc: Getting Layers

Description:

Arc: Getting Layers Dr Andy Evans – PowerPoint PPT presentation

Number of Views:67
Avg rating:3.0/5.0
Slides: 14
Provided by: StanO159
Category:
Tags: arc | carto | getting | layers

less

Transcript and Presenter's Notes

Title: Arc: Getting Layers


1
Arc Getting Layers
  • Dr Andy Evans

2
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.

3
Getting data
Document (.mxd file)
Map
AttributeTable
FID Data
1 234
2 875
Layer
Feature
234
Values
4
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.getD
    ocument()
  • IMap mxDoc mxDocument.getFocusMap()
  • FocusMap is the one visible in data view or
    selected in layout view.

5
Getting all Maps
  • You can also get an Object containing all the
    Maps.
  • IMaps maps mxDoc.getMaps()

6
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 lt maps.getCount i)
  • map maps.getItem(i)
  • Other IMaps methods include
  • add(IMap), create(), remove(IMap),
    removeAt(index), Reset Remove all.

7
Getting data
  • Its rare we want to get data out of a Map. Its
    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
8
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 i0 i lt map.getLayerCount() i)
  • layer map.getLayer(i)
  • // Do something

9
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.

10
Standard use of Enumerations
  • IEnumSomething enumSomething someEnumGett
    ingMethod()
  • 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.

11
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()

12
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 dont know the layers in the document we
    may need to check for a specific type.

13
The instanceof keyword
  • You can check whether an object implements an
    Interface using Javas instanceof keyword.
  • For example, if the users selected something in
    ArcMap's tree of contents, you can test whether
    its a GeoFeatureLayer, thus
  • // Assuming weve 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()
Write a Comment
User Comments (0)
About PowerShow.com