130 likes | 259 Views
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.
E N D
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 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.*; IMxDocumentmxDocument = (IMxDocument)app.getDocument(); IMapmxDoc = mxDocument.getFocusMap(); FocusMap 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 maps = mxDoc.getMaps();
IMaps You can loop through all the IMap Interface objects in an IMaps Interface object using its .getCountand .getItemmethods. 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 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 }
Enumerations Objects containing lists of other objects. Like a 1D array. Arc uses them to return arrays of data to you. Have a nextmethod to get the next object. Also a resetmethod to return to the start. ArcObject types have different Enumerations. e.g. IEnumLayer is the Interface for a set of Layers.
Standard use of Enumerations IEnumSomethingenumSomething = someEnumGettingMethod(); enumSomething.reset(); SomeClassvariable = 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 IEnumLayerenumLayer = map.getLayers(null,true); enumLayer.reset(); ILayer layer = enumLayer.next(); while (layer != null) { \\ Do something with the ILayer layer = enumLayer.next(); }
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.
The instanceof keyword You can check whether an object implements an Interface using Java’sinstanceofkeyword. 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. IGeoFeatureLayerfeatLayer = null; ILayer layer = enumLayer.next(); while (layer != null) { if (layerinstanceofIGeoFeatureLayer) { featLayer= (IGeoFeatureLayer) layer; //Do something with featLayer } layer = enumLayer.next(); }