简体   繁体   English

DotSpatial shapefile的性能非常慢

[英]Very slow performance with DotSpatial shapefile

I'm trying to read all of the feature data from particular shapefile. 我正在尝试从特定的shapefile中读取所有特征数据。 In this case, I'm using DotSpatial to open the file, and I'm iterating through the features. 在这种情况下,我正在使用DotSpatial打开文件,并且正在遍历功能。 This particular shapefile is only 9mb in size, and the dbf file is 14mb. 这个特定的shapefile大小仅为9mb,而dbf文件为14mb。 There is roughly 75k features to loop through. 大约有75k要素需要循环。

Note, this is all programmatically through a console app, so there is no rendering or anything involved. 请注意,所有这些都是通过控制台应用程序以编程方式进行的,因此没有渲染或任何相关内容。

When loading the shape file, I reproject, then I'm iterating. 加载形状文件时,我重新投影,然后进行迭代。 The loading an reprojecting is super quick. 加载重新投影非常快。 However, as soon as the code reaches my foreach block, it takes nearly 2 full minutes to load the data, and uses roughly 2GB of memory when debugging in VisualStudio. 但是,一旦代码到达我的foreach块,将花费将近2分钟的时间来加载数据,并且在Visual Studio中进行调试时将使用大约2GB的内存。 This seems very, very excessive for what's a reasonably small data file. 对于相当小的数据文件来说,这似乎非常非常过分。

I've ran the same code outside of Visual Studio, from the command line, however the time is still roughly 2 full minutes, and about 1.3GB of memory for the process. 我已经从命令行在Visual Studio外部运行了相同的代码,但是时间仍然大约是2个完整的分钟,大约需要1.3GB的内存。

Is there anyway to speed this up at all? 无论如何,有什么可以加快速度的吗?

Below is my code: 下面是我的代码:

// 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.
}

Interestingly, when I use the VS immediate window, it's super super fast, no delay at all... 有趣的是,当我使用VS立即窗口时,它超级快,根本没有延迟...

I've managed to figure this out... 我设法弄清楚了...

For some reason, calling foreach on the features is painfully slow. 出于某些原因,在功能上调用foreach非常缓慢。

However, as these files have a 1-1 mapping with features - data rows (each feature has a relevant data row), I've modified it slightly to the following. 但是,由于这些文件具有与功能1-1映射的关系-数据行(每个功能都有一个相关的数据行),因此我对其进行了少许修改。 It's now very quick.. less than a second to start the iterations. 现在非常快..不到一秒钟就可以开始迭代。

// 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.
}

I wonder why this would be. 我不知道为什么会这样。 I think I need to look at the iterator on the IFeatureList implementation. 我想我需要查看IFeatureList实现上的迭代器。

Cheers, Justin 干杯,贾斯汀

This has the same problem for very large files (1.2 millions of features), populating .Features collections never ends. 对于很大的文件(120万个功能),填充.Features集合永无止境,也有同样的问题。

But if you ask for the feature you do not have memory or delay overheads. 但是,如果您要求该功能,则没有内存或延迟开销。

        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;
            }

        }

Look for the GetFeature method. 寻找GetFeature方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM