gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
10楼#
发布于:2005-07-26 10:56
<P>本例要实现的是如何创建定制的可停靠窗口(Dockable Window)</P>
<P 21pt; TEXT-INDENT: -21pt">l 要点</P>
<P 17.95pt">用户通过在类模块中实现IDockableWindowDef接口来创建定制的可停靠窗口(Dockable Window)。IDockableWindowDef接口包括Caption、ChildHWND,UserData及Name等属性和OnCreate、OnDestroy事件。</P>
<P 17.95pt">·ChildHWND属性表示可停靠窗口包含的Window的Handle。</P>
<P 17.95pt">·OnCreate事件的参数hook传入ArcGIS的Application实例。</P>
<P 17.95pt">·创建并注册可停靠窗口的步骤:</P>
<P -0.1pt; TEXT-INDENT: 18.05pt">1、实现IdockableWindowDef接口(参见实例);</P>
<P 17.95pt">2、编译成DLL;</P>
<P 17.95pt">3、调用windows目录下system32子目录下的regsvr32.exe用下面的形式注册编译好的DLL:</P>
<P 17.95pt">win目录\system32\regsvr32.exe  <路径>\<文件名>.dll</P>
<P 17.95pt">4、运行<arcmap目录>\arcexe81\Bin\categories.exe,在打开的Component Catregory Manager中找到ESRI Mx Dockable Window,点击Add Object…按钮将上面注册的DLL文件加入,并选中实现IdockableWindowDef接口的类名即可。</P>
<P 0cm; TEXT-INDENT: 0cm">l 程序说明</P>
<P 17.95pt">类模块 ClsDockableWindow只是创建与注册可停靠窗口,但还不能用,还必须定义一个IdockableWindow接口的变量引用注册的类(必须用IdockableWindowsManager接口的GetDockableWindow获取,其ID号用"实现IdockableWindowDef接口的工程名project1. 实现IdockableWindowDef接口的类名class1")。</P>
<P 21pt; TEXT-INDENT: -21pt">l 代码</P>
<P>
<TABLE height=43 width=541 align=center border=0>

<TR>
<TD width=531>
<P>'类模块 ClsDockableWindow<BR>Option Explicit<BR>Implements IDockableWindowDef<BR>Dim m_pApplication As IApplication </P>
<P>Private Property Get IDockableWindowDef_Caption() As String<BR>    IDockableWindowDef_Caption = "Dockable Window"<BR>End Property </P>
<P>Private Property Get IDockableWindowDef_ChildHWND() As esriCore.OLE_HANDLE<BR>    '将FrmDWin窗口的Handle赋给IDockableWindowDef_ChildHWND<BR>    IDockableWindowDef_ChildHWND = FrmDWin.hWnd<BR>End Property </P>
<P>Private Property Get IDockableWindowDef_Name() As String<BR>    IDockableWindowDef_Name = "docwin"<BR>End Property </P>
<P>Private Sub IDockableWindowDef_OnCreate(ByVal hook As Object)<BR>    Set m_pApplication = hook<BR>End Sub </P>
<P>Private Sub IDockableWindowDef_OnDestroy()<BR>    Set m_pApplication = Nothing<BR>End Sub </P>
<P>Private Property Get IDockableWindowDef_UserData() As Variant<BR>End Property </P>
<P>'类模块 class1<BR>Option Explicit<BR>Implements ICommand<BR>Dim m_pApp As IApplication<BR>Dim m_pDWMgr As IDockableWindowManager<BR>Dim m_pDWin As IDockableWindow </P>
<P>Private Property Get ICommand_Bitmap() As esriCore.OLE_HANDLE<BR>End Property </P>
<P>Private Property Get ICommand_Caption() As String<BR>    ICommand_Caption = "Dockable Window"<BR>End Property </P>
<P>Private Property Get ICommand_Category() As String<BR>    ICommand_Category = "Dockable Window"<BR>End Property </P>
<P>Private Property Get ICommand_Checked() As Boolean<BR>End Property </P>
<P>Private Property Get ICommand_Enabled() As Boolean<BR>    ICommand_Enabled = True<BR>End Property </P>
<P>Private Property Get ICommand_HelpContextID() As Long<BR>End Property </P>
<P>Private Property Get ICommand_HelpFile() As String<BR>End Property </P>
<P>Private Property Get ICommand_Message() As String<BR>End Property </P>
<P>Private Property Get ICommand_Name() As String<BR>    ICommand_Name = "DocWin"<BR>End Property </P>
<P>Private Sub ICommand_OnClick()<BR>    m_pDWin.Show Not m_pDWin.IsVisible<BR>End Sub </P>
<P>Private Sub ICommand_OnCreate(ByVal hook As Object)<BR>    Set m_pApp = hook<BR>    ' QI(Dockable Window)<BR>    Set m_pDWMgr = hook<BR>    Dim pid As New UID<BR>    pid.Value = "Prodockablewindow.Clsdockablewindow"<BR>    Set m_pDWin = m_pDWMgr.GetDockableWindow(pid)<BR>End Sub </P>
<P>Private Property Get ICommand_Tooltip() As String<BR>    ICommand_Tooltip = "Dockable Window"<BR>End Property</P></TD></TR></TABLE></P>
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
11楼#
发布于:2005-07-26 10:56
<P>本例要实现的是如何创建、使用定制的Extension</P>
<P> 要点</P>
<P 17.95pt">用户需要实现IExtension接口来创建定制的Extension。IExtension接口包括Name属性和startup和shutdown事件。</P>
<P 17.95pt">·创建并注册Extension的步骤:</P>
<P 17.95pt">1.实现IExtension接口;</P>
<P 17.95pt">2.编译成DLL;</P>
<P 17.95pt">3.调用windows目录下system32子目录下的regsvr32.exe用下面的形式注册编译好的DLL</P>
<P 17.95pt">win目录\system32\regsvr32.exe  <路径>\<文件名>.dll</P>
<P 17.95pt">4.运行<arcmap目录>\arcexe81\Bin\categories.exe,在打开的Component Catregory Manager中找到ESRI Mx Extensions,点击Add Object…按钮将上面注册的DLL文件加入,并选中实现IExtension接口的类名即可。</P>
<P 0cm; TEXT-INDENT: 0cm">l 程序说明</P>
<P 17.95pt">用户通过在类模块中实现IExtension接口来创建定制的Extension。Extension将在ArcMap打开时自动加载,在ArcMap关闭时自动卸载。</P>
<P 21pt; TEXT-INDENT: -21pt">l 代码</P>
<P>
<TABLE height=43 width=541 align=center border=0>

