zys
zys
路人甲
路人甲
  • 注册日期2004-01-07
  • 发帖数103
  • QQ
  • 铜币61枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:2074回复:0

ok

楼主#
更多 发布于:2004-08-16 10:30
<P>addshapefiles修正版,可直接拷贝使用</P>
<P 0pt? 0cm><FONT face="Times New Roman">Public Sub AddShapeFile()</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  Dim pWorkspaceFactory As IWorkspaceFactory</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  Dim pFeatureWorkspace As IFeatureWorkspace</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  Dim pFeatureLayer As IFeatureLayer</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  Dim pMxDocument As IMxDocument</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  Dim pMap As IMap</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  </FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  Dim pFeatureDataset As IGxDataset</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  Dim pGxDialog As IGxDialog</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  Dim pGxCatalog As IGxCatalog</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  Set pGxDialog = New GxDialog</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  With pGxDialog</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">    .AllowMultiSelect = False</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">    Set .ObjectFilter = New GxFilterFeatureClasses</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">    .DoModalOpen ThisDocument.Parent.hWnd, Nothing</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">    Set pGxCatalog = .InternalCatalog</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">    Set pFeatureDataset = pGxCatalog.SelectedObject</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  End With</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  Dim sWSName As String</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  Dim sFeatureName As String</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">    sFeatureName = pFeatureDataset.Dataset.BrowseName</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">    sWSName = pFeatureDataset.Dataset.Workspace.PathName</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">    'MsgBox pFeatureDataset.Dataset.Name</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  'Create a new ShapefileWorkspaceFactory object and open a shapefile folder</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  Set pWorkspaceFactory = New ShapefileWorkspaceFactory</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  </FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  Set pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(sWSName, 0)</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  'Create a new FeatureLayer and assign a shapefile to it</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman"></FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  Set pFeatureLayer = New FeatureLayer</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  </FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  Set pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(sFeatureName)</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  'Add the FeatureLayer to the focus map</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  Set pMxDocument = Application.Document</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  Set pMap = pMxDocument.FocusMap</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  pMap.AddLayer pFeatureLayer</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  pMxDocument.ActiveView.Refresh</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">End Sub</FONT></P>
喜欢0 评分0
游客

返回顶部