/// <summary> /// The status strip tiles provider double click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void StatusStripTilesProviderDoubleClick(object sender, EventArgs e) { // Enable default tiling again: if (this.axMap1.NumLayers == 0) { // Set map projection: var geoprojection = new GeoProjectionClass(); geoprojection.ImportFromEPSG(3857); this.axMap1.GeoProjection = geoprojection; } this.axMap1.Tiles.Visible = true; this.SetStatusstripControls(); }
private static void GridStatistics() { const string workingFolder = @"D:\dev\GIS-Data\Siebe\NetCDF\"; var currentProcess = Process.GetCurrentProcess(); using (var writer = new StreamWriter(Path.Combine(workingFolder, "GridStatisticsForPolygon.log"), false)) { currentProcess.Refresh(); writer.WriteLine(DateTime.Now + " Starting. Total memory: " + FormatBytes(currentProcess.WorkingSet64)); // Load shapefile with polygons: var sf = new ShapefileClass(); if (!sf.Open(Path.Combine(workingFolder, "ARK.shp"))) { writer.WriteLine( DateTime.Now + " Could not open shapefile. Reason " + sf.ErrorMsg[sf.LastErrorCode]); return; } var numShapes = sf.NumShapes; var netCdfFiles = Directory.GetFiles(workingFolder, "*.nc"); var utils = new UtilsClass(); _settings.ResetGdalError(); var amersfoort = new GeoProjectionClass(); amersfoort.ImportFromEPSG(28992); // Check projection: if (!sf.GeoProjection.IsSame[amersfoort]) { sf.GeoProjection = amersfoort.Clone(); } // Loop through all netCDF files in folder: foreach (var netCdfFile in netCdfFiles) { var grd = new GridClass(); if (!grd.Open(netCdfFile)) { writer.WriteLine(DateTime.Now + " Could not open {0}. Reason: {1}, GDAL Error: {2}", netCdfFile, grd.ErrorMsg[grd.LastErrorCode], _settings.GdalLastErrorMsg); continue; } currentProcess.Refresh(); writer.WriteLine(DateTime.Now + "Loaded grid " + netCdfFile + " Current memory " + FormatBytes(currentProcess.WorkingSet64)); var header = grd.Header; var noDataValue = (double)grd.Header.NodataValue; var extents = grd.Extents; // Set projection: header.GeoProjection = amersfoort.Clone(); // Get each band: var numBands = grd.NumBands; for (var i = 0; i < numBands; i++) { if (!grd.OpenBand(i)) { writer.WriteLine(DateTime.Now + " Could not open band {0}. Reason: {1}, GDAL Error: {2}", i, grd.ErrorMsg[grd.LastErrorCode], _settings.GdalLastErrorMsg); continue; } currentProcess.Refresh(); writer.WriteLine(DateTime.Now + " Working with band {0} Current memory: {1} ", i, FormatBytes(currentProcess.WorkingSet64)); var mean = 0d; var min = 0d; var max = 0d; for (var j = 0; j < numShapes; j++) { var shp = sf.Shape[j]; if ( !utils.GridStatisticsForPolygon(grd, header, extents, shp, noDataValue, ref mean, ref min, ref max)) { writer.WriteLine(DateTime.Now + " Error getting statistics: " + utils.ErrorMsg[utils.LastErrorCode]); } currentProcess.Refresh(); writer.WriteLine(DateTime.Now + " Mean: {0}, Min: {1}, Max: {2}, Current memory: {3}", mean, min, max, FormatBytes(currentProcess.WorkingSet64)); } } // Close grid: grd.Close(); currentProcess.Refresh(); writer.WriteLine(DateTime.Now + " Closed grid Current memory: " + FormatBytes(currentProcess.WorkingSet64)); } currentProcess.Refresh(); writer.WriteLine(DateTime.Now + " Done. Current memory: " + FormatBytes(currentProcess.WorkingSet64)); } Debug.WriteLine("Ready"); }