C# 点空间形状文件的性能非常慢

C# 点空间形状文件的性能非常慢,c#,shapefile,dotspatial,C#,Shapefile,Dotspatial,我试图从特定的shapefile读取所有的特征数据。在本例中,我使用DotSpatial打开该文件,并遍历这些特性。这个特殊的形状文件只有9mb大小,而dbf文件是14mb。大约有75k个功能需要循环使用 注意,这都是通过一个控制台应用程序以编程方式实现的,因此不涉及渲染或任何内容 加载形状文件时,我会重新投影,然后进行迭代。重新投影的加载速度非常快。但是,一旦代码到达我的foreach块,加载数据就需要将近2分钟的时间,在VisualStudio中进行调试时大约需要2GB的内存。对于一个相当小

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

注意,这都是通过一个控制台应用程序以编程方式实现的,因此不涉及渲染或任何内容

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

我已经在VisualStudio之外的命令行上运行了相同的代码,但是时间仍然大约为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 immediate窗口时,它超级快速,一点也不延迟…

我已经设法解决了这个问题

出于某种原因,在特性上调用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.
}
//加载形状文件并将其投影到GDA94
Shapefile indexMapFile=Shapefile.OpenFile(shapeFilePath);
indexMapFile.Reproject(KnownCoordinationSystems.Geographic.Australia.GeocentricDatumofAustralia1994);
//从要素数据中获取地图索引
for(int i=0;i
我想知道为什么会这样。我想我需要看看IFeatureList实现中的迭代器

干杯,
贾斯汀

我已经设法解决了这个问题

出于某种原因,在特性上调用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.
}
//加载形状文件并将其投影到GDA94
Shapefile indexMapFile=Shapefile.OpenFile(shapeFilePath);
indexMapFile.Reproject(KnownCoordinationSystems.Geographic.Australia.GeocentricDatumofAustralia1994);
//从要素数据中获取地图索引
for(int i=0;i
我想知道为什么会这样。我想我需要看看IFeatureList实现中的迭代器

干杯,
Justin

对于非常大的文件(120万个功能)来说,这也有同样的问题。功能集合永远不会结束

但是,如果您要求提供该功能,您就没有内存或延迟开销

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

        }
intlrows=fs.NumRows();
对于(int i=0;i

寻找GetFeature方法。

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

但是,如果您要求提供该功能,您就没有内存或延迟开销

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

        }
intlrows=fs.NumRows();
对于(int i=0;i

寻找GetFeature方法。

indexMapFile.DataTable.Rows.Count语句似乎正在将整个文件加载到内存中,如果是大型数据集,则需要花费大量时间。事实上,我从来没有用这个来浏览过一个文件。
indexMapFile.DataTable.Rows.Count
语句似乎正在将整个文件加载到内存中,如果是大型数据集,则需要花费大量时间。事实上,我从来没有用这个来浏览过一个文件。这个解决方案工作得很好,在内存上也很软。这个解决方案工作得很好,在内存上也很软。