コード例 #1
0
        private void AddCountryPagesPins(Model3DGroup modelGroup, List <OxyColor> colors, AuthorCountry authorCountry,
                                         string name, WorldCountry country)
        {
            int pagesCount = (int)authorCountry.TotalPagesReadFromCountry;
            int booksCount = (int)authorCountry.TotalBooksReadFromCountry;

            var    pagesLookup = (int)_countryToLogPagesLookUp[authorCountry.Country];
            var    maxPages    = _countryToLogPagesLookUp.Values.OrderByDescending(x => x).FirstOrDefault();
            double height      = (12.0 * (double)pagesLookup) / ((double)maxPages);

            if (height < 1.0)
            {
                height = 1.0;
            }

            GeometryModel3D countryGeometry =
                GetCountryOctahedronGeometry(country.Latitude, country.Longitude,
                                             height, colors[pagesLookup], booksCount);

            modelGroup.Children.Add(countryGeometry);

            string label =
                string.Format("{0}\nLat/Long ( {1:0.###} ,{2:0.###} ) \nTotal Pages {3}",
                              name, country.Latitude, country.Longitude, pagesCount);

            TextVisual3D countryText =
                GetCountryText(country.Latitude, country.Longitude, pagesCount, label, height);

            modelGroup.Children.Add(countryText.Content);
        }
コード例 #2
0
        private void AddCountryPagesSpiral(Model3DGroup modelGroup, List <Color> colors, AuthorCountry authorCountry,
                                           string name, WorldCountry country)
        {
            int pagesCount = (int)authorCountry.TotalPagesReadFromCountry;

            int    pagesLookup = (int)_countryToLogPagesLookUp[authorCountry.Country];
            uint   maxPages    = _countryToLogPagesLookUp.Values.OrderByDescending(x => x).FirstOrDefault();
            double height      = (12.0 * pagesLookup) / maxPages;

            if (height < 1.0)
            {
                height = 1.0;
            }

            GeometryModel3D countryGeometry =
                DiagramUtilities.GetCountryHelixArrowGeometry(country.Latitude, country.Longitude, height, colors[pagesLookup]);

            modelGroup.Children.Add(countryGeometry);

            string label =
                $"{name}\nLat/Long ( {country.Latitude:0.###} ,{country.Longitude:0.###} ) \nTotal Pages {pagesCount}";

            TextVisual3D countryText =
                DiagramUtilities.GetCountryText(country.Latitude, country.Longitude, pagesCount, label, height);

            modelGroup.Children.Add(countryText.Content);
        }
コード例 #3
0
ファイル: GeoData.cs プロジェクト: mcavigelli/wpf-samples
 private bool ContainsRegion(WorldCountry item)
 {
     foreach (var region in Regions)
     {
         var regionName = item.Region.Replace(" ", "").ToLower();
         if (regionName == region.Replace(" ", "").ToLower())
         {
             return(true);
         }
     }
     return(false);
 }
        private void AddBooksAndPagesScatterSeries(PlotModel newPlot)
        {
            ScatterSeries pointsSeries;

            OxyPlotUtilities.CreateScatterPointSeries(out pointsSeries,
                                                      ChartAxisKeys.LongitudeKey, ChartAxisKeys.LatitudeKey, "Countries");

            foreach (AuthorCountry authorCountry in BooksReadProvider.AuthorCountries)
            {
                string       name    = authorCountry.Country;
                WorldCountry country = GeographyProvider.WorldCountries.FirstOrDefault(w => w.Country == name);
                if (country != null)
                {
                    int pointSize = authorCountry.TotalBooksReadFromCountry;
                    if (pointSize < 5)
                    {
                        pointSize = 5;
                    }

                    PolygonPoint latLong = new PolygonPoint()
                    {
                        Latitude = country.Latitude, Longitude = country.Longitude
                    };
                    double x, y;
                    latLong.GetCoordinates(out x, out y);

                    ScatterPoint point =
                        new ScatterPoint(x, y, pointSize,
                                         authorCountry.TotalPagesReadFromCountry)
                    {
                        Tag = name
                    };
                    pointsSeries.Points.Add(point);
                }
            }
            pointsSeries.RenderInLegend      = false;
            pointsSeries.TrackerFormatString = "{Tag}\nLat/Long ( {4:0.###} ,{2:0.###} ) \nTotalPages {6}";
            newPlot.Series.Add(pointsSeries);

            List <OxyColor> colors = new List <OxyColor>();

            foreach (OxyColor color in OxyPalettes.Jet(200).Colors)
            {
                OxyColor faintColor = OxyColor.FromArgb(128, color.R, color.G, color.B);
                colors.Add(faintColor);
            }

            OxyPalette faintPalette = new OxyPalette(colors);

            newPlot.Axes.Add(new LinearColorAxis {
                Position = AxisPosition.Right, Palette = faintPalette, Title = "Total Pages"
            });
        }