<TR>
<TD width=531>
<P>Option Explicit<BR> Implements IExtension<BR> Dim m_pApplication As IApplication<BR> ' Need to listen for the MxDocument events<BR> Dim WithEvents m_pDocument As MxDocument </P>
<P> Private Property Get IExtension_Name() As String<BR>     IExtension_Name = "My Extension"<BR> End Property </P>
<P> Private Sub IExtension_Shutdown()<BR>     ' Clear the reference to the Application and MxDocument<BR>     Set m_pApplication = Nothing<BR>     Set m_pDocument = Nothing<BR> End Sub </P>
<P>Private Sub IExtension_Startup(initializationData As Variant)<BR>     ' This extension is an ArcMap Extension. When this extension in loaded on<BR>     ' ArcMap startup, initializationData is passed in as a reference to the<BR>     ' Application object<BR>     Set m_pApplication = initializationData<BR>     'Start listening for the MxDocument events.<BR>     Set m_pDocument = m_pApp.Document<BR> End Sub </P>
<P> Private Function m_pDocument_NewDocument() As Boolean<BR>     ' Do something when a new document is created<BR>     MsgBox "Creating a new document."<BR> End Function </P>
<P> Private Function m_pDocument_OpenDocument() As Boolean<BR>     ' So something when a document is opened.<BR>     MsgBox "Opening a document"<BR> End Function</P></TD></TR></TABLE></P>
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
12楼#
发布于:2005-07-26 10:57
<P>如何使用状态条(StatusBar)与进度条(ProgressBar)</P>
<P 17.95pt">本例要演示的是如何使用状态条(StatusBar)与进度条(ProgressBar)。实现后的结果为在ArcMap中,状态条位于其底部,它显示ArcMAP当前状态的信息,包含进度条。</P>
<P 39pt; TEXT-INDENT: -42pt">l   要点</P>
<P 17.95pt">一般情况下,通过ArcMAP的Application实例获取IstatusBar的实例,然后再通过StatusBar获取IprogressBar的实例,并将IprogressBar的实例赋给IstepProgressor类型的变量。</P>
<P 39pt; TEXT-INDENT: -42pt">l   程序说明</P>
<P 17.95pt">运行函数ShowProgress将在ArcMap的下方添加一个状态条(StatusBar)和进度条(ProgressBar)。</P>
<P 39pt; TEXT-INDENT: -42pt">l   代码</P>
<P>
<TABLE height=43 width=541 align=center border=0>

