Exemple #1
0
        private void menu_Click(object sender, EventArgs e)
        {
            FormContour Frm = new FormContour();

            Frm.layers = App.Map.GetRasterLayers();

            if (Frm.layers.GetLength(0) <= 0)
            {
                MessageBox.Show("No raster layer found!");
                return;
            }

            if (Frm.ShowDialog() == DialogResult.OK)
            {
                IMapFeatureLayer fl = App.Map.Layers.Add(Frm.Contours);
                fl.LegendText = Frm.LayerName + " - Contours";

                int numlevs = Frm.lev.GetLength(0);

                switch (Frm.contourtype)
                {
                    case (Contour.ContourType.Line):
                        {
                            LineScheme ls = new LineScheme();
                            ls.Categories.Clear();

                            for (int i = 0; i < Frm.color.GetLength(0); i++)
                            {
                                LineCategory lc = new LineCategory(Frm.color[i], 2.0);

                                lc.FilterExpression = "[Value] = " + Frm.lev[i].ToString();
                                lc.LegendText = Frm.lev[i].ToString();

                                ls.AddCategory(lc);
                            }

                            fl.Symbology = ls;
                        }
                        break;

                    case (Contour.ContourType.Polygon):
                        {
                            PolygonScheme ps = new PolygonScheme();
                            ps.Categories.Clear();

                            for (int i = 0; i < Frm.color.GetLength(0); i++)
                            {
                                PolygonCategory pc = new PolygonCategory(Frm.color[i], Color.Transparent, 0);
                                pc.FilterExpression = "[Lev] = " + i.ToString();
                                pc.LegendText = Frm.lev[i].ToString() + " - " + Frm.lev[i + 1].ToString();

                                ps.AddCategory(pc);
                            }

                            fl.Symbology = ps;
                        }
                        break;
                }
            }
        }
Exemple #2
0
        private void Configure(IFeatureSet inFeatureSet)
        {
            if (inFeatureSet == null) throw new ArgumentNullException("inFeatureSet");
            if (inFeatureSet.FeatureType != FeatureType.Polygon) throw new PolygonFeatureTypeException();

            Symbology = new PolygonScheme();
            Symbology.SetParentItem(this);
        }
Exemple #3
0
 private void Configure(IFeatureSet inFeatureSet)
 {
     if (inFeatureSet.FeatureType != FeatureType.Polygon)
     {
         throw new PolygonFeatureTypeException();
     }
     PolygonScheme ps = new PolygonScheme();
     ps.SetParentItem(this);
     Symbology = ps;
 }
