/// <summary> /// Example of how to plot a mesh file. A mesh contains bottom levels in each node. /// </summary> public static void MeshTest(bool makeBmp) { DHI.Chart.Map.Chart.Init(); // Load mesh data string pathName = Path.Combine(UnitTestHelper.TestDataRoot, @"oresund.mesh"); MeshFile meshFile = MeshFile.ReadMesh(pathName); // FemGridData is data for the bottom levels, a value in each element node, used for coloring FemGridData data = new FemGridData(); data.CreateNodesAndElements(meshFile.NumberOfNodes, meshFile.NumberOfElements, meshFile.X, meshFile.Y, meshFile.Z.ToFloatArray(), meshFile.ElementTable); // Create chart DHI.Chart.Map.Chart chart = new DHI.Chart.Map.Chart(); // Add overlay that plots the bottom levels FemGridOverlay overlay = new FemGridOverlay(); overlay.SetGridData(data); overlay.EnableNiceValue = true; overlay.CreateAutoScaledRainbowPalette(); overlay.EnableIsoline = true; overlay.ColoringType = MapOverlay.EColoringType.ContinuousColoring; overlay.SetFeathering(true, 0.5f); overlay.EnableIsolineLabel = true; chart.AddOverlay(overlay); // Grab map projection of meshfile MapProjection mapProj = new MapProjection(meshFile.ProjectionString); double lonOrigin, latOrigin, eastOrigin, northOrigin; mapProj.GetOrigin(out lonOrigin, out latOrigin); mapProj.Geo2Proj(lonOrigin, latOrigin, out eastOrigin, out northOrigin); double convergence = mapProj.GetConvergence(lonOrigin, latOrigin); // Overlay adding geographical lines // Mesh is drawn in map projection coordinates GeoGridOverlay ggOverlay = new GeoGridOverlay(); ggOverlay.ReferenceProjection = meshFile.ProjectionString; ggOverlay.DisplayProjection = meshFile.ProjectionString; // Origin for mesh data is the origin of the projection ggOverlay.SetGeoOrigin(lonOrigin, latOrigin); ggOverlay.SetOrigin(eastOrigin, northOrigin); // Mesh overlay draws in map projection coordinates, so north-Y rotation is the convergence (which is zero) ggOverlay.SetNYCRotation(convergence); ggOverlay.EnableLonLatGrid = true; ggOverlay.EnableMapProjGrid = true; // DataValid must be set after changing in GeoGridOverlay ggOverlay.DataValid = true; chart.AddOverlay(ggOverlay); // Select rectangle to plot, by default the full data area MzRectangle wrect = new MzRectangle(); data.GetDataArea(wrect); // Here you may limit the area to be plotted //wrect.X0 = wrect.X0 + 20000; //wrect.Y0 = wrect.Y0 + 20000; //wrect.X1 = wrect.X0 + 30000; //wrect.Y1 = wrect.Y0 + 30000; chart.SetDataArea(wrect); chart.SetView(wrect); //chart.GetActiveCoordinateSystem().SetDrawAxis(true, true); //chart.GetActiveCoordinateSystem().EnableBorder(true); //chart.DrawGrid = true; //chart.DrawTitle = true; // Draw to bitmap double ratio = wrect.Width / (double)wrect.Height; Bitmap bmp = new Bitmap(((int)(ratio * 1024)) + 10, 1024); chart.Draw(bmp); chart.Dispose(); if (makeBmp) { string pngFilepath = Path.Combine(UnitTestHelper.TestDataRoot, @"oresundMesh.png"); bmp.Save(pngFilepath); System.Diagnostics.Process.Start(pngFilepath); } }