<TR>
<TD width=531>
<P>Sub ShowProgress()<BR>    On Error GoTo err1<BR>    Dim pDocument As IMxDocument<BR>    Dim pMap As IMap<BR>    Dim pLayer As ILayer<BR>    Dim pFeatureLayer As IFeatureLayer<BR>    Dim pFeatureCursor As IFeatureCursor<BR>    Dim pFeatureClass As IFeatureClass<BR>    Dim pFeature As IFeature<BR>    Dim dSum As Double<BR>    Dim lFieldIndex As Long<BR>    Dim lNumFeat As Long<BR>    Dim dInterval As Double<BR>    Set pDocument = Application.Document<BR>    Set pMap = pDocument.FocusMap<BR>    Set pLayer = pMap.Layer(0)<BR>    Set pFeatureLayer = pLayer<BR>    Set pFeatureClass = pFeatureLayer.FeatureClass<BR>    Set pFeatureCursor = pFeatureLayer.Search(Nothing, True)<BR>    Dim pStatusBar As IStatusBar<BR>    Set pStatusBar = Application.StatusBar<BR>    Dim pStepProgressor As IStepProgressor<BR>    Set pStepProgressor= pStatusBar.ProgressBar<BR>    lNumFeat = pFeatureClass.FeatureCount(Nothing)<BR>    dInterval = lNumFeat / 100<BR>    Set pFeature = pFeatureCursor.NextFeature<BR>    ' 字段名"FID"用户根据实际而改变<BR>    lFieldIndex = pFeature.Fields.FindField("FID")<BR>    Dim PauseTime, Start, Finish, TotalTime, i<BR>    PauseTime = 0.5<BR>    pStepProgressor.MinRange = 1<BR>    pStepProgressor.MaxRange = lNumFeat<BR>    pStepProgressor.StepValue = dInterval<BR>    For i = 1 To lNumFeat<BR>        dSum = dSum + pFeature.Value(lFieldIndex)<BR>        Set pFeature = Nothing<BR>        Set pFeature = pFeatureCursor.NextFeature<BR>        pStepProgressor.Position = i<BR>        pStepProgressor.Message = "Reading record " ; Str(i) ; ". Sum =" ; Str(dSum)<BR>        pStepProgressor.Step<BR>        pStepProgressor.Show<BR>        Start = Timer<BR>        Do While Timer < Start + PauseTime<BR>            DoEvents<BR>        Loop<BR>    Next<BR>    pStepProgressor.Hide<BR>    Exit Sub<BR>    err1:<BR>      MsgBox Err.Description<BR>End Sub</P></TD></TR></TABLE></P>
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
13楼#
发布于:2005-07-26 10:58
<P>如何使用ArcGIS的对话框</P>
<P 17.95pt">添加对话框可以通过相应的接口实现。比如“添加数据对话框”使用IaddDataDialog接口,“生成点坐标对话框” 使用ICoordinateDialog接口,“生成字符串对话框”使用IGetStringDialog接口,“生成数值对话框”使用INumberDialog接口等等。本例以添加数据对话框(Add Data Dialog)为例,讲述对话框是如何通过接口实现添加的。</P>
<P 39pt; TEXT-INDENT: -42pt">l   要点</P>
<P 17.95pt">用户通过实现IaddDataDialog接口来创建定制的添加数据对话框,IaddDataDialog接口包括Document和Map属性和Show事件。</P>
<P 39pt; TEXT-INDENT: -42pt">l   程序说明</P>
<P -0.2pt; TEXT-INDENT: 18.2pt">在程序中除了必须生成IaddDataDialog接口的实例外,还必须指定对话框的Document和Map。当为AddDataDialog指定Document和Map之后,系统会自动将用户选择的数据加入到指定Document和Map中。最后实现在ArcMap中添加数据的对话框。</P>
<P 39pt; TEXT-INDENT: -39pt">l 代码</P>
<P>
<TABLE height=43 width=541 align=center border=0>

