zyf1097727546
zyf1097727546
2017-08-11 04:53

索引超出范围。必须为非负值并小于集合大小。这是怎么回事啊

60
  • c#
  • arcgis engine
  • dataset

public static ISpatialReference GetSpatialReference(IFeatureDataset pFeatureDataset)
{
IGeoDataset pGeoDataset = pFeatureDataset as IGeoDataset;
ISpatialReference pSpatialReference = pGeoDataset.SpatialReference;
return pSpatialReference;
}
public static List GetAllFeatureClass(IWorkspace workspace)
{
IEnumDataset dataset = workspace.get_Datasets(esriDatasetType.esriDTFeatureDataset);
IFeatureDataset featureDataset = dataset as IFeatureDataset;

             List<IFeatureDataset> featureDatasetList = new List<IFeatureDataset>();
             while (featureDataset != null)
             {
                 featureDatasetList.Add(featureDataset);
                 featureDataset = dataset.Next() as IFeatureDataset;
             }
             return featureDatasetList;
         }
         public static IWorkspace GetShapefileWorkspace(string sFilePath)
         {
             try
             {
                 IWorkspaceFactory factory = new ShapefileWorkspaceFactoryClass();
                 sFilePath = System.IO.Path.GetDirectoryName(sFilePath);
                 return factory.OpenFromFile(sFilePath, 0);
             }
             catch
             {
                 return null;
             }
         }
    private void 属性ToolStripMenuItem_Click(object sender, EventArgs e)
    {

        IWorkspace workspace = GetShapefileWorkspace(@"C:\Users\10977\Desktop\AE\培训数据\空间分析\1为新学校选址\新学校选址.mxd");
        List<IFeatureDataset> lfd = GetAllFeatureClass(workspace);

        ISpatialReference isr = GetSpatialReference(lfd[0]);
        string st=isr.Name.ToString();
        Form2 fr =new Form2();
        fr.Show();
    }
            ISpatialReference isr = GetSpatialReference(lfd[0]);这句话提示索引超出范围。必须为非负值并小于集合大小。求解啊
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

4条回答