コード例 #5
0
        /// <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 in Location with Books Read Plot"
            };

            OxyPlotUtilities.SetupPlotLegend(newPlot, "Countries in Location with Books Read Plot");
            SetupLatitudeAndLongitudeAxes(newPlot);

            // create series and add them to the plot
            ScatterSeries pointsSeries;

            OxyPlotUtilities.CreateScatterPointSeries(out pointsSeries,
                                                      ChartAxisKeys.LongitudeKey, ChartAxisKeys.LatitudeKey, "Countries");

            foreach (AuthorCountry authorCountry in BooksReadProvider.AuthorCountries)
            {
                string       name    = authorCountry.Country;
                WorldCountry country = GeographyProvider.WorldCountries.FirstOrDefault(w => w.Country == name);
                if (country != null)
                {
                    var pointSize = authorCountry.TotalBooksReadFromCountry;
                    if (pointSize < 5)
                    {
                        pointSize = 5;
                    }

                    ScatterPoint point =
                        new ScatterPoint(country.Longitude, country.Latitude, pointSize,
                                         authorCountry.TotalBooksReadFromCountry)
                    {
                        Tag = name
                    };
                    pointsSeries.Points.Add(point);
                }
            }

            pointsSeries.TrackerFormatString = "{Tag}\nLat/Long ( {4:0.###} ,{2:0.###} ) \nTotal Books {6}";
            newPlot.Series.Add(pointsSeries);

            List <OxyColor> colors =
                OxyPalettes.Jet(200).Colors.Select(color => OxyColor.FromArgb(128, color.R, color.G, color.B)).ToList();

            OxyPalette faintPalette = new OxyPalette(colors);

            newPlot.Axes.Add(new LinearColorAxis
            {
                Position = AxisPosition.Right, Palette = faintPalette, Title = "Books Read"
            });

            return(newPlot);
        }
コード例 #6
0
        public override void SetupModel()
        {
            Model3DGroup modelGroup = new Model3DGroup();

            // get the range of colours for the for the countries
            int range = BooksReadProvider.AuthorCountries.Count > 0 ?
                        BooksReadProvider.AuthorCountries.Select(s => s.TotalBooksReadFromCountry).Max() : 5;
            List <Color> colors;

            ColorUtilities.SetupFaintPaletteForRange(range, out colors, 128);
            List <Color> stdColors = ColorUtilities.SetupStandardColourSet();

            int geographyIndex = 0;

            // set up lookups of the countries with numbers read
            int maxBooksPages;
            int maxBooksLogPages;
            Dictionary <string, long> countryToReadLookUp;
            Dictionary <string, uint> countryToPagesLookUp;
            Dictionary <string, uint> countryToLogPagesLookUp;

            SetupCountyPagesLookups(out maxBooksPages, out maxBooksLogPages,
                                    out countryToReadLookUp, out countryToPagesLookUp, out countryToLogPagesLookUp);
            _countryToLogPagesLookUp = countryToLogPagesLookUp;


            foreach (AuthorCountry authorCountry in BooksReadProvider.AuthorCountries.OrderByDescending(x => x.TotalBooksReadFromCountry))
            {
                string       name    = authorCountry.Country;
                WorldCountry country = GeographyProvider.WorldCountries.FirstOrDefault(w => w.Country == name);
                if (country != null)
                {
                    AddCountryPagesSpiral(modelGroup, colors, authorCountry, name, country);
                }

                if (GeographyProvider.CountryGeographies != null && GeographyProvider.CountryGeographies.Count > 0)
                {
                    geographyIndex = AddCountryGeographyPlane(modelGroup, stdColors, geographyIndex, name);
                }
            }

            AddGeographiesForCountriesWithoutBooksRead(modelGroup);

            PagesByCountryModel = modelGroup;
        }