<TR>
<TD width=531>
<P>Sub ShowProgress()<BR>  Dim mDocument As IMxDocument<BR>  Dim mAddDataDialog As IAddDataDialog<BR>  Set mAddDataDialog = New AddDataDialog<BR>  Set mDocument = ThisDocument<BR>  mAddDataDialog.Document = mDocument<BR>  mAddDataDialog.Map = mDocument.FocusMap<BR>  mAddDataDialog.Show Application.hWnd, True<BR>End Sub</P></TD></TR></TABLE></P>
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
14楼#
发布于:2005-07-26 10:58
<P>如何调用ArcMap中现有的功能</P>
<P 17.95pt">如何调用ArcMap中现有的功能,比如菜单栏、工具栏中的某些功能。这些都可以通过UID来实现。本例是通过UID调用“另存为”功能。</P>
<P>可以通过两种方法得到UID:</P>
<P>方法一:运用ArcID模块</P>
<P 39pt; TEXT-INDENT: -39pt">l 要点</P>
<P 17.95pt">通过ArcID获得UID,ArcID是ArcMap的VBA中的模块。只需要知道要调用功能的名称运用代码就可以实现。</P>
<P 39pt; TEXT-INDENT: -39pt">l 程序说明</P>
<P 17.95pt">程序通过运用ArcID模块和命令名称来实现调用“另存为”的功能。</P>
<P 39pt; TEXT-INDENT: -39pt">l 代码</P>
<P>Sub ExecuteCmd()<BR>  Dim pCommandItem As ICommandItem<BR>  ' Use ArcID module and the Name of the SaveAs command<BR> Set pCommandItem = Application.Document.CommandBars.Find(arcid.File_SaveAs)<BR>  pCommandItem.Execute<BR>End Sub</P>
<P>方法二:直接写代码</P>
<P 39pt; TEXT-INDENT: -39pt">l 要点</P>
<P 17.95pt">通过直接写代码获得UID实现调用功能。</P>
<P 39pt; TEXT-INDENT: -39pt">l 程序说明</P>
<P 17.95pt">写入文件菜单项的GUID(CLSID或ProgID)来调用文件菜单项,同时还需要通过设置Subtype的值来调用文件菜单项的“另存为”功能。</P>
<P 39pt; TEXT-INDENT: -39pt">l 代码</P>
<P>
<TABLE height=43 width=541 align=center border=0>

<TR>
<TD width=531>
<P>Sub ExecuteCmd2()<BR>  Dim pUID As New UID<BR>  Dim pCommandItem As ICommandItem<BR>  ' Use the GUID of the Save command<BR>  pUID.Value = "{119591DB-0255-11D2-8D20-080009EE4E51}"<BR>  ' or you can use the ProgID<BR>  ' pUID.Value = "esriCore.MxFileMenuItem"<BR>  pUID.SubType = 3<BR>  Set pCommandItem = Application.Document.CommandBars.Find(pUID)<BR>  pCommandItem.Execute<BR>End Sub</P></TD></TR></TABLE></P>
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
15楼#
发布于:2005-07-26 10:59
<P>如何创建放大镜(虫眼)</P>
<P> </P>
<P 17.95pt">本例要实现的是如何创建放大镜(虫眼),将所选区域放大一定的倍数。</P>
<P 39pt; TEXT-INDENT: -39pt">l 要点</P>
<P 17.95pt">用户通过定义IMapInset、IMapInsetWindow、IDataWindowFactory三个接口,运用它们的方法、属性来创建放大镜(虫眼)。</P>
<P 39pt; TEXT-INDENT: -39pt">l 程序说明</P>
<P 17.95pt">运用这个子程序生成了一个新的放大镜窗口,在本例中将放大率设定为200%代替原来的400%。</P>
<P 39pt; TEXT-INDENT: -39pt">l 代码</P>
<P>
<TABLE height=43 width=541 align=center border=0>

<TR>
<TD width=531>
<P>Public Sub CreateMagnifierWindow()<BR><BR>    Dim pMapInset As IMapInset<BR>    Dim pMapInsetWindow As IMapInsetWindow<BR>    Dim pDataWindowFactory As IDataWindowFactory<BR><BR>    Set pDataWindowFactory = New MapInsetWindowFactory<BR>    If pDataWindowFactory.CanCreate(Application) Then<BR>        Set pMapInsetWindow = pDataWindowFactory.Create(Application)<BR>        Set pMapInset = pMapInsetWindow.MapInset<BR>        'Set the zoom percent to 200%<BR>        pMapInset.ZoomPercent = 200<BR>        pMapInsetWindow.Show True<BR>    End If<BR><BR>End Sub</P></TD></TR></TABLE></P>
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
16楼#
发布于:2005-07-26 11:00
如何加载Shape文件
<br><FONT size=2>本例实现的是在ArcMap中连接指定的Shape文件,并将其加载到当前激活的Map中。<FONT face="MS UI Gothic"> </FONT></FONT>
<P 39pt; TEXT-INDENT: -42pt"> l   要点</P>
<P 21pt; LINE-HEIGHT: 14pt">通过FeatureLayer类实现IFeatureLayer接口对象,设置IFeatureLayer.FeatureClass属性和Name属性,使用IMap.AddLayer方法将新层添加到当前地图。利用IWorkspaceFacktory接口、IFeatureWorkspace接口和IFeatureLayer接口实现连接Shape文件</P>
<P 39pt; TEXT-INDENT: -42pt"> l   程序说明</P>
<P 17.95pt">函数OpenShapeFile根据输入的Shape文件路径sFilePath,将文件名为sFileName的Shape文件连接到当前激活的Map中去。</P>
<P 39pt; TEXT-INDENT: -42pt"> l   代码</P>
<TABLE height=43 width=541 align=center border=0><!--DWLayoutTable-->

