1.加载Shapefile数据
1
IWorkspaceFactory pWorkspaceFactory;
2
IFeatureWorkspace pFeatureWorkspace;
3
IFeatureLayer pFeatureLayer;
4
5
//
获取当前路径和文件名
6
OpenFileDialog dlg
=
new
OpenFileDialog();
7
dlg.Filter
=
"
Shape(*.shp)|*.shp|All Files(*.*)|*.*
"
;
8
dlg.Title
=
"
Open Shapefile data
"
;
9
dlg.ShowDialog();
10
string
strFullPath
=
dlg.FileName;
11
if
(strFullPath
==
""
)
return
;
12
int
Index
=
strFullPath.LastIndexOf(
"
//
"
);
13
string
filePath
=
strFullPath.Substring(
0
, Index);
14
string
fileName
=
strFullPath.Substring(Index
+
1
);
15
16
//
打开工作空间并添加shp文件
17
pWorkspaceFactory
=
new
ShapefileWorkspaceFactoryClass();
18
pFeatureWorkspace
=
(IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(filePath,
0
);
19
pFeatureLayer
=
new
FeatureLayerClass();
20
21
pFeatureLayer.FeatureClass
=
pFeatureWorkspace.OpenFeatureClass(fileName);
22
pFeatureLayer.Name
=
pFeatureLayer.FeatureClass.AliasName;
23
axMapControl1.Map.AddLayer(pFeatureLayer);
24
axMapControl1.ActiveView.Refresh();

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

2.加载栅格数据
1
IWorkspaceFactory pWorkspaceFactory;
2
IRasterWorkspace pRasterWorkspace;
3
4
OpenFileDialog dlg
=
new
OpenFileDialog();
5
dlg.Filter
=
"
Layer File(*.lyr)|*.jpg;*.bmp;*.tiff
"
;
6
dlg.Title
=
"
Open Raster Data File
"
;
7
dlg.ShowDialog();
8
//
获取当前路径和文件名
9
string
strFullPath
=
dlg.FileName;
10
if
(strFullPath
==
""
)
return
;
11

2

3

4

5

6

7

8

9

10

11