使用点空间形状文件的性能非常慢



我正在尝试从特定的形状文件中读取所有特征数据。在本例中,我使用 DotSpatial 打开文件,并循环访问功能。这个特定的形状文件的大小只有9mb,dbf文件的大小是14mb。大约有 75k 个功能可以循环。

请注意,这一切都是通过控制台应用以编程方式进行的,因此不涉及任何呈现或任何内容。

加载形状文件时,我重新投影,然后进行迭代。加载重新投影非常快。但是,一旦代码到达我的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 即时窗口时,它非常快,完全没有延迟......

对于非常大的文件(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 方法。

我已经设法弄清楚了...

出于某种原因,调用功能非常缓慢。

但是,由于这些文件与特征 - 数据行(每个特征都有一个相关的数据行(具有 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实现的迭代器。

干杯贾斯汀

最新更新