打开各种类型的featureclass
来源:http://www.cnblogs.com/wall/archive/2008/05/20/1203377.html
1打开各种类型的featureclass#Region "打开各种类型的featureclass"
2 /**/''' <summary>
3 ''' 打开Access,返回featureclass
4 ''' </summary>
5 ''' <param name="sDBName">Access文件名(全路径)</param>
6 ''' <param name="sFCName">featureclass名称</param>
7 ''' <returns>要素类featureclass</returns>
8 ''' <remarks></remarks>
9 Public Function OpenAccessDatabase()Function OpenAccessDatabase(ByVal sDBName As String, ByVal sFCName As String) As IFeatureClass
10 Dim pPropset As IPropertySet
11 pPropset = New PropertySet
12 Dim pFact As IWorkspaceFactory
13 Dim pWorkspace As IWorkspace
14 pPropset.SetProperty("DATABASE", sDBName)
15 pFact = New AccessWorkspaceFactory
16 pWorkspace = pFact.Open(pPropset, 0)
17 Dim pFeatureWorkspace As IFeatureWorkspace
18 pFeatureWorkspace = pWorkspace
19 Dim pFeatureClass As IFeatureClass
20 pFeatureClass = pFeatureWorkspace.OpenFeatureClass(sFCName)
21 Return pFeatureClass
22 End Function
23/**/''' <summary>
24 ''' 打开Shapefile,返回featureclass
25 ''' </summary>
26 ''' <param name="sDBName">shapefile路径</param>
27 ''' <param name="sFCName">featureclass名称</param>
28 ''' <returns>要素类featureclass</returns>
29 ''' <remarks></remarks>
30 Public Function OpenShapefile()Function OpenShapefile(ByVal sDBName As String, ByVal sFCName As String) As IFeatureClass
31 Dim pPropset As IPropertySet
32 pPropset = New PropertySet
33 Dim pFact As IWorkspaceFactory
34 Dim pWorkspace As IWorkspace
35 pPropset.SetProperty("DATABASE", sDBName)
36 pFact = New ShapefileWorkspaceFactory
37 pWorkspace = pFact.Open(pPropset, 0)
38 Dim pFeatureWorkspace As IFeatureWorkspace
39 pFeatureWorkspace = pWorkspace
40 Dim pFeatureClass As IFeatureClass
41 pFeatureClass = pFeatureWorkspace.OpenFeatureClass(sFCName)
42 Return pFeatureClass
43 End Function
44/**/''' <summary>
45 ''' 打开SDE,返回featureclass
46 ''' </summary>
47 ''' <param name="sServerName">sde服务名称</param>
48 ''' <param name="sFCName">featureclass名称</param>
49 ''' <returns>要素类featureclass</returns>
50 ''' <remarks></remarks>
51Public Function OpenSDE()Function OpenSDE(ByVal sServerName As String, ByVal sFCName As String) As IFeatureClass
52 Dim pPropset As IPropertySet
53 pPropset = New PropertySet
54 Dim pFact As IWorkspaceFactory
55 Dim pWorkspace As IWorkspace
56 With pPropset
57 .SetProperty("Server", sServerName)
58 .SetProperty("Instance", "sdemss")
59 .SetProperty("Database", "sde") 'Ignored with ArcSDE for Oracle
60 .SetProperty("user", "sde")
61 .SetProperty("password", "go")
62 .SetProperty("version", "sde.DEFAULT")
63 End With
64 pFact = New SdeWorkspaceFactory
65 pWorkspace = pFact.Open(pPropset, 0)
66 Dim pFeatureWorkspace As IFeatureWorkspace
67 pFeatureWorkspace = pWorkspace
68 Dim pFeatureClass As IFeatureClass
69 pFeatureClass = pFeatureWorkspace.OpenFeatureClass(sFCName)
70 Return pFeatureClass
71 End Function
72/**/''' <summary>
73 ''' 打开Raster,返回dataset
74 ''' </summary>
75 ''' <param name="sDir">路径名</param>
76 ''' <param name="sFile">文件名</param>
77 ''' <returns>返回RasterDataset</returns>
78 ''' <remarks></remarks>
79 Public Function OpenRasterDataset()Function OpenRasterDataset(ByVal sDir As String, ByVal sFile As String) As IRasterDataset
80 'Open the raster dataset with the given name.
81 'sDir is the directory the file resides
82 'sFile is the filename
83 Dim pWsFact As IWorkspaceFactory
84 Dim pWs As IRasterWorkspace
85 Dim pRasterDataset As IRasterDataset
86 'Open the workspace
87 pWsFact = New RasterWorkspaceFactory
88 pWs = pWsFact.OpenFromFile(sDir, 0)
89 'Open the raster dataset
90 pRasterDataset = pWs.OpenRasterDataset(sFile)
91 'Return
92 pWsFact = Nothing
93 pWs = Nothing
94 pRasterDataset = Nothing
95 Return pRasterDataset
96 End Function
97#End Region
2 /**/''' <summary>
3 ''' 打开Access,返回featureclass
4 ''' </summary>
5 ''' <param name="sDBName">Access文件名(全路径)</param>
6 ''' <param name="sFCName">featureclass名称</param>
7 ''' <returns>要素类featureclass</returns>
8 ''' <remarks></remarks>
9 Public Function OpenAccessDatabase()Function OpenAccessDatabase(ByVal sDBName As String, ByVal sFCName As String) As IFeatureClass
10 Dim pPropset As IPropertySet
11 pPropset = New PropertySet
12 Dim pFact As IWorkspaceFactory
13 Dim pWorkspace As IWorkspace
14 pPropset.SetProperty("DATABASE", sDBName)
15 pFact = New AccessWorkspaceFactory
16 pWorkspace = pFact.Open(pPropset, 0)
17 Dim pFeatureWorkspace As IFeatureWorkspace
18 pFeatureWorkspace = pWorkspace
19 Dim pFeatureClass As IFeatureClass
20 pFeatureClass = pFeatureWorkspace.OpenFeatureClass(sFCName)
21 Return pFeatureClass
22 End Function
23/**/''' <summary>
24 ''' 打开Shapefile,返回featureclass
25 ''' </summary>
26 ''' <param name="sDBName">shapefile路径</param>
27 ''' <param name="sFCName">featureclass名称</param>
28 ''' <returns>要素类featureclass</returns>
29 ''' <remarks></remarks>
30 Public Function OpenShapefile()Function OpenShapefile(ByVal sDBName As String, ByVal sFCName As String) As IFeatureClass
31 Dim pPropset As IPropertySet
32 pPropset = New PropertySet
33 Dim pFact As IWorkspaceFactory
34 Dim pWorkspace As IWorkspace
35 pPropset.SetProperty("DATABASE", sDBName)
36 pFact = New ShapefileWorkspaceFactory
37 pWorkspace = pFact.Open(pPropset, 0)
38 Dim pFeatureWorkspace As IFeatureWorkspace
39 pFeatureWorkspace = pWorkspace
40 Dim pFeatureClass As IFeatureClass
41 pFeatureClass = pFeatureWorkspace.OpenFeatureClass(sFCName)
42 Return pFeatureClass
43 End Function
44/**/''' <summary>
45 ''' 打开SDE,返回featureclass
46 ''' </summary>
47 ''' <param name="sServerName">sde服务名称</param>
48 ''' <param name="sFCName">featureclass名称</param>
49 ''' <returns>要素类featureclass</returns>
50 ''' <remarks></remarks>
51Public Function OpenSDE()Function OpenSDE(ByVal sServerName As String, ByVal sFCName As String) As IFeatureClass
52 Dim pPropset As IPropertySet
53 pPropset = New PropertySet
54 Dim pFact As IWorkspaceFactory
55 Dim pWorkspace As IWorkspace
56 With pPropset
57 .SetProperty("Server", sServerName)
58 .SetProperty("Instance", "sdemss")
59 .SetProperty("Database", "sde") 'Ignored with ArcSDE for Oracle
60 .SetProperty("user", "sde")
61 .SetProperty("password", "go")
62 .SetProperty("version", "sde.DEFAULT")
63 End With
64 pFact = New SdeWorkspaceFactory
65 pWorkspace = pFact.Open(pPropset, 0)
66 Dim pFeatureWorkspace As IFeatureWorkspace
67 pFeatureWorkspace = pWorkspace
68 Dim pFeatureClass As IFeatureClass
69 pFeatureClass = pFeatureWorkspace.OpenFeatureClass(sFCName)
70 Return pFeatureClass
71 End Function
72/**/''' <summary>
73 ''' 打开Raster,返回dataset
74 ''' </summary>
75 ''' <param name="sDir">路径名</param>
76 ''' <param name="sFile">文件名</param>
77 ''' <returns>返回RasterDataset</returns>
78 ''' <remarks></remarks>
79 Public Function OpenRasterDataset()Function OpenRasterDataset(ByVal sDir As String, ByVal sFile As String) As IRasterDataset
80 'Open the raster dataset with the given name.
81 'sDir is the directory the file resides
82 'sFile is the filename
83 Dim pWsFact As IWorkspaceFactory
84 Dim pWs As IRasterWorkspace
85 Dim pRasterDataset As IRasterDataset
86 'Open the workspace
87 pWsFact = New RasterWorkspaceFactory
88 pWs = pWsFact.OpenFromFile(sDir, 0)
89 'Open the raster dataset
90 pRasterDataset = pWs.OpenRasterDataset(sFile)
91 'Return
92 pWsFact = Nothing
93 pWs = Nothing
94 pRasterDataset = Nothing
95 Return pRasterDataset
96 End Function
97#End Region