private GeometryModel3D GetGeographyPlaneGeometry(CountryGeography geography, OxyColor color, double opacity = 0.25) { int i = 0; var landBlocks = geography.LandBlocks.OrderByDescending(b => b.TotalArea); GeometryModel3D countryGeometry = new GeometryModel3D(); var mapColor = new Color() { A = color.A, R = color.R, G = color.G, B = color.B }; var material = MaterialHelper.CreateMaterial(mapColor, opacity); countryGeometry.Material = material; countryGeometry.BackMaterial = material; var geographyBuilder = new MeshBuilder(false, false); foreach (var boundary in landBlocks) { List <List <DataPoint> > simpleAreaSet = SimplifyBoundary(boundary); foreach (var simpleArea in simpleAreaSet) { var areaPts = new List <Point3D>() { }; foreach (var vertex in simpleArea) { areaPts.Add(new Point3D(vertex.X, vertex.Y, 0)); } Point3DCollection area = new Point3DCollection(areaPts); Polygon3D poly3D = new Polygon3D(area); geographyBuilder.AddPolygon(area); } // just do the 10 biggest bits per country (looks to be enough) i++; if (i > 10) { break; } } countryGeometry.Geometry = geographyBuilder.ToMesh(); return(countryGeometry); }
private int AddNationsCountryGeographyPlane(Model3DGroup modelGroup, List <Color> stdColors, int geographyIndex, string name) { var nation = GeographyProvider.Nations.FirstOrDefault(g => g.Name == name); CountryGeography geography = nation?.Geography; if (geography != null) { var colour = stdColors[(geographyIndex % stdColors.Count)]; GeometryModel3D geographyGeometry = DiagramUtilities.GetGeographyPlaneGeometry(geography, colour, 0.4); modelGroup.Children.Add(geographyGeometry); geographyIndex++; } return(geographyIndex); }
private void AddGeographiesForNationsWithoutBooksRead(Model3DGroup modelGroup) { if (_mainModel.Nations != null && _mainModel.Nations.Count > 0) { List <string> authorCountries = _mainModel.AuthorCountries.Select(x => x.Country).ToList(); foreach (Nation nation in _mainModel.Nations) { CountryGeography geography = nation.Geography; if (geography != null && !authorCountries.Contains(geography.Name)) { GeometryModel3D geographyGeometry = GetGeographyPlaneGeometry(geography, OxyColors.LightGray); modelGroup.Children.Add(geographyGeometry); } } } }
private static void AddCountryGeographyToPlot( PlotModel newPlot, Dictionary <string, int> countryToReadLookUp, List <OxyColor> colors, CountryGeography country) { OxyColor color = OxyColors.LightGray; string tagString = ""; if (countryToReadLookUp.ContainsKey(country.Name)) { color = colors[countryToReadLookUp[country.Name]]; tagString = "\nBooks Read = " + countryToReadLookUp[country.Name].ToString(); } string trackerFormat = "{0}\nLat/Long ( {4:0.###} ,{2:0.###} )" + tagString; OxyPlotUtilities.AddCountryGeographyAreaSeriesToPlot(newPlot, country, color, country.Name, tagString, trackerFormat); }
private int AddNationsCountryGeographyPlane(Model3DGroup modelGroup, List <OxyColor> stdColors, int geographyIndex, string name) { var nation = _mainModel.Nations.Where(g => g.Name == name).FirstOrDefault(); if (nation != null) { CountryGeography geography = nation.Geography; if (geography != null) { var colour = stdColors[(geographyIndex % stdColors.Count)]; GeometryModel3D geographyGeometry = GetGeographyPlaneGeometry(geography, colour, 0.4); modelGroup.Children.Add(geographyGeometry); geographyIndex++; } } return(geographyIndex); }
public static void AddCountryGeographyAreaSeriesToPlot( PlotModel newPlot, CountryGeography country, OxyColor colour, string title, string tag, string trackerFormat) { int i = 0; IOrderedEnumerable <PolygonBoundary> landBlocks = country.LandBlocks.OrderByDescending(b => b.TotalArea); foreach (var boundary in landBlocks) { AreaSeries areaSeries = new AreaSeries { Color = colour, Title = title, RenderInLegend = false, Tag = tag }; List <PolygonPoint> points = boundary.Points; if (points.Count > PolygonReducer.MaxPolygonPoints) { points = PolygonReducer.AdaptativePolygonReduce(points, PolygonReducer.MaxPolygonPoints); } foreach (PolygonPoint point in points) { double ptX; double ptY; point.GetCoordinates(out ptX, out ptY); DataPoint dataPoint = new DataPoint(ptX, ptY); areaSeries.Points.Add(dataPoint); } areaSeries.TrackerFormatString = trackerFormat; newPlot.Series.Add(areaSeries); // just do the 10 biggest bits per country (looks to be enough) i++; if (i > 10) { break; } } }
/// <summary> /// Sets up the plot model to be displayed. /// </summary> /// <returns>The plot model.</returns> protected override PlotModel SetupPlot() { // Create the plot model PlotModel newPlot = new PlotModel { Title = "Countries of the World and Books Read" }; SetupLatitudeAndLongitudeAxes(newPlot); // make up a lit of the countries with books read int maxBooksRead = -1; Dictionary <string, int> countryToReadLookUp = new Dictionary <string, int>(); foreach (AuthorCountry authorCountry in BooksReadProvider.AuthorCountries) { maxBooksRead = Math.Max(authorCountry.TotalBooksReadFromCountry, maxBooksRead); countryToReadLookUp.Add(authorCountry.Country, authorCountry.TotalBooksReadFromCountry); } List <OxyColor> colors; OxyPalette faintPalette; maxBooksRead = OxyPlotUtilities.SetupFaintPaletteForRange(maxBooksRead, out colors, out faintPalette, 128); foreach (Nation nation in GeographyProvider.Nations) { CountryGeography country = nation.Geography; if (country != null) { AddCountryGeographyToPlot(newPlot, countryToReadLookUp, colors, country); } } newPlot.Axes.Add(new LinearColorAxis { Position = AxisPosition.Right, Palette = faintPalette, Title = "Books Read", Maximum = maxBooksRead, Minimum = 0 }); // finally update the model with the new plot return(newPlot); }
protected int AddCountryGeographyPlane(Model3DGroup modelGroup, List <Color> stdColors, int geographyIndex, string name) { CountryGeography geography = null; foreach (CountryGeography countryGeography in GeographyProvider.CountryGeographies) { if (countryGeography != null && countryGeography.Name == name) { geography = countryGeography; break; } } if (geography != null) { Color colour = stdColors[(geographyIndex % stdColors.Count)]; GeometryModel3D geographyGeometry = DiagramUtilities.GetGeographyPlaneGeometry(geography, colour, 0.4); modelGroup.Children.Add(geographyGeometry); geographyIndex++; } return(geographyIndex); }
/// <summary> /// Sets up the plot model to be displayed. /// </summary> /// <returns>The plot model.</returns> protected override PlotModel SetupPlot() { // Create the plot model PlotModel newPlot = new PlotModel { Title = "Countries of the World" }; SetupLatitudeAndLongitudeAxes(newPlot); int flagCount = 0; foreach (Nation nation in GeographyProvider.Nations) { CountryGeography country = nation.Geography; if (country != null) { OxyColor colour = OxyColors.LightGreen; string title = country.Name; string tag = ""; string trackerFormat = "{0}"; OxyPlotUtilities.AddCountryGeographyAreaSeriesToPlot(newPlot, country, colour, title, tag, trackerFormat); } if (!string.IsNullOrEmpty(nation.ImageUri) && flagCount < 100) { PolygonPoint capitalCity = new PolygonPoint(nation.Longitude, nation.Latitude); double x, y; capitalCity.GetCoordinates(out x, out y); WebRequest req = WebRequest.Create(nation.ImageUri); Stream stream = req.GetResponse().GetResponseStream(); if (stream == null) { continue; } Bitmap bitmap = new Bitmap(stream); MemoryStream memoryStream = new MemoryStream(); bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Bmp); byte[] asBytes = memoryStream.ToArray(); ImageFormat typeOfImage = GetImageFormat(asBytes); if (typeOfImage == ImageFormat.Unknown) { continue; } OxyImage image = new OxyImage(asBytes); newPlot.Annotations.Add( new ImageAnnotation { ImageSource = image, Opacity = 0.5, X = new PlotLength(x, PlotLengthUnit.Data), Y = new PlotLength(y, PlotLengthUnit.Data), Width = new PlotLength(30, PlotLengthUnit.ScreenUnits), Height = new PlotLength(20, PlotLengthUnit.ScreenUnits), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Middle }); flagCount++; } } // finally update the model with the new plot return(newPlot); }