<TR>
<TD vAlign=top width=535 height=75>
<P 10pt">Private Sub OpenShapeFile(ByVal sFilePath As String, ByVal sFileName As String)</P>
<P 10pt">    Dim pWorkspaceFactory       As IWorkspaceFactory<BR>    Dim pFeatureWorkspace       As IFeatureWorkspace<BR>    Dim pFeatureLayer           As IFeatureLayer<BR>    Dim pMxDocument             As IMxDocument<BR>    Dim pMap                    As IMap<BR>    Dim sDir                    As String    </P>
<P 10pt">On Error GoTo ErrorHandler:</P>
<P 10pt">    sDir = Dir(sFilePath ; "\" ; sFileName ; ".shp")<BR>    If (sDir = "") Then<BR>        sDir = Dir(sFilePath ; "\" ; sFileName)<BR>        If (sDir = "") Then<BR>            MsgBox ("文件不存在")<BR>            Exit Sub<BR>        End If<BR>    End If</P>
<P 10pt">    'Create a new ShapefileWorkspaceFactory object and open a shapefile folder<BR>    Set pWorkspaceFactory = New ShapefileWorkspaceFactory<BR>    Set pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(sFilePath, 0)<BR><BR>    'Create a new FeatureLayer and assign a shapefile to it<BR>    Set pFeatureLayer = New FeatureLayer<BR>    Set pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(sFileName)<BR>    pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName</P>
<P 10pt">    'Add the FeatureLayer to the focus map<BR>    Set pMxDocument = Application.Document<BR>    Set pMap = pMxDocument.FocusMap<BR>    pMap.AddLayer pFeatureLayer</P>
<P 10pt">    Exit Sub</P>
<P 10pt">ErrorHandler:<BR>    MsgBox Err.Description</P>
<P 10pt">End Sub</P>
<P 10pt">Private Sub UIButtonControl1_Click()</P>
<P 10pt">    Dim pVBProject              As VBProject</P>
<P 10pt">On Error GoTo ErrorHandler:</P>
<P 10pt">    Set pVBProject = ThisDocument.VBProject<BR>    OpenShapeFile pVBProject.FileName ; "\..\..\..\.." ; "\data\", "Continents"</P>
<P 10pt">    Exit Sub</P>
<P 10pt">ErrorHandler:<BR>    MsgBox Err.Description</P>
<P 10pt">End Sub</P></TD></TR></TABLE>
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
17楼#
发布于:2005-07-26 11:01
如何在ArcMap中加入Text和dBASE文件
<P>l   要点</P>
<P 17.95pt">首先为Text文件或dBASE文件创建一个与之对应的ITable接口对象,然后通过IMap实例获得IStandaloneTable接口对象和IStandaloneTableCollection接口对象,并设置其属性,最后使用IStandaloneTableCollection.AddStandaloneTable方法将Text文件或dBASE文件加入到当前的ArcMap中。加入Text文件或dBASE文件的区别仅在于创建ITable对象时IWorkspaceFactory的类型不同,加入Text文件时是TextFileWorkspaceFactory类型,加入dBASE文件时是ShapefileWorkspaceFactory类型。</P>
<P 17.95pt">主要用到了IWorkspaceFactory接口,IWorkspace接口,IFeatureWorkspace接口,ITable接口,IStandaloneTable接口和IStandaloneTableCollection接口。</P>
<P 39pt; TEXT-INDENT: -42pt"> l   程序说明</P>
<P 17.95pt">函数AddTextFile通过文件路径sFilePath和文件名sFileName找到Text文件并为其创建ITable对象</P>
<P 17.95pt">函数AddDBASEFile通过文件路径sFilePath和文件名sFileName找到dBASE文件并为其创建ITable对象</P>
<P 17.95pt">函数Add_Table_TOC将ITable对象pTable加入到当前的ArcMap中。</P>
<P 39pt; TEXT-INDENT: -42pt"> l   代码</P>
<P>
<TABLE height=43 width=541 align=center border=0><!--DWLayoutTable-->

