Juz*_*ott 2 c# shapefile dotspatial
我正在尝试从特定形状文件中读取所有特征数据。在本例中,我使用 DotSpatial 打开文件,并迭代这些功能。这个特定的 shapefile 文件大小仅为 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.
}
Run Code Online (Sandbox Code Playgroud)
有趣的是,当我使用VS立即窗口时,它超级超级快,完全没有延迟......
小智 5
对于非常大的文件(120 万个特征),这也存在同样的问题,填充 .Features 集合永远不会结束。
但如果您需要该功能,则没有内存或延迟开销。
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;
}
}
Run Code Online (Sandbox Code Playgroud)
查找 GetFeature 方法。
| 归档时间: |
|
| 查看次数: |
3835 次 |
| 最近记录: |