I'm tyring to convert a shapefile to MapInfo using ogr2ogr. (C#/.NET 6)
I get the following error when running the code below: Unable to open datasource [directory path]\file.mif
.
However, If I open cmd.exe in the ogr2ogr directory and copy/paste the argument, it executes and the shapefile is converted to .mif/.mid, as I would expect it to.
command line argument = ogr2ogr -f "MapInfo File" -overwrite -dsco FORMAT=MIF "[directory path]\Polygon.mif" "[directory path]\Polygon.shp"
Code:
var ogr2ogrPath = "[directory path]\\ogr2ogr.exe"
ProcessStartInfo StartInfo = new ProcessStartInfo() {
FileName = ogr2ogrPath,
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
Arguments = $"ogr2ogr -f \"MapInfo File\" -overwrite -dsco FORMAT=MIF \"[directory path]\file.mif\" \"[directory path]\file.shp\"",
};
var streamOutput = "";
using(var shellProcess = Process.Start(StartInfo)) {
StreamReader readerStdOut = shellProcess.StandardError;
while (readerStdOut.EndOfStream == false) {
streamOutput += readerStdOut.ReadLine() + Environment.NewLine;
}
shellProcess.WaitForExit();
streamOutput += " - Finished " + Environment.NewLine;
}
C:\\example\\test.shp