Exemple #4
0
        private void Configure(IFeatureSet inFeatureSet)
        {
            if (inFeatureSet.FeatureType != FeatureType.Polygon)
            {
                throw new PolygonFeatureTypeException();
            }
            PolygonScheme ps = new PolygonScheme();

            ps.SetParentItem(this);
            Symbology = ps;
        }
        public void TestSetViewExtents()
        {
            Map mainMap = new Map();
            mainMap.Projection = KnownCoordinateSystems.Projected.World.WebMercator;

            Extent defaultMapExtent = new Extent(-130, 5, -70, 60);

            string baseMapFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestFiles");
            //SetDefaultMapExtents(mainMap);
            MapPolygonLayer layStates;

            MapGroup baseGroup = new MapGroup(mainMap.Layers, mainMap.MapFrame, mainMap.ProgressHandler);
            baseGroup.LegendText = "Base Map Data";
            baseGroup.ParentMapFrame = mainMap.MapFrame;
            baseGroup.MapFrame = mainMap.MapFrame;
            baseGroup.IsVisible = true;

            //load the 'Countries of the world' layer
            try
            {
                string fileName = Path.Combine(baseMapFolder, "50m_admin_0_countries.shp");
                IFeatureSet fsCountries = FeatureSet.OpenFile(fileName);
                fsCountries.Reproject(mainMap.Projection);
                MapPolygonLayer layCountries = new MapPolygonLayer(fsCountries);
                layCountries.LegendText = "Countries";
                PolygonScheme schmCountries = new PolygonScheme();
                schmCountries.EditorSettings.StartColor = Color.Orange;
                schmCountries.EditorSettings.EndColor = Color.Silver;
                schmCountries.EditorSettings.ClassificationType =
                    ClassificationType.UniqueValues;
                schmCountries.EditorSettings.FieldName = "NAME";
                schmCountries.EditorSettings.UseGradient = true;
                schmCountries.CreateCategories(layCountries.DataSet.DataTable);
                layCountries.Symbology = schmCountries;
                baseGroup.Layers.Add(layCountries);
                layCountries.MapFrame = mainMap.MapFrame;
            }
            catch { }
            //load U.S. states layer
            try
            {
                string fileName = Path.Combine(baseMapFolder, "50mil_us_states.shp");
                IFeatureSet fsStates = FeatureSet.OpenFile(fileName);
                fsStates.Reproject(mainMap.Projection);
                layStates = new MapPolygonLayer(fsStates);
                PolygonScheme schmStates = new PolygonScheme();
                layStates.IsVisible = true;
                layStates.LegendText = "U.S. States";
                schmStates.EditorSettings.StartColor = Color.LemonChiffon;
                schmStates.EditorSettings.EndColor = Color.LightPink;
                schmStates.EditorSettings.ClassificationType =
                    ClassificationType.UniqueValues;
                schmStates.EditorSettings.FieldName = "NAME";
                schmStates.EditorSettings.UseGradient = true;
                schmStates.CreateCategories(layStates.DataSet.DataTable);
                layStates.Symbology = schmStates;
                baseGroup.Layers.Add(layStates);
                layStates.MapFrame = mainMap.MapFrame;
            }
            catch { }
            //load Canada Provinces layer
            try
            {
                string fileName = Path.Combine(baseMapFolder, "50mil_canada_provinces.shp");
                IFeatureSet fsProvince = FeatureSet.OpenFile(fileName);
                fsProvince.Reproject(mainMap.Projection);
                MapPolygonLayer layProvince = new MapPolygonLayer(fsProvince);
                PolygonScheme schmProvince = new PolygonScheme();
                layProvince.IsVisible = true;
                layProvince.LegendText = "Canada Provinces";
                schmProvince.EditorSettings.StartColor = Color.Green;
                schmProvince.EditorSettings.EndColor = Color.Yellow;
                schmProvince.EditorSettings.ClassificationType =
                    ClassificationType.UniqueValues;
                schmProvince.EditorSettings.FieldName = "NAME";
                schmProvince.EditorSettings.UseGradient = true;
                schmProvince.CreateCategories(layProvince.DataSet.DataTable);
                layProvince.Symbology = schmProvince;
                baseGroup.Layers.Add(layProvince);
                layProvince.MapFrame = mainMap.MapFrame;
            }
            catch { }

            

            //theme data group
            //create a new empty 'themes' data group
            try
            {
                MapGroup themeGroup = new MapGroup(mainMap.Layers,
                    mainMap.MapFrame, mainMap.ProgressHandler);
                themeGroup.ParentMapFrame = mainMap.MapFrame;
                themeGroup.MapFrame = mainMap.MapFrame;
                themeGroup.LegendText = "Themes";
            }
            catch { }

            double[] xy = new double[4];
            xy[0] = defaultMapExtent.MinX;
            xy[1] = defaultMapExtent.MinY;
            xy[2] = defaultMapExtent.MaxX;
            xy[3] = defaultMapExtent.MaxY;
            double[] z = new double[] { 0, 0 };
            string esri = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223562997]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]";
            ProjectionInfo wgs84 = ProjectionInfo.FromEsriString(esri);
            Reproject.ReprojectPoints(xy, z, wgs84, mainMap.Projection, 0, 2);

            xy[0] = 1000000000000000;
            xy[1] = 2000000000000000;
            xy[2] = 3000000000000000;
            xy[3] = 4000000000000000;
            Extent ext = new Extent(xy);
            mainMap.ViewExtents = ext;
        }
        /// <summary>
        /// Creates a new raster with the specified cell size.  If the cell size
        /// is zero, this will default to the shorter of the width or height
        /// divided by 256.  If the cell size produces a raster that is greater
        /// than 8, 000 pixels in either dimension, it will be re-sized to
        /// create an 8, 000 length or width raster.
        /// </summary>
        /// <param name="fs">The featureset to convert to a raster.</param>
        /// <param name="extent">Force the raster to this specified extent.</param>
        /// <param name="cellSize">The double extent of the cell.</param>
        /// <param name="fieldName">The integer field index of the file.</param>
        /// <param name="outputFileName">The fileName of the raster to create.</param>
        /// <param name="driverCode">The optional GDAL driver code to use if using GDAL
        /// for a format that is not discernable from the file extension.  An empty string
        ///  is usually perfectly acceptable here.</param>
        /// <param name="options">For GDAL rasters, they can be created with optional parameters
        ///  passed in as a string array.  In most cases an empty string is perfectly acceptable.</param>
        /// <param name="progressHandler">An interface for handling the progress messages.</param>
        /// <returns>Generates a raster from the vectors.</returns>
        public static IRaster ToRaster(IFeatureSet fs, Extent extent, double cellSize, string fieldName,
                                       string outputFileName,
                                       string driverCode, string[] options, IProgressHandler progressHandler)
        {
            Extent env = extent;
            if (cellSize == 0)
            {
                if (env.Width < env.Height)
                {
                    cellSize = env.Width / 256;
                }
                else
                {
                    cellSize = env.Height / 256;
                }
            }
            int w = (int)Math.Ceiling(env.Width / cellSize);
            if (w > 8000)
            {
                w = 8000;
                cellSize = env.Width / 8000;
            }
            int h = (int)Math.Ceiling(env.Height / cellSize);
            if (h > 8000)
            {
                h = 8000;
            }
            Bitmap bmp = new Bitmap(w, h);
            Graphics g = Graphics.FromImage(bmp);
            g.Clear(Color.Transparent);
            g.SmoothingMode = SmoothingMode.None;
            g.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
            g.InterpolationMode = InterpolationMode.NearestNeighbor;
            Hashtable colorTable;
            MapArgs args = new MapArgs(new Rectangle(0, 0, w, h), env, g);

            switch (fs.FeatureType)
            {
                case FeatureType.Polygon:
                    {
                        MapPolygonLayer mpl = new MapPolygonLayer(fs);
                        PolygonScheme ps = new PolygonScheme();
                        colorTable = ps.GenerateUniqueColors(fs, fieldName);
                        mpl.Symbology = ps;
                        mpl.DrawRegions(args, new List<Extent> { env });
                    }
                    break;
                case FeatureType.Line:
                    {
                        MapLineLayer mpl = new MapLineLayer(fs);
                        LineScheme ps = new LineScheme();
                        colorTable = ps.GenerateUniqueColors(fs, fieldName);
                        mpl.Symbology = ps;
                        mpl.DrawRegions(args, new List<Extent> { env });
                    }
                    break;
                default:
                    {
                        MapPointLayer mpl = new MapPointLayer(fs);
                        PointScheme ps = new PointScheme();
                        colorTable = ps.GenerateUniqueColors(fs, fieldName);
                        mpl.Symbology = ps;
                        mpl.DrawRegions(args, new List<Extent> { env });
                    }
                    break;
            }
            Type tp = fieldName == "FID" ? typeof(int) : fs.DataTable.Columns[fieldName].DataType;
            // We will try to convert to double if it is a string
            if (tp == typeof(string))
            {
                tp = typeof(double);
            }
            InRamImageData image = new InRamImageData(bmp, env);
            ProgressMeter pm = new ProgressMeter(progressHandler, "Converting To Raster Cells", h);

            IRaster output;
            output = Raster.Create(outputFileName, driverCode, w, h, 1, tp, options);
            output.Bounds = new RasterBounds(h, w, env);

            double noDataValue = output.NoDataValue;

            if (fieldName != "FID")
            {
                // We can't use this method to calculate Max on a non-existent FID field.
                double dtMax = Convert.ToDouble(fs.DataTable.Compute("Max(" + fieldName + ")", ""));
                double dtMin = Convert.ToDouble(fs.DataTable.Compute("Min(" + fieldName + ")", ""));

                if (dtMin <= noDataValue && dtMax >= noDataValue)
                {
                    if (dtMax != GetFieldValue(tp, "MaxValue"))
                    {
                        output.NoDataValue = noDataValue;
                    }
                    else if (dtMin != GetFieldValue(tp, "MinValue"))
                    {
                        output.NoDataValue = noDataValue;
                    }
                }
            }

            List<RcIndex> locations = new List<RcIndex>();
            List<string> failureList = new List<string>();
            for (int row = 0; row < h; row++)
            {
                for (int col = 0; col < w; col++)
                {
                    Color c = image.GetColor(row, col);
                    if (c.A == 0)
                    {
                        output.Value[row, col] = output.NoDataValue;
                    }
                    else
                    {
                        if (colorTable.ContainsKey(c) == false)
                        {
                            if (c.A < 125)
                            {
                                output.Value[row, col] = output.NoDataValue;
                                continue;
                            }

                            // Use a color matching distance to pick the closest member
                            object val = GetCellValue(w, h, row, col, image, c, colorTable, locations);

                            output.Value[row, col] = GetDouble(val, failureList);
                        }
                        else
                        {
                            output.Value[row, col] = GetDouble(colorTable[c], failureList);
                        }
                    }
                }
                pm.CurrentValue = row;
            }
            const int maxIterations = 5;
            int iteration = 0;
            while (locations.Count > 0)
            {
                List<RcIndex> newLocations = new List<RcIndex>();
                foreach (RcIndex location in locations)
                {
                    object val = GetCellValue(w, h, location.Row, location.Column, image,
                                              image.GetColor(location.Row, location.Column), colorTable, newLocations);
                    output.Value[location.Row, location.Column] = GetDouble(val, failureList);
                }
                locations = newLocations;
                iteration++;
                if (iteration > maxIterations)
                {
                    break;
                }
            }

            pm.Reset();
            return output;
        }