コード例 #7
0
        private void UpdateBookLocationDeltas()
        {
            // clear the list and the counts
            BookLocationDeltas.Clear();
            if (BooksRead.Count < 1)
            {
                return;
            }
            DateTime startDate = BooksRead[0].Date;

            // get all the dates a book has been read (after the first quarter)
            Dictionary <DateTime, DateTime> bookReadDates = GetBookReadDates(startDate);

            // then add the delta made up of the books up to that date
            foreach (DateTime date in bookReadDates.Keys.ToList())
            {
                BookLocationDelta delta = new BookLocationDelta(date, startDate);
                foreach (var book in BooksRead)
                {
                    if (book.Date <= date)
                    {
                        WorldCountry country = GetCountryForBook(book);
                        if (country != null)
                        {
                            BookLocation location =
                                new BookLocation()
                            {
                                Book = book, Latitude = country.Latitude, Longitude = country.Longitude
                            };

                            delta.BooksLocationsToDate.Add(location);
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                //delta.UpdateTallies();
                BookLocationDeltas.Add(delta);
            }
        }
コード例 #8
0
        public static void AddCountryBooksEllipsoid(
            Model3DGroup modelGroup,
            List <Color> colors,
            AuthorCountry authorCountry,
            string name,
            WorldCountry country)
        {
            int booksCount = authorCountry.TotalBooksReadFromCountry;

            GeometryModel3D countryGeometry =
                GetCountryEllipsoidArrowGeometry(country.Latitude, country.Longitude, booksCount, colors[booksCount]);

            modelGroup.Children.Add(countryGeometry);

            string label =
                $"{name}\nLat/Long ( {country.Latitude:0.###} ,{country.Longitude:0.###} ) \nTotal Books {booksCount}";

            TextVisual3D countryText =
                GetCountryText(country.Latitude, country.Longitude, booksCount, label);

            modelGroup.Children.Add(countryText.Content);
        }
コード例 #9
0
        public override void SetupModel()
        {
            Model3DGroup modelGroup = new Model3DGroup();

            // get the range of colours for the for the countries
            int range = BooksReadProvider.AuthorCountries.Count > 0 ?
                        BooksReadProvider.AuthorCountries.Select(s => s.TotalBooksReadFromCountry).Max() : 5;
            List <Color> colors;

            ColorUtilities.SetupFaintPaletteForRange(range, out colors, 128);
            List <Color> stdColors = ColorUtilities.SetupStandardColourSet();

            int geographyIndex = 0;

            foreach (AuthorCountry authorCountry in BooksReadProvider.AuthorCountries.OrderByDescending(x => x.TotalBooksReadFromCountry))
            {
                string       name    = authorCountry.Country;
                WorldCountry country = GeographyProvider.WorldCountries.FirstOrDefault(w => w.Country == name);
                if (country != null)
                {
                    DiagramUtilities.AddCountryBooksEllipsoid(modelGroup, colors, authorCountry, name, country);
                }

                if (GeographyProvider.CountryGeographies != null && GeographyProvider.CountryGeographies.Count > 0)
                {
                    geographyIndex = AddCountryGeographyPlane(modelGroup, stdColors, geographyIndex, name);
                }
            }

            AddGeographiesForCountriesWithoutBooksRead(modelGroup);

            double       maxHeight = Math.Log(range);
            TubeVisual3D path      = GetPathForMeanReadingLocation(maxHeight);

            modelGroup.Children.Add(path.Content);

            BooksReadByCountryModel = modelGroup;
        }
コード例 #10
0
        private void AddCountryBooksEllipsoid(Model3DGroup modelGroup, List <OxyColor> colors,
                                              AuthorCountry authorCountry, string name, WorldCountry country)
        {
            var booksCount = authorCountry.TotalBooksReadFromCountry;

            GeometryModel3D countryGeometry =
                GetCountryEllipsoidArrowGeometry(country.Latitude, country.Longitude, booksCount, colors[booksCount]);

            modelGroup.Children.Add(countryGeometry);

            string label =
                string.Format("{0}\nLat/Long ( {1:0.###} ,{2:0.###} ) \nTotal Books {3}",
                              name, country.Latitude, country.Longitude, booksCount);

            TextVisual3D countryText =
                GetCountryText(country.Latitude, country.Longitude, booksCount, label);

            modelGroup.Children.Add(countryText.Content);
        }
コード例 #11
0
        public static WorldCountries ProcessWorldCountries(ShapefileConverter shapefile)
        {
            var countries = new WorldCountries();

            foreach (ShapefileRecord record in shapefile)
            {
                var item = new WorldCountry();
                if (record.Fields != null)
                {
                    // get geo-shape from shape file (SHP)
                    item.LoadPoints(record.Points);
                    //location.Longitude = record.Points[0][0].X;
                    //location.Latitude = record.Points[0][0].Y;

                    // get data about a country from old database file (DBF)
                    if (record.Fields.ContainsKey("CODE"))
                    {
                        item.CountryCode = (string)(record.Fields["CODE"]);
                    }
                    if (record.Fields.ContainsKey("CNTRY_NAME"))
                    {
                        item.CountryName = (string)(record.Fields["CNTRY_NAME"]);
                    }
                    if (record.Fields.ContainsKey("POP_CNTRY"))
                    {
                        item.Population = (double)(record.Fields["POP_CNTRY"]);
                    }

                    // get data about a country from new database file (DBF)
                    if (record.Fields.ContainsKey("ISO_2_CODE"))
                    {
                        item.CountryCode = (string)(record.Fields["ISO_2_CODE"]);
                    }
                    if (record.Fields.ContainsKey("NAME"))
                    {
                        item.CountryName = (string)(record.Fields["NAME"]);
                    }
                    if (record.Fields.ContainsKey("REGION"))
                    {
                        item.Region = (string)(record.Fields["REGION"]);
                    }
                    if (record.Fields.ContainsKey("POP2005"))
                    {
                        item.Population = (double)(record.Fields["POP2005"]);
                    }
                    if (record.Fields.ContainsKey("AREA"))
                    {
                        item.Area = (double)(record.Fields["AREA"]);
                    }

                    if (item.Population < 0)
                    {
                        item.Population = 0;
                    }
                    if (item.Area < 0)
                    {
                        item.Area = 0;
                    }

                    if (item.CountryName == "US" || item.CountryName == "USA")
                    {
                        item.CountryName = "United States";
                    }
                    if (item.CountryName == "UK" || item.CountryName == "GB")
                    {
                        item.CountryName = "United Kingdom";
                    }

                    item.Label = "Country: " + item.CountryName + ", " + item.Region
                                 + Environment.NewLine + "Population: " + String.Format("{0:#,##0,,.0 M}", item.Population)
                                 + Environment.NewLine + "Area: " + String.Format("{0:#,##0,.0 K}", item.Area);

                    // update countries stats
                    countries.Population.Update(item.Population);
                    countries.Area.Update(item.Area);

                    // add an item to data collection
                    countries.Add(item);
                }
            }
            countries.Sort((x, y) => - x.Population.CompareTo(y.Population));
            return(countries);
        }