90 likes | 305 Views
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. Dim pGxDialog As IGxDialog Dim pGxFilter As IGxObjectFilter
E N D
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.
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. Prepare an Add Data dialog
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, pGxObjects Set pGxDataset = pGxObjects.Next ' Exit sub if no dataset has been added. If pGxDataset Is Nothing Then Exit Sub End 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.Next Loop Get the datasets
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" Query select feature
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 Perform the selection
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 Deal with the 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 Move two points of selected feature