DotSpatial shapefile性能非常慢

问题描述:

我试图从特定的shapefile中读取所有的特征数据。在这种情况下,我使用DotSpatial打开文件,并且遍历这些功能。这个特定的shapefile只有9mb大小,dbf文件是14mb。大约有75k个功能可以循环使用。DotSpatial shapefile性能非常慢

注意,这是所有编程通过一个控制台应用程序,所以没有参与渲染或任何东西。

当装载形状文件,我重新投影,然后我迭代。重新加载的速度非常快。但是,只要代码到达我的foreach块,加载数据需要将近2分钟的时间,并且在VisualStudio中调试时使用大约2GB的内存。这对于合理的小数据文件来说似乎非常非常过分。

我跑的Visual Studio之外相同的代码,在命令行,但时间仍然大约2个完整分钟,左右的内存为1.3GB的过程。

无论如何加快这一点呢?

下面是我的代码:

// Load the shape file and project to GDA94 
Shapefile indexMapFile = Shapefile.OpenFile(shapeFilePath); 
indexMapFile.Reproject(KnownCoordinateSystems.Geographic.Australia.GeocentricDatumofAustralia1994); 

// Get's slow here and takes forever to get to the first item 
foreach(IFeature feature in indexMapFile.Features) 
{ 
    // Once inside the loop, it's blazingly quick. 
} 

有趣的是,当我使用VS立即窗口,它是超级超级快,没有延迟在所有...

我已经设法想出解决办法...

出于某种原因,呼吁功能的foreach慢得令人痛苦。

然而,由于这些文件有1-1映射与功能 - 数据行(每个要素都有一个相关的数据行),我稍微修改到以下。现在非常快速......不到一秒钟就可以开始迭代。

// Load the shape file and project to GDA94 
Shapefile indexMapFile = Shapefile.OpenFile(shapeFilePath); 
indexMapFile.Reproject(KnownCoordinateSystems.Geographic.Australia.GeocentricDatumofAustralia1994); 

// Get the map index from the Feature data 
for(int i = 0; i < indexMapFile.DataTable.Rows.Count; i++) 
{ 

    // Get the feature 
    IFeature feature = indexMapFile.Features.ElementAt(i); 

    // Now it's very quick to iterate through and work with the feature. 
} 

我想知道为什么会这样。我想我需要查看IFeatureList实现上的迭代器。

干杯, 贾斯汀

这对于非常大的文件同样的问题(1.2百万的功能),填充■特征集合永远不会结束。

但如果你问的功能,你不必记忆或延迟开销。

 int lRows = fs.NumRows(); 
     for (int i = 0; i < lRows; i++) 
     { 

      // Get the feature 
      IFeature pFeat = fs.GetFeature(i); 

      StringBuilder sb = new StringBuilder(); 
      { 
       sb.Append(Guid.NewGuid().ToString()); 
       sb.Append("|"); 
       sb.Append(pFeat.DataRow["MAPA"]); 
       sb.Append("|"); 
       sb.Append(pFeat.BasicGeometry.ToString()); 
      } 
      pLinesList.Add(sb.ToString()); 
      lCnt++; 

      if (lCnt % 10 == 0) 
      { 
       pOld = Console.ForegroundColor; 
       Console.ForegroundColor = ConsoleColor.DarkGreen; 
       Console.Write("\r{0} de {1} ({2}%)", lCnt.ToString(), lRows.ToString(), (100.0 * ((float)lCnt/(float)lRows)).ToString()); 
       Console.ForegroundColor = pOld; 
      } 

     } 

寻找GetFeature方法。