1 / 8

Project 5 : programming ArcObject with VBA Part I Vector data

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

pink
Download Presentation

Project 5 : programming ArcObject with VBA Part I Vector data

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Part I • Project Part I – Vector data • Move an assigned polygon right border 25 unit to the right.

  3. 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

  4. 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

  5. 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

  6. 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

  7. 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

  8. 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

More Related