Download presentation
Presentation is loading. Please wait.
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 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
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.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.
5
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.
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 < maps.getCount; i++) { map = maps.getItem(i) } Other IMaps methods include… add(IMap), create(), remove(IMap), removeAt(index), Reset [Remove all].
7
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
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 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.
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. In order to understand the other ways of getting Layers, we need to understand Enumerations. These are a generic computing pattern.
10
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.
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(); } enumLayer.reset() sets the enumeration to the first record.
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 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.
13
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 ( so here are some: IDataLayer {6CA416B1-E160-11D2-9F4E-00C04F6BC78E} IGeoFeatureLayer {E156D7E5-22AF-11D3-9F99-00C04F6BC78E} IGraphicsLayer {34B2EF81-F4AC-11D1-A B6F22B} IFDOGraphicsLayer {34B2EF85-F4AC-11D1-A B6F22B} ICoverageAnnotationLayer {0C22A4C7-DAFD-11D2-9F46-00C04F6BC78E} IGroupLayer {EDAD D1-86AE-0000F }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.