<TR>
<TD vAlign=top width=535 height=75>
<P 10pt">Private Sub AddTextFile(ByVal sFilePath As String, ByVal sFileName As String)</P>
<P 10pt">    Dim pWorkspaceFactory            As IWorkspaceFactory<BR>    Dim pWorkspace                   As IWorkspace<BR>    Dim pFeatureWorkspace            As IFeatureWorkspace<BR>    Dim pTable                       As ITable<BR>    Dim sDir                         As String    </P>
<P 10pt">On Error GoTo ErrorHandler:</P>
<P 10pt">    sDir = Dir(sFilePath ; sFileName ; ".txt")<BR>    If (sDir = "") Then<BR>        MsgBox (sFileName ; ".txt" ; "  文件不存在")<BR>        Exit Sub<BR>    End If</P>
<P 10pt">    'Get the ITable from the geodatabase<BR>    Set pWorkspaceFactory = New TextFileWorkspaceFactory<BR>    Set pWorkspace = pWorkspaceFactory.OpenFromFile(sFilePath, 0)<BR>    Set pFeatureWorkspace = pWorkspace<BR>    Set pTable = pFeatureWorkspace.OpenTable(sFileName ; ".txt")</P>
<P 10pt">    'Add the table<BR>    Add_Table_TOC pTable</P>
<P 10pt">    Exit Sub</P>
<P 10pt">ErrorHandler:<BR>    MsgBox Err.Description</P>
<P 10pt">End Sub</P>
<P 10pt">Private Sub AddDBASEFile(ByVal sFilePath As String, ByVal sFileName As String)</P>
<P 10pt">    Dim pWorkspaceFactory            As IWorkspaceFactory<BR>    Dim pWorkspace                   As IWorkspace<BR>    Dim pFeatureWorkspace            As IFeatureWorkspace<BR>    Dim pTable                       As ITable</P>
<P 10pt">On Error GoTo ErrorHandler:</P>
<P 10pt">    'Get the ITable from the geodatabase<BR>    Set pWorkspaceFactory = New ShapefileWorkspaceFactory<BR>    Set pWorkspace = pWorkspaceFactory.OpenFromFile(sFilePath, 0)<BR>    Set pFeatureWorkspace = pWorkspace<BR>    Set pTable = pFeatureWorkspace.OpenTable(sFileName)</P>
<P 10pt">    'Add the table<BR>    Add_Table_TOC pTable</P>
<P 10pt">    Exit Sub</P>
<P 10pt">ErrorHandler:<BR>    MsgBox Err.Description</P>
<P 10pt">End Sub</P>
<P 10pt">Private Sub Add_Table_TOC(pTable As ITable)</P>
<P 10pt">    Dim pDoc                        As IMxDocument<BR>    Dim pMap                        As IMap<BR>    Dim pStandaloneTable            As IStandaloneTable<BR>    Dim pStandaloneTableC           As IStandaloneTableCollection</P>
<P 10pt">On Error GoTo ErrorHandler:</P>
<P 10pt">    Set pDoc = ThisDocument<BR>    Set pMap = pDoc.FocusMap</P>
<P 10pt">    'Create a new standalone table and add it<BR>    'to the collection of the focus map<BR>    Set pStandaloneTable = New StandaloneTable<BR>    Set pStandaloneTable.Table = pTable<BR>    Set pStandaloneTableC = pMap<BR>    pStandaloneTableC.AddStandaloneTable pStandaloneTable</P>
<P 10pt">    'Refresh the TOC<BR>    pDoc.UpdateContents</P>
<P 10pt">    Exit Sub</P>
<P 10pt">ErrorHandler:<BR>    MsgBox Err.Description</P>
<P 10pt">End Sub</P>
<P 10pt">Private Sub UIButtonControl1_Click()</P>
<P 10pt">    Dim pVBProject              As VBProject</P>
<P 10pt">On Error GoTo ErrorHandler:</P>
<P 10pt">    Set pVBProject = ThisDocument.VBProject</P>
<P 10pt">    'Add  text file to ArcMap.  Dont include .txt extension<BR>    AddTextFile pVBProject.FileName ; "\..\..\..\.." ; "\data\", "Continents"</P>
<P 10pt">    'Add dBASE file to ArcMap<BR>    AddDBASEFile pVBProject.FileName ; "\..\..\..\.." ; "\data\", "Continents"</P>
<P 10pt">    Exit Sub</P>
<P 10pt">ErrorHandler:<BR>    MsgBox Err.Description</P>
<P 10pt">End Sub</P></TD></TR></TABLE></P>
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
18楼#
发布于:2005-07-26 11:02
<P>如何连接Coverage文件</P>
<P 17.95pt">本例实现的是如何在当前激活的Map中连接一个Coverage文件。</P>
<P 39pt; TEXT-INDENT: -42pt"> l   要点</P>
<P 17.95pt">使用ArcInfoWorkspaceFactory类实现IWorkSpaceFactory接口对象,用IWorkspaceFactory.Open方法打开一个Workspace,并获得Dataset对象。由于此时的Dataset对象可能有多个Coverage文件,所以要获得IEnumDataset接口对象,通过IEnumDataset.Next方法获得一个Coverage文件,并将其所有的FeatureClass放在IFeatureClassContainer对象中。最后通过IFeatureClassContainer.Class方法获得IFeatureClass接口实例,用IMap.AddLayer方法将要连接的Coverage文件的所有FeatureClass加载到当前激活的Map中。</P>
<P 17.95pt">主要用到IWorkspaceFactory接口,IWorkspace接口,IPropertySet接口,IDataset接口,IEnumDataset接口,IFeatureClassContainer接口。</P>
<P 39pt; TEXT-INDENT: -42pt"> l   程序说明</P>
<P 17.95pt">函数ConnectCoverageFile将sFilePath指定的ArcInfo Workspace中的名称和sFileName相同的Coverage文件加载到当前激活的Map中。</P>
<P 39pt; TEXT-INDENT: -42pt"> l   代码</P>
<P>
<TABLE height=43 width=541 align=center border=0><!--DWLayoutTable-->

