8
Project 5 : programming ArcObject with VBA Part I Vector data Sherry Fu CE 697V Nov. 30, 2006

Project 5 : programming ArcObject with VBA Part I Vector data Sherry Fu CE 697V Nov. 30, 2006

Embed Size (px)

Citation preview

Page 1: Project 5 : programming ArcObject with VBA Part I Vector data Sherry Fu CE 697V Nov. 30, 2006

Project 5 : programming ArcObject with VBA

Part I Vector data

Sherry FuCE 697V

Nov. 30, 2006

Page 2: Project 5 : programming ArcObject with VBA Part I Vector data Sherry Fu CE 697V Nov. 30, 2006

Part I

• Project Part I – Vector data

• Move an assigned polygon right border 25 unit to the right.

Page 3: Project 5 : programming ArcObject with VBA Part I Vector data Sherry Fu CE 697V Nov. 30, 2006

Prepare an Add Data dialog

Dim pGxDialog As IGxDialog

Dim pGxFilter As IGxObjectFilter

Set pGxDialog = New GxDialog

Set pGxFilter = New GxFilterShapefiles

' Define the dialog's properties.

With pGxDialog

.AllowMultiSelect = True

.ButtonCaption = "Add"

Set .ObjectFilter = pGxFilter

.Title = "Add Shapefiles"

End With

• Let the users select shapefiles from a dialog box and adds them to an active map.

• The key point is to use ArcCatalog classes: GxDialog and GxFilter.

• GxDialog is a form to accept the datasets selected by the user and add them.

Page 4: Project 5 : programming ArcObject with VBA Part I Vector data Sherry Fu CE 697V Nov. 30, 2006

Get the datasets

• This part is to get the datasets selected by the user and adds them as layers to the map.

• The DoModalOpen method open the dialog box and saves the selected files into a collection.

pGxDialog.DoModalOpen 0, pGxObjectsSet pGxDataset = pGxObjects.Next' Exit sub if no dataset has been added.If pGxDataset Is Nothing Then Exit SubEnd If Do Until pGxDataset Is Nothing Set pLayer = New FeatureLayer Set pLayer.FeatureClass =

pGxDataset.Dataset pLayer.Name =

pLayer.FeatureClass.AliasName pMap.AddLayer pLayer Set pGxDataset = pGxObjects.NextLoop

Page 5: Project 5 : programming ArcObject with VBA Part I Vector data Sherry Fu CE 697V Nov. 30, 2006

Query select feature

• The third polygon ID is 100103.

• To search the feature on the layer. Use pQueryFilter.WhereClause SQL to select the assigned ID from attribute table field of the shapefile and export the filtered data.

Dim pMXDoc As IMxDocument

Set pMXDoc = ThisDocument

Dim pLayer As IFeatureLayer

Set pLayer = pMXDoc.FocusMap.Layer(0)

Dim pFeatureSelection As IFeatureSelection

Set pFeatureSelection = pLayer

Dim pQueryFilter As IQueryFilter

Set pQueryFilter = New QueryFilter

pQueryFilter.WhereClause = "PolyID=100103"

Page 6: Project 5 : programming ArcObject with VBA Part I Vector data Sherry Fu CE 697V Nov. 30, 2006

Perform the selection

• Perform the select feature by pQueryFilter and flag the selection by pActiveView.PartialRefresh esriViewGeoSelection

• The selected feature will be active on the map.

pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing

pFeatureSelection.SelectFeatures pQueryFilter, esriSelectionResultNew, False

pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing

Dim pFeatureCursor As IFeatureCursor

Dim pFeature As IFeature

Dim pGeometry As IGeometry

Dim pPolygon As IPolygon

Set pFeatureCursor = pLayer.Search(pQueryFilter, False)

Set pFeature = pFeatureCursor.NextFeature

Set pPolygon = pFeature.Shape

Page 7: Project 5 : programming ArcObject with VBA Part I Vector data Sherry Fu CE 697V Nov. 30, 2006

Deal with the selected feature

• The selected feature is a rectangle. Therefore, we can apply IEnvelope interface.

• Envelopes are the rectangular window that contain a specific element.

• The envelope is an geometry objects defined by the XMin, XMax, YMin, and YMax of the object

Dim pEnvelopeFrom As IEnvelope,

Dim pEnvelopeTo As IEnvelope

Set pEnvelopeFrom=pFeature.Extent

Dim pPolColl As IGeometryCollection

Set pPolColl = pPolygon

Dim pPtColl As IPointCollection

Set pPtColl = pPolygon

Dim pPoint As IPoint

Page 8: Project 5 : programming ArcObject with VBA Part I Vector data Sherry Fu CE 697V Nov. 30, 2006

Move two points of selected feature

• Move the feature right border 25 unit to the right.

• To access and manipulate point geometry by using IGeometryCollection and IPointCollection.

• The method is to move XMax and XMin points by +25.

Set pPoint = New Point

pPoint.X = pEnvelopeFrom.XMax + 25

pPoint.Y = pEnvelopeFrom.YMax

pPtColl.UpdatePoint 1, pPoint

pPolColl.GeometriesChanged

pFeature.Store

Set pPoint = New Point

pPoint.X = pEnvelopeFrom.XMax + 25

pPoint.Y = pEnvelopeFrom.YMin

pPtColl.UpdatePoint 2, pPoint

pPolColl.GeometriesChanged

pFeature.Store