Exemple #7
0
        private void AssociateToGrid()
        {

            IFeatureSet fT = null;
            IMapPolygonLayer tem = null;
            foreach (IMapPolygonLayer ila in this.map.GetPolygonLayers())
            {
                fT = (IFeatureSet)ila.DataSet;
                tem = ila;
                if (ila.LegendText == "Grid")
                    break;
            }
            if (fT == null)
                return;
            Stat stat = new Stat(false);
            foreach (IFeature fea in fT.Features)
            {
                IFeature center = fea.Centroid();
                double st = dataK.Interpolate(center.Coordinates[0].X, center.Coordinates[0].Y, center.Coordinates[0].Z, true)[0];
                fea.DataRow["Field"] = st;
                stat += new Stat(st);
            }
            fT.Save();

            tem.DataSet.FillAttributes();
            PolygonScheme polScheme = new PolygonScheme();
            polScheme.EditorSettings.FieldName = "Field";
            polScheme.EditorSettings.ClassificationType = ClassificationType.Custom;

            // polScheme.EditorSettings.StartColor = Color.Green;
            // polScheme.EditorSettings.EndColor = Color.Magenta;
            //// polScheme.EditorSettings.UseColorRange = true;

            // polScheme.EditorSettings.RampColors = true;
            for (int i = 0; i < 12; i++)
            {
                PolygonCategory cat = new PolygonCategory();
                cat.SetColor(Color.FromArgb(i * 20, 50, 250 - (i * 20)));

                cat.Range = new Range(stat.Min + (i - 1) * (stat.Max - stat.Min) / 10, stat.Min + (i) * (stat.Max - stat.Min) / 10);
                cat.FilterExpression = string.Format("[Field]>{0} AND [Field]<={1}", Math.Round((double)cat.Range.Minimum, 3), Math.Round((double)cat.Range.Maximum, 3));
                cat.LegendText = string.Format("{0} - {1}", Math.Round((double)cat.Range.Minimum, 3), Math.Round((double)cat.Range.Maximum, 3));
                polScheme.AddCategory(cat);
            }

            tem.Symbology = polScheme;
            //  tem.ApplyScheme(polScheme);
            map.ResetBuffer();
        }