我也遇到了类似的问题。通过代码测试了好多次。
(1)在保证授权许可没有问题;
(2)文件路径和文件名没有问题;
在以上两种情况下,可能是shp数据文件出现了错误。可以用ArcMap打开这个文件试试看,是不是这个错误。
IWorkspaceFactory PWorkSpaceFactory新ShapefileWorkspaceFactory();
IFeatureWorkspace PFeatureWorkSpace
IFeatureLayer PFeatureLayer新FeatureLayerClass();
的OpenFileDialog打开新的OpenFileDialog();
Open.Title =“选择需要加载的地理数据文件;
Open.Filter =“shape文件(SHP)| *。 SHP;
Open.ShowDialog();
和字符串strFullPath = Open.FileName
(strFullPath ==“”)返回;
诠释指数= strFullPath。为lastIndexOf(“\ \”);
字符串的文件路径= strFullPath.Substring(0,索引);
字符串文件名= strFullPath.Substring(指数+ 1);
PFeatureWorkSpace = (IFeatureWorkspace)PWorkSpaceFactory.OpenFromFile“(文件路径,0);
PFeatureLayer.FeatureClass = PFeatureWorkSpace.OpenFeatureClass(文件名);
IFeatureClass pFeatureClass = PFeatureWorkSpace.OpenFeatureClass(文件名); BR />
axMapControl2.Map.ClearLayers();
/ /添加到MapControl中
axMapControl2.Map.AddLayer(PFeatureLayer);
axMapControl2.Refresh() ;
IWorkspaceFactory PWorkSpaceFactory = new ShapefileWorkspaceFactory();
IFeatureWorkspace PFeatureWorkSpace;
IFeatureLayer PFeatureLayer = new FeatureLayerClass();
OpenFileDialog Open = new OpenFileDialog();
Open.Title = "选择需要加载的地理数据文件";
Open.Filter = "shapefile(.shp)|*.shp";
Open.ShowDialog();
string strFullPath = Open.FileName;
if (strFullPath == "") return;
int index = strFullPath.LastIndexOf("\\");
string filepath = strFullPath.Substring(0, index);
string filename = strFullPath.Substring(index + 1);
PFeatureWorkSpace = (IFeatureWorkspace)PWorkSpaceFactory.OpenFromFile(filepath, 0);
PFeatureLayer.FeatureClass = PFeatureWorkSpace.OpenFeatureClass(filename);
IFeatureClass pFeatureClass = PFeatureWorkSpace.OpenFeatureClass(filename);
axMapControl2.Map.ClearLayers();
//Add to MapControl
axMapControl2.Map.AddLayer(PFeatureLayer);
axMapControl2.Refresh();
把axLicenseControl 这个控件也加进去就好了
数据的路径中是否有中文 或者 符号?
都改成英文试试