Programming for Geographical Information Analysis: Advanced Skills - PowerPoint PPT Presentation

About This Presentation
Title:

Programming for Geographical Information Analysis: Advanced Skills

Description:

Programming for Geographical Information Analysis: Advanced Skills Lecture 3: Arc Data Framework Dr Andy Evans – PowerPoint PPT presentation

Number of Views:64
Avg rating:3.0/5.0
Slides: 33
Provided by: StanO158
Category:

less

Transcript and Presenter's Notes

Title: Programming for Geographical Information Analysis: Advanced Skills


1
Programming for Geographical Information
AnalysisAdvanced 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
Document (.mxd file)
Map
AttributeTable
FID Data
1 234
2 875
Layer
Feature
234
Values
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.getD
    ocument()
  • 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 lt maps.getCount i)
  • map maps.getItem(i)
  • Other IMaps methods include
  • add(IMap), create(), remove(IMap),
    removeAt(index), Reset Remove all.

9
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
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 i0 i lt 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 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.

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

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

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
AttributeTable
FID Data
1 234
2 875
Layer
Feature
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 lt table.rowCount(null) i)
  • row table.getRow(i)
  • int index table.findField("School")
  • Object value row.getValue(index)

20
Getting the Attribute Table
IAttributeTable pAttributeTable
(IAttributeTable) enumLayer.next()
ITable table pAttributeTable.getAttributeTable
() IRow row null for (int i
1 i lt 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
AttributeTable
FID Data
1 234
2 875
Layer
Feature
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 youre 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
Making a QueryFilter
  • 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()

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 youll have
    to setSubFields to first.

27
Sorting data
  • You can use searching to also sort data. However,
    it is a bit hit-and-miss.
  • Well 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 dont 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 IMaps
    getFeatureSelection method, or an ISelectionSet
    Object.
  • IMaps selectFeature method takes in an ILayer
    and IFeature.
  • Refresh the display using the MxDocuments
    refresh.
  • mxDoc.getActiveView().refresh()

30
Getting data
Document (.mxd file)
Map
AttributeTable
FID Data
1 234
2 875
Layer
Feature
234
Values
31
Summary
  • Get the Applications 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 Layers search routine to search for
    Features.

32
Next Lecture
  • Editing data.
  • External applications.
  • Practical
  • Building a Toolbar.
  • Getting and sorting data.
Write a Comment
User Comments (0)
About PowerShow.com