Download presentation
Presentation is loading. Please wait.
Published bySarah Patrick Modified over 9 years ago
1
Programming for Geographical Information Analysis: Advanced Skills Lecture 3: Arc Data Framework Dr Andy Evans
2
Data Getting maps and layers Getting data points and attributes Sorting and searching
3
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.
4
Data Getting maps and layers Getting data points and attributes Sorting and searching
5
Getting data Map Feature Layer FIDData 1234 2875 AttributeTable 234 Values Document (.mxd file)
6
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.
7
Getting all Maps You can also get an Object containing all the Maps. IMaps maps = mxDoc.getMaps();
8
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].
9
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 Feature Layer FIDData 1234 2875 AttributeTable 234 Values
10
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 }
11
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.
12
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.
13
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(); }
14
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.
15
The instanceof k eyword 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(); }
16
Data Getting maps and layers Getting data points and attributes Sorting and searching
17
Getting Data/Features from Layers Assign your Layer to an appropriate Interface. IGeoFeatureLayer : Treat as geographical data IFeatureLayer : Treat as a general Layer IAttributeTable : Treat as an attribute table Get the Attribute Table or search the Layer.
18
Getting data Once we have our Layer, we want to get data from it. Map Feature Layer FIDData 1234 2875 AttributeTable 234 Values
19
Getting the Attribute Table Assuming we have a Layer Enumeration, we set the Layer to an IAttributeTable. import com.esri.arcgis.geodatabase.*; IAttributeTable pAttributeTable = (IAttributeTable)enumLayer.next(); ITable table = pAttributeTable.getAttributeTable(); IRow row = null; for (int i = 1; i <= table.rowCount(null); i++) { row = table.getRow(i); int index = table.findField("School"); Object value = row.getValue(index); }
20
Getting the Attribute Table Get Layer as AttributeTable Get actual Table Get each row Get a particular Field IAttributeTable pAttributeTable = (IAttributeTable) enumLayer.next(); ITable table = pAttributeTable.getAttributeTable(); IRow row = null; for (int i = 1; i <= table.rowCount(null) ; i++) { row = table.getRow(i); int index = table.findField("School"); Object value = row.getValue(index); }
21
Getting data Alternative is to get data from a Feature. Map Feature Layer FIDData 1234 2875 AttributeTable 234 Values First though, we need to get only the features we are interested in. We can search for these.
22
Data Getting maps and layers Getting data points and attributes Sorting and searching
23
Searching You need to get a reference to the data and a search cursor ( ICursor / IFeatureCursor ). The search cursor jumps between records in a dataset that match some search criteria. The cursor marks the row/feature in the dataset that you’re currently interested in. They have a nextSomething method which gets a object appropriate to the dataset.
24
Search Methods IFeatureLayer / IGeoFeatureLayer IFeatureCursor cursor = featureLayer.search (queryFilter, false); ITable from an IAttributeTable ICursor cursor = table.search (queryFilter, false); Where queryFilter is an IQueryFilter Object True / false determines how the records are allocated to the Cursor – set to False.
25
You can get everything by setting these to null. cursor = pFeatureLayer.search(null, false); IQueryFilter objects store fields you want returned and query strings. You need to (rare this) make a QueryFilter object from scratch… IQueryFilter queryFilter = new QueryFilter(); Making a QueryFilter
26
IQueryFilter Objects pQueryFilter.setSubFields("SCHOOL,CITY"); pQueryFilter.addField ("POSTCODE"); pQueryFilter.setWhereClause = "CITY = 'Leeds'"; By default the fields are set to “*” i.e. all fields, so if you use just addField you’ll have to setSubFields to “” first.
27
Sorting data You can use searching to also sort data. However, it is a bit hit-and-miss. We’ll look at the more usual TableSort in the practical.
28
Getting Data from a Feature Use the cursor to get the next feature IFeature feature = featureCursor.nextFeature(); while (feature != null) { //Do stuff to feature feature = featureCursor.nextFeature(); } The Feature method getValue(i) takes in an integer number equalling the position of the field column. If you don’t know it, there are lookup methods that return integers… feature.getFields().findField("SCHOOL");
29
Setting/Getting Features Selected An alternative is to get the selected Features. To get the Features you need IMap’s getFeatureSelection method, or an ISelectionSet Object. IMap’s selectFeature method takes in an ILayer and IFeature. Refresh the display using the MxDocument’s refresh. mxDoc.getActiveView().refresh();
30
Getting data Map Feature Layer FIDData 1234 2875 AttributeTable 234 Values Document (.mxd file)
31
Summary Get the Application’s Document. Get the Maps from it. Pick the one you want or loop through them. Get a Layer from the Map, or Loop through all of them. Generate an Attribute table and use Rows / Fields to get data. Or use the Layer’s search routine to search for Features.
32
Next Lecture Editing data. External applications. Practical Building a Toolbar. Getting and sorting data.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.