首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DotSpatial shapefile的性能非常慢

DotSpatial shapefile的性能非常慢
EN

Stack Overflow用户
提问于 2016-02-12 15:06:13
回答 2查看 3.3K关注 0票数 1

我正在尝试读取特定shapefile中的所有特征数据。在本例中,我使用DotSpatial打开文件,并遍历特性。这个特殊的shapefile只有9mb大小,而dbf文件是14mb。大约有75k个特征需要循环。

请注意,所有这些都是通过控制台应用程序编程实现的,因此不需要渲染或任何相关内容。

当加载形状文件时,我重新投影,然后进行迭代。加载一个重投影是超级快的。然而,一旦代码到达我的foreach块,就需要将近2分钟的时间来加载数据,并且在VisualStudio中调试时使用大约2 2GB的内存。对于一个相当小的数据文件来说,这似乎非常、非常过分。

我已经在Visual Studio之外从命令行运行了相同的代码,但是时间仍然大约是整整2分钟,进程大约需要1.3 of的内存。

有没有什么办法可以加速这一切呢?

下面是我的代码:

代码语言:javascript
复制
// 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即时窗口时,它超级快,没有任何延迟……

EN

回答 2

Stack Overflow用户

发布于 2016-02-12 17:31:35

我已经想出办法了.

由于某些原因,在特性上调用foreach的速度非常慢。

但是,由于这些文件具有特征-数据行的一对一映射(每个特征都有一个相关的数据行),我对其进行了稍微修改,如下所示。现在很快了..不到一秒就可以开始迭代。

代码语言:javascript
复制
// 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实现上的迭代器。

干杯,贾斯汀

票数 4
EN

Stack Overflow用户

发布于 2017-06-07 05:30:34

这对于非常大的文件(120万个特征)也有同样的问题,填充.Features集合永远不会结束。

但是,如果您请求该功能,则没有内存或延迟开销。

代码语言:javascript
复制
        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方法。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35356697

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档