阅读:1140回复:0
该怎么实现读取.shp文件和文件的DBF文件呢?
<P>大家好!</P>
<P>高手帮我该下代码吧!看看哪里出问题了!</P> <P>我想实现的是读取.shp文件和文件的DBF表格,运行时总是出错!</P> <P>Private Sub Form_Load()<BR>Dim sFilePath As String<BR>Dim sFileName As String<BR>Dim pFeatureLayer As IFeatureLayer<BR>Dim pWorkspaceFactory As IWorkspaceFactory<BR>Dim pFeatureWorkspace As IFeatureWorkspace<BR>Dim pMxDocument As IMxDocument<BR>Dim pMap As IMap<BR>Dim sDir As String<BR>On Error GoTo ErrorHandler:<BR>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<BR>'Create a new ShapefileWorkspaceFactory object and open a shapefile folder<BR>Set pWorkspaceFactory = New ShapefileWorkspaceFactory<BR>Set pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(sFilePath, 0)<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<BR>'Add the FeatureLayer to the focus map<BR>Set pMxDocument = Application.Document<BR>Set pMap = pMxDocument.FocusMap<BR>pMap.AddLayer pFeatureLayer<BR>Exit Sub<BR>ErrorHandler:<BR>MsgBox Err.Description</P> <P>If PageLayoutControl1.CheckMxFile(sFilePath ; "\" ; sFileName ; ".shp") Then<BR>PageLayoutControl1.LoadMxFile sFilePath ; "\" ; sFileName ; ".shp"<BR>End If</P> <P>End Sub</P> |
|