Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Fall 2003
AddShapeFile()
Public Sub AddShapeFile() Dim pWorkspaceFactory As IWorkspaceFactory Dim pFeatureWorkspace As IFeatureWorkspace Dim pFeatureLayer As IFeatureLayer Dim pMxDocument As IMxDocument Dim pMap As IMap 'Create a new ShapefileWorkspaceFactory object and open a shapefile folder Set pWorkspaceFactory = New ShapefileWorkspaceFactory Set pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(c:\esri\esridata\world", 0) 'Create a new FeatureLayer and assign a shapefile to it Set pFeatureLayer = New FeatureLayer Set pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(country") pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName 'Add the FeatureLayer to the focus map Set pMxDocument = Application.Document Set pMap = pMxDocument.FocusMap pMap.AddLayer pFeatureLayer 5 End Sub
Private Sub UIToolControl1_MouseDown(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long) Dim pMxApp As IMxApplication Dim pMxDoc As IMxDocument Dim pMap As IMap Dim pActiveView As IActiveView Dim pEnvelope As IEnvelope Set pMxApp = Application Set pMxDoc = Application.Document Set pMap = pMxDoc.FocusMap Set pActiveView = pMap Set pEnvelope = pMxDoc.CurrentLocation.Envelope pEnvelope.Expand pMxDoc.SearchTolerance, pMxDoc.SearchTolerance, False 'Refresh the old selection to erase it pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing 'Perform the selection using a point created on mouse down pMap.SelectByShape pEnvelope, pMxApp.SelectionEnvironment, True 7 'Refresh again to draw the new selection
AttributeQuery
Public Sub AttributeQuery() Dim pQueryAttributes As IQueryAttributes 'Create a new Query Attribute Dialog and set 'some necessary properties before launching it Set pQueryAttributes = New QueryAttributes Set pQueryAttributes.Application = Application pQueryAttributes.SelectFeaturesInLayerOnOK = True 'Provide a default expression if desired 'pQueryAttributes.Expression = """NAME"" = 'Halifax'" 'Lauch the dialog pQueryAttributes.DoModal Application.hWnd End Sub
Macro in ArcMap
Go to Tools>Macro and select Normal in Macro in Type in MyZoomIn in Macro Name and click Create Go to File>Close Return to ArcMap In ArcMap, go to Tools>Macro> and select Module1.MyZoomIn macro and click Run (make sure your macro settings is in Normal) The display zoomed in 50% smaller.
10
Selection/Buffer
Add Buffer Feature and create graphic elements by clicking on left window and copy to your new module in existing macro Add Select Features Using An Attribute Query to next module in same macro. Select Name = Kroger in business layer and buffer this feature using 1000 meters (go to View > Data Frame Properties and select Predefined > Projected Coordinate System > UTM > NAD 1983 > NAD 1983 UTM Zone 16N. This will set your projected system to UTM 1983)
11
Open a ArcGIS file and create a macro with the following code and run it (switch your view between map and PageLayout window
Sub PageLayout() Dim pActiveView As IActiveView ' Define interface pointer Dim pMxDoc As IMxDocument Set pMxDoc = ThisDocument Set pActiveView = pMxDoc.ActiveView ' Get active view of document If TypeOf pActiveView Is IMap Then ' Test the view object type MsgBox "This page is a map window" Else MsgBox "It's a PageLayout object" End If End Sub
12
Add Table
Public Sub AddTable() Dim pMxDoc As IMxDocument Dim pMap As IMap Dim pTableCollection As ITableCollection Set pMxDoc = ThisDocument Set pMap = pMxDoc.FocusMap Set pTableCollection = pMap Set pTable = OpenTable(c:\esri\esridata\usa\", "States.dbf") If pTable Is Nothing Then Exit Sub pTableCollection.AddTable pTable pMxDoc.UpdateContents End Sub
13
14
Function..
'Create the table name object Set pDatasetName = New TableName pDatasetName.Name = strTableName Set pDatasetName.WorkspaceName = pShpWorkspaceName 'Open the table Set pName = pDatasetName Set OpenTable = pName.Open Exit Function 'exit to avoid error handler ErrorHandler: Set OpenTable = Nothing End Function
15
Map objects
When a new map object is instantiated, two other related objects are created too. ScreenDisplay and CompositeGraphicsLayer. IMAP is the starting point for Map. (for example, add/ delete/access map layers, associate with Map surround :legend,scale bar..)
17
ArcMap objects
MapSurround() provides the list of map surround objects. Scale and SpatialReference are metric properties common to all layers of a given Map. Each map has its own list of bookmarks, available through the IMapBookmarks interface. Bookmarks managed through the main menu options are of the AOIBookmark type (AOI = "area of interest").
18
Map layer
Map layers are represented by various types of layer objects according to the type of data they present. FeatureLayer - geodata-defined map elements (features) stored as feature class data in a geodatabase. FDOGraphicsLayer (FDO = "feature data object") annotation feature class data. Annotation features are graphical elements used to annotate members of a feature layer. FDOGraphicsLayer data is also stored in a geodatabase. CompositeGraphicsLayer - used by Map for its BasicGraphicsLayer property. CoverageAnnotationLayer - for display of ArcInfo coverage files. RasterLayer and TinLayer - for raster or TIN data. GroupLayer - allows treating multiple layers as single unit.
19
Layer type
A given map may contain layers of different types. All layer objects implement the ILayer interface, and this is what is returned by Map's layer selection functions. To determine the exact layer type, you need to try querying the object for type-specific interfaces. For example, if the layer object supports the IFeatureLayer interface, then you know it is a FeatureLayer object. In VisualBasic, this might be coded as follows (Add this code to the previous macro) Dim pLayer As ILayer Dim pMap As IMap Set pMap = pMxDoc.FocusMap Set pLayer = pMap.Layer(0) ' (pMap points to Map object) If TypeOf pLayer Is IFeatureLayer Then MsgBox "pLayer is a FeatureLayer object" 20 End If
Layer
GraphicElement objects are used for the display of nonfeature data (a FeatureLayer displays itself using a feature renderer acting on each record of the layer dataset). Graphic elements include text, primitive geometric shapes, and pictures. (TIP: Graphs and reports are stored as EmfPictureElements.) The MapSurround class includes legends, scale bars, and north arrows. Map grid support is provided by objects derived from MapGrid, MapGridBorder, and GridLabel. Members of the NumberFormat class assist in grid labeling with a variety of numeric display format options. FrameElements serve as graphical containers for other objects. In addition to providing backgrounds and borders, they perform other functions according to their type: A MapFrame houses a Map object. It stores map grids, locator rectangles, and clipping parameters. A MapSurroundFrame houses a MapSurround object.
21