GDAL Warping in C#

2.6k views Asked by At

I haven't worked on GDAL libraries till date. Please excuse me if this question does not make any sense.

I am trying to implement warping of Images from EPSG:32611 to EPSG: 3857. I was able to successfully warp using the following commands using command line. I want to implement the same set of commands in my C# project. I am not sure where to start. I could not find any GDAL wrapper library for C#. Any help on this would be appreciated.

These are the commands I run in my command line. Raw.png is the source image.

gdal_translate -of Gtiff -co "tfw=yes" -a_ullr 273996.1204 5070668.029 274682.6204 5069981.529 -a_srs "EPSG:3857"  "C:/Temp/Raw.png" "C:/Temp/GEOTIFF.gtiff"

gdalwarp -s_srs EPSG:32611 -t_srs EPSG:3857 "C:/Temp/GEOTIFF.gtiff" "C:/Temp/WarpedGTIFF.tiff"

gdal_translate -of PNG "C:/Temp/WarpedGTIFF.tiff" "C:/Temp/WarpedPNG.png"

Thanks!!!

1

There are 1 answers

0
Programmer2.0 On

The below code is the fix!!

 System.Diagnostics.Process process = new System.Diagnostics.Process();
 System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
 startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
 startInfo.FileName = "cmd.exe";
 startInfo.Arguments = "gdal_translate -of Gtiff -co "tfw=yes" -a_ullr 273996.1204 5070668.029 274682.6204 5069981.529 -a_srs "EPSG:3857"  "C:/Temp/Raw.png" "C:/Temp/GEOTIFF.gtiff"";
 process.StartInfo = startInfo;
 process.Start();

 process.WaitForExit();
 startInfo.Arguments = "gdalwarp -s_srs EPSG:32611 -t_srs EPSG:3857 "C:/Temp/GEOTIFF.gtiff" "C:/Temp/WarpedGTIFF.tiff"";
 process.StartInfo = startInfo;
 process.Start();

 process.WaitForExit();
 startInfo.Arguments = "gdal_translate -of PNG "C:/Temp/WarpedGTIFF.tiff" "C:/Temp/WarpedPNG.png"";
 process.StartInfo = startInfo;
 process.Start();

Thanks DJ KRAZE!!!