<TR>
<TD vAlign=top width=535 height=75>
<P 10pt">Private Sub ConnectCoverageFile(ByVal sFilePath As String, ByVal sFileName As String)</P>
<P 10pt">    Dim pWorkspace                  As IWorkspace<BR>    Dim pWorkspaceFactory           As IWorkspaceFactory<BR>    Dim pPropertySet                As IPropertySet<BR>    Dim pDataset                    As IDataset<BR>    Dim pEnumDataset                As IEnumDataset<BR>    Dim pFeatureClassC              As IFeatureClassContainer<BR>    Dim pFeatureLayer               As IFeatureLayer<BR>    Dim pMxDocument                 As IMxDocument<BR>    Dim pMap                        As IMap<BR>    Dim nNumber                     As Integer<BR>    Dim sWorkspace                  As String</P>
<P 10pt">On Error GoTo ErrorHandler:</P>
<P 10pt">    sWorkspace = Dir(sFilePath, vbDirectory)<BR>    If (sWorkspace = "") Then<BR>        MsgBox ("文件不存在")<BR>        Exit Sub<BR>    End If</P>
<P 10pt">    Set pWorkspaceFactory = New ArcInfoWorkspaceFactory<BR>    Set pPropertySet = New PropertySet</P>
<P 10pt">    'canada is an arcinfoworkspace<BR>    pPropertySet.SetProperty "DATABASE", sFilePath</P>
<P 10pt">    'pWorkSp is a pointer to the IArcInfoWorkspace<BR>    Set pWorkspace = pWorkspaceFactory.Open(pPropertySet, 0)</P>
<P 10pt">    'now get to dataset objects using Idataset<BR>    Set pDataset = pWorkspace</P>
<P 10pt">    'use enum to get datasets<BR>    Set pEnumDataset = pDataset.Subsets</P>
<P 10pt">    pEnumDataset.Reset</P>
<P 10pt">    'use FeatureClassContainer to get datasets<BR>    Set pFeatureClassC = pEnumDataset.Next</P>
<P 10pt">    Do While Not pFeatureClassC Is Nothing<BR>        Set pDataset = pFeatureClassC<BR>        If (pDataset.Name <> sFileName) Then<BR>            Set pFeatureClassC = pEnumDataset.Next<BR>        Else<BR>            Exit Do<BR>        End If<BR>    Loop</P>
<P 10pt">    'add FeatureClassContainer to map<BR>    If (pFeatureClassC Is Nothing) Then<BR>        MsgBox ("文件不存在")<BR>    Else<BR>        nNumber = 0<BR>        Set pMxDocument = ThisDocument<BR>        Set pMap = pMxDocument.FocusMap<BR>        Do While nNumber < pFeatureClassC.ClassCount<BR>            Set pFeatureLayer = New FeatureLayer<BR>            Set pFeatureLayer.FeatureClass = pFeatureClassC.Class(nNumber)<BR>            pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName<BR>            nNumber = nNumber + 1<BR>            pMap.AddLayer pFeatureLayer<BR>        Loop<BR>    End If</P>
<P 10pt">    Exit Sub</P>
<P 10pt">ErrorHandler:<BR>    MsgBox Err.Description</P>
<P 10pt">End Sub</P>
<P 10pt">Private Sub UIButtonControl1_Click()</P>
<P 10pt">    Dim pVBProject              As VBProject</P>
<P 10pt">On Error GoTo ErrorHandler:</P>
<P 10pt">    Set pVBProject = ThisDocument.VBProject<BR>    ConnectCoverageFile pVBProject.FileName ; "\..\..\..\.." ; "\data\canada", "canada"</P>
<P 10pt">    Exit Sub</P>
<P 10pt">ErrorHandler:<BR>    MsgBox Err.Description</P>
<P 10pt">End Sub</P></TD></TR></TABLE></P>
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
19楼#
发布于:2005-07-26 11:02
<P>如何连接栅格文件</P>
<P> </P>
<P 17.95pt">本例实现的是如何在当前激活的Map中添加一个栅格文件。</P>
<P 39pt; TEXT-INDENT: -42pt"> l   要点</P>
<P 17.95pt">创建一个IrasterLayer接口对象,使用IRasterLayer.CreateFromFilePath方法加载一个Raster文件,最后用IMap.AddLayer方法将IRasterLayer添加到当前激活的Map中。</P>
<P 17.95pt">主要用到IRasterLayer接口。</P>
<P 39pt; TEXT-INDENT: -42pt"> l   程序说明</P>
<P 17.95pt">函数AddRasterFile将路径sFilePath下的栅格文件sFileName添加到当前激活的Map中。</P>
<P 39pt; TEXT-INDENT: -42pt"> l   代码</P>
<P>
<TABLE height=43 width=541 align=center border=0><!--DWLayoutTable-->

