예제 #1
0
        private static DynamicIsoLineLayer GetDynamicIsoLineLayer()
        {
            // Define the colors for different earthquake magnitude.
            Collection <GeoColor> colorsOfMagnitude = new Collection <GeoColor>()
            {
                GeoColor.FromHtml("#FFFFBE"),
                GeoColor.FromHtml("#FDFF9E"),
                GeoColor.FromHtml("#FDFF37"),
                GeoColor.FromHtml("#FDDA04"),
                GeoColor.FromHtml("#FFA701"),
                GeoColor.FromHtml("#FF6F02"),
                GeoColor.FromHtml("#EC0000"),
                GeoColor.FromHtml("#B90000"),
                GeoColor.FromHtml("#850100"),
                GeoColor.FromHtml("#620001"),
                GeoColor.FromHtml("#450005"),
                GeoColor.FromHtml("#2B0804")
            };

            // Get the file path name from its relative path.
            string shpFilePathName = GetFullPath("App_Data/usEarthquake.shp");

            // Create the layer for IsoLine.
            ShapeFileFeatureSource          featureSource      = new ShapeFileFeatureSource(shpFilePathName);
            Dictionary <PointShape, double> dataPoints         = GetDataPoints(featureSource);
            GridInterpolationModel          interpolationModel = new InverseDistanceWeightedGridInterpolationModel(3, double.MaxValue);
            DynamicIsoLineLayer             isoLineLayer       = new DynamicIsoLineLayer(dataPoints, GetClassBreakValues(dataPoints.Values, 12), interpolationModel, IsoLineType.ClosedLinesAsPolygons);

            // Create the style for different level of earthquake magnitude.
            ClassBreakStyle earthquakeMagnitudeBreakStyle = new ClassBreakStyle(isoLineLayer.DataValueColumnName);

            earthquakeMagnitudeBreakStyle.ClassBreaks.Add(new ClassBreak(double.MinValue, new AreaStyle(new GeoPen(GeoColor.FromHtml("#FE6B06"), 1), new GeoSolidBrush(new GeoColor(100, colorsOfMagnitude[0])))));
            for (int i = 0; i < isoLineLayer.IsoLineLevels.Count - 1; i++)
            {
                earthquakeMagnitudeBreakStyle.ClassBreaks.Add(new ClassBreak(isoLineLayer.IsoLineLevels[i + 1], new AreaStyle(new GeoPen(GeoColor.FromHtml("#FE6B06"), 1), new GeoSolidBrush(new GeoColor(100, colorsOfMagnitude[i + 1])))));
            }
            isoLineLayer.CustomStyles.Add(earthquakeMagnitudeBreakStyle);

            TextStyle textStyle = TextStyles.CreateSimpleTextStyle(isoLineLayer.DataValueColumnName, "Arial", 8, DrawingFontStyles.Bold, GeoColor.StandardColors.Black, 0, 0);

            textStyle.HaloPen               = new GeoPen(GeoColor.StandardColors.White, 2);
            textStyle.OverlappingRule       = LabelOverlappingRule.NoOverlapping;
            textStyle.SplineType            = SplineType.StandardSplining;
            textStyle.DuplicateRule         = LabelDuplicateRule.UnlimitedDuplicateLabels;
            textStyle.TextLineSegmentRatio  = 9999999;
            textStyle.FittingLineInScreen   = true;
            textStyle.SuppressPartialLabels = true;
            textStyle.NumericFormat         = "{0:0.00}";
            isoLineLayer.CustomStyles.Add(textStyle);

            return(isoLineLayer);
        }
