private void Callback_MapControl_RasterReprojected(object sender, Events.MapControl_RasterReprojected e) { Console.WriteLine("Finished"); Image img = new Image(); if (img.Open(e.rasterLayer.FileName)) { string proj = img.GetProjection(); int layerHandle = AxMap.AddLayer(img, true); if (layerHandle == -1) { Events.MapControl_Error imghandle_error = new Events.MapControl_Error() { ErrorCode = Events.ErrorCodes.CouldNotLoadLayer, InMethod = "AddRasterLayer", AxMapError = new GlobalSettings().GdalLastErrorMsg }; On_Error(imghandle_error); } e.rasterLayer.Handle = layerHandle; MapControlTools.Layers.Add(e.rasterLayer); Events.MapControl_LayerChange layerchange = new Events.MapControl_LayerChange() { LayerChangeReason = Events.LayerChangeReason.AddLayer, Layer = e.rasterLayer }; On_LayerChange(layerchange); } }
public void Run(string filename, string fileLocation, RasterLayer r) { string localData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); var output = localData + "\\ResTBDesktop\\temp\\" + filename; var options = new[] { "-t_srs", "EPSG:3857", "-overwrite" }; var gdalUtils = new GdalUtils(); RasterReprojectCallback callback = new RasterReprojectCallback(r, MapControlTools); gdalUtils.GlobalCallback = callback; if (!gdalUtils.GdalRasterWarp(fileLocation, output, options)) { Events.MapControl_Error imghandle_error = new Events.MapControl_Error() { ErrorCode = Events.ErrorCodes.GdalWarpError, InMethod = "AddRasterLayer", AxMapError = "GdalWarp failed: " + gdalUtils.ErrorMsg[gdalUtils.LastErrorCode] + " Detailed error: " + gdalUtils.DetailedErrorMsg }; MapControlTools.On_Error(imghandle_error); } if (MapControl_RasterReprojected != null) { Events.MapControl_RasterReprojected eventArgs = new Events.MapControl_RasterReprojected(); eventArgs.rasterLayer = r; MapControl_RasterReprojected(this, eventArgs); } Events.MapControl_BusyStateChange bc = new Events.MapControl_BusyStateChange(); bc.BusyState = Events.BusyState.Idle; bc.KeyOfSender = "Rasterreprojected"; bc.Percent = 100; bc.Message = ""; MapControlTools.On_BusyStateChange(bc); }