<TR>
<TD vAlign=top width=535 height=75>
<P 10pt">Private Sub AddRasterFile(sFilePath As String, sFileName As String)</P>
<P 10pt">    'sFileName: the filename of the raster dataset<BR>    'sPath: the directory where the raster dataset resides</P>
<P 10pt">    Dim pRasterLy           As IRasterLayer<BR>    Dim pMxDoc              As IMxDocument<BR>    Dim pMap                As IMap<BR>    Dim sRasterFile         As String</P>
<P 10pt">On Error GoTo ErrorHandler:</P>
<P 10pt">    sRasterFile = Dir(sFilePath ; sFileName)<BR>    If (sRasterFile = "") Then<BR>        MsgBox ("文件不存在")<BR>        Exit Sub<BR>    End If</P>
<P 10pt">    'Create a raster layer<BR>    Set pRasterLy = New RasterLayer</P>
<P 10pt">    'This is only one of the three ways to create a RasterLayer object.<BR>    'If there is already a Raster or RasterDataset object, then<BR>    'method CreateFromDataset or CreateFromRaster can be used.<BR>    pRasterLy.CreateFromFilePath sFilePath ; sFileName</P>
<P 10pt">    'Add the raster layer to ArcMap<BR>    Set pMxDoc = ThisDocument<BR>    Set pMap = pMxDoc.FocusMap<BR>    pMap.AddLayer pRasterLy<BR>    pMxDoc.ActiveView.Refresh</P>
<P 10pt">    Exit Sub</P>
<P 10pt">ErrorHandler:<BR>    MsgBox Err.Description</P>
<P 10pt">End Sub</P>
<P 10pt">Private Sub UIButtonControl1_Click()</P>
<P 10pt">    Dim pVBProject              As VBProject</P>
<P 10pt">On Error GoTo ErrorHandler:</P>
<P 10pt">    Set pVBProject = ThisDocument.VBProject<BR>    AddRasterFile pVBProject.FileName ; "\..\..\..\.." ; "\data\", "photo.tif"</P>
<P 10pt">    Exit Sub</P>
<P 10pt">ErrorHandler:<BR>    MsgBox Err.Description</P>
<P 10pt">End Sub</P></TD></TR></TABLE></P>
举报 回复(0) 喜欢(0)     评分
游客

返回顶部