예제 #2
0
        private void Initialize()
        {
            Collection <GeoColor> levelAreaColors = new Collection <GeoColor>();

            levelAreaColors.Add(GeoColor.FromHtml("#FFFFBE"));
            levelAreaColors.Add(GeoColor.FromHtml("#FDFF9E"));
            levelAreaColors.Add(GeoColor.FromHtml("#FDFF37"));
            levelAreaColors.Add(GeoColor.FromHtml("#FDDA04"));
            levelAreaColors.Add(GeoColor.FromHtml("#FFA701"));
            levelAreaColors.Add(GeoColor.FromHtml("#FF6F02"));
            levelAreaColors.Add(GeoColor.FromHtml("#EC0000"));
            levelAreaColors.Add(GeoColor.FromHtml("#B90000"));
            levelAreaColors.Add(GeoColor.FromHtml("#850100"));
            levelAreaColors.Add(GeoColor.FromHtml("#620001"));
            levelAreaColors.Add(GeoColor.FromHtml("#450005"));
            levelAreaColors.Add(GeoColor.FromHtml("#2B0804"));

            FeatureSource.Open();

            Dictionary <PointShape, double> dataPoints         = GetDataPoints();
            GridInterpolationModel          interpolationModel = new InverseDistanceWeightedGridInterpolationModel(3, double.MaxValue);

            isoLineLayer = new DynamicIsoLineLayer(dataPoints, GetClassBreakValues(dataPoints.Values, 12), interpolationModel, IsoLineType.ClosedLinesAsPolygons);

            isoLineLayer.CellWidthInPixel  = 32;
            isoLineLayer.CellHeightInPixel = 32;
            levelClassBreakStyle           = new ClassBreakStyle(isoLineLayer.DataValueColumnName);
            levelClassBreakStyle.ClassBreaks.Add(new ClassBreak(double.MinValue, new AreaStyle(new GeoPen(GeoColor.FromHtml("#FE6B06"), 1), new GeoSolidBrush(new GeoColor(100, levelAreaColors[0])))));
            for (int i = 0; i < IsoLineLevels.Count - 1; i++)
            {
                if (!levelClassBreakStyle.ClassBreaks.Any(c => c.Value == IsoLineLevels[i + 1]))
                {
                    levelClassBreakStyle.ClassBreaks.Add(new ClassBreak(IsoLineLevels[i + 1], new AreaStyle(new GeoPen(GeoColor.FromHtml("#FE6B06"), 1), new GeoSolidBrush(new GeoColor(100, levelAreaColors[i + 1])))));
                }
            }
            isoLineLayer.CustomStyles.Add(levelClassBreakStyle);

            TextStyle textStyle = TextStyles.CreateSimpleTextStyle(isoLineLayer.DataValueColumnName, "Arial", 8, DrawingFontStyles.Bold, GeoColor.StandardColors.Black, 0, 0);

            textStyle.HaloPen               = new GeoPen(GeoColor.StandardColors.White, 2);
            textStyle.OverlappingRule       = LabelOverlappingRule.NoOverlapping;
            textStyle.SplineType            = SplineType.StandardSplining;
            textStyle.DuplicateRule         = LabelDuplicateRule.UnlimitedDuplicateLabels;
            textStyle.TextLineSegmentRatio  = 9999999;
            textStyle.FittingLineInScreen   = true;
            textStyle.SuppressPartialLabels = true;
            textStyle.NumericFormat         = "{0:0.00}";
            isoLineLayer.CustomStyles.Add(textStyle);
        }
예제 #3
0
        private void GenerateGrid(string filename)
        {
            //Point based shapefile used to create the GRID (sample points of pH level of a field)
            ShapeFileFeatureLayer pointLayer = new ShapeFileFeatureLayer(@"..\..\data\sample_ph_2.shp");

            //Sets the extent of the grid based on the extent of the sample points shapefile and slightly larger.
            pointLayer.Open();
            RectangleShape gridExtent = pointLayer.GetBoundingBox();

            gridExtent.ScaleUp(5);

            //Gets the data (points with their pH value) to build the GRID.
            Collection <Feature>            features   = pointLayer.FeatureSource.GetAllFeatures(new string[] { "PH" });
            Dictionary <PointShape, double> dataPoints = new Dictionary <PointShape, double>();

            pointLayer.Close();

            foreach (Feature feature in features)
            {
                PointShape pointShape = (PointShape)feature.GetShape();
                double     value      = double.Parse(feature.ColumnValues["PH"]);
                dataPoints.Add(pointShape, value);
            }

            //Cell size based on the width of the extent divided by 100.
            double cellSize = gridExtent.Width / 100;
            //Sets the definition of the GRID with its extent, the cell size, the non value, and the data (point locations with their value)
            //For more information on GRID definition see http://en.wikipedia.org/wiki/ASCII_GRID
            GridDefinition definition = new GridDefinition(gridExtent, cellSize, -9999, dataPoints);

            //Inverse Distance Weighted (IDW) is the interpolation model used for the GRID for assigning values to unknown points
            //based on known neighbor points.
            //http://en.wikipedia.org/wiki/Inverse_distance_weighting
            GridInterpolationModel interpolationModel = new InverseDistanceWeightedGridInterpolationModel();

            FileStream outputStream = new FileStream(filename, FileMode.Create);

            GridFeatureSource.GenerateGrid(definition, interpolationModel, outputStream);
        }
        private void Initialize()
        {
            Collection<GeoColor> levelAreaColors = new Collection<GeoColor>();
            levelAreaColors.Add(GeoColor.FromHtml("#FFFFBE"));
            levelAreaColors.Add(GeoColor.FromHtml("#FDFF9E"));
            levelAreaColors.Add(GeoColor.FromHtml("#FDFF37"));
            levelAreaColors.Add(GeoColor.FromHtml("#FDDA04"));
            levelAreaColors.Add(GeoColor.FromHtml("#FFA701"));
            levelAreaColors.Add(GeoColor.FromHtml("#FF6F02"));
            levelAreaColors.Add(GeoColor.FromHtml("#EC0000"));
            levelAreaColors.Add(GeoColor.FromHtml("#B90000"));
            levelAreaColors.Add(GeoColor.FromHtml("#850100"));
            levelAreaColors.Add(GeoColor.FromHtml("#620001"));
            levelAreaColors.Add(GeoColor.FromHtml("#450005"));
            levelAreaColors.Add(GeoColor.FromHtml("#2B0804"));

            FeatureSource.Open();

            Dictionary<PointShape, double> dataPoints = GetDataPoints();
            GridInterpolationModel interpolationModel = new InverseDistanceWeightedGridInterpolationModel(3, double.MaxValue);
            isoLineLayer = new DynamicIsoLineLayer(dataPoints, IsoLineLayer.GetIsoLineLevels(dataPoints.Values, 12), interpolationModel, IsoLineType.ClosedLinesAsPolygons);

            IsoLineLayer.GetIsoLineLevels(dataPoints, 12);

            levelClassBreakStyle = new ClassBreakStyle(isoLineLayer.DataValueColumnName);
            levelClassBreakStyle.ClassBreaks.Add(new ClassBreak(double.MinValue, new AreaStyle(new GeoPen(GeoColor.FromHtml("#FE6B06"), 1), new GeoSolidBrush(new GeoColor(100, levelAreaColors[0])))));
            for (int i = 0; i < IsoLineLevels.Count - 1; i++)
            {
                levelClassBreakStyle.ClassBreaks.Add(new ClassBreak(IsoLineLevels[i + 1], new AreaStyle(new GeoPen(GeoColor.FromHtml("#FE6B06"), 1), new GeoSolidBrush(new GeoColor(100, levelAreaColors[i + 1])))));
            }
            isoLineLayer.CustomStyles.Add(levelClassBreakStyle);

            TextStyle textStyle = TextStyles.CreateSimpleTextStyle(isoLineLayer.DataValueColumnName, "Arial", 8, DrawingFontStyles.Bold, GeoColor.StandardColors.Black, 0, 0);
            textStyle.HaloPen = new GeoPen(GeoColor.StandardColors.White, 2);
            textStyle.OverlappingRule = LabelOverlappingRule.NoOverlapping;
            textStyle.SplineType = SplineType.StandardSplining;
            textStyle.DuplicateRule = LabelDuplicateRule.UnlimitedDuplicateLabels;
            textStyle.TextLineSegmentRatio = 9999999;
            textStyle.FittingLineInScreen = true;
            textStyle.SuppressPartialLabels = true;
            textStyle.NumericFormat = "{0:0.00}";
            isoLineLayer.CustomStyles.Add(textStyle);
        }