【发布时间】:2020-03-27 05:12:46
【问题描述】:
我已经下载了以下地图:
andorra-latest.osm.pbf https://download.geofabrik.de/europe/andorra-latest.osm.pbf
azores-latest.osm.pbf https://download.geofabrik.de/europe/azores-latest.osm.pbf
cyprus-latest.osm.pbf https://download.geofabrik.de/europe/cyprus-latest.osm.pbf
我需要合并以上地图。所以我使用osmconvert 来合并地图。我读了this answer about merging maps。因此,如果我复制以下命令并粘贴到 command window 中,那么它可以正常工作 - 它会创建 all.osm.pbf 文件:
因此创建了所需的文件all.osm.pbf:
但是,现在我想以编程方式调用此命令。我的意思是,我想通过 C# 调用上述命令。所以我在我的控制台应用程序中尝试了这段代码:
static Process process = new Process();
static void Main(string[] args)
{
process.EnableRaisingEvents = true;
process.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(process_OutputDataReceived);
process.ErrorDataReceived += new System.Diagnostics.DataReceivedEventHandler(process_ErrorDataReceived);
process.Exited += new System.EventHandler(process_Exited);
process.StartInfo.FileName = @"osmconvert.exe";
process.StartInfo.Arguments = @"osmconvert.exe andorra-latest.osm.pbf --out-o5m | osmconvert.exe - azores-latest.osm.pbf | osmconvert.exe - cyprus-latest.osm.pbf -o=all.osm.pbf";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;
process.Start();
process.BeginErrorReadLine();
process.BeginOutputReadLine();
}
但我总是看到以下错误:
我的文件位于D:\Downloads:
你能说,我做错了什么吗?
更新:
我试过这段代码,但是错误是一样的:
process.StartInfo.FileName = @"D:\Downloads\osmconvert.exe";
process.StartInfo.Arguments = @"D:\Downloads\osmconvert.exe D:\Downloads\andorra-latest.osm.pbf --out-o5m | D:\Downloads\osmconvert.exe - D:\Downloads\azores-latest.osm.pbf | D:\Downloads\osmconvert.exe - D:\Downloads\cyprus-latest.osm.pbf -o=D:\Downloads\all.osm.pbf";
这种方法:
process.StartInfo.FileName = @"D:\\Downloads\\osmconvert.exe";
process.StartInfo.Arguments = @"D:\\Downloads\\osmconvert.exe D:\\Downloads\\andorra-latest.osm.pbf --out-o5m | D:\\Downloads\\osmconvert.exe - D:\\Downloads\\azores-latest.osm.pbf | D:\\Downloads\\osmconvert.exe - D:\\Downloads\\cyprus-latest.osm.pbf -o=D:\\Downloads\\all.osm.pbf";
【问题讨论】:
-
你到底想做什么?启动三个文件的进程?将输出通过管道传输到另一个可执行文件?因为管道在这里没有任何意义。如果你只是想用三个文件启动可执行文件,那么一个接一个地启动它们
-
尝试将完整或相对路径传递给您的地图,而不仅仅是文件名。
-
你需要把所有文件和文件夹的完整路径名。 Process 类以空环境 PATH 开头,因此找不到可执行文件。
-
@scai 感谢您的回复。怎么给相对地图?
-
@Learner 尝试传递
D:\\Downloads\\azores-latest.osm.pbf而不是azores-latest.osm.pbf。
标签: c# openstreetmap