private void btnQuant_Click(object sender, EventArgs e)
        {
            //Create a new instance for MapWinGIS.Table
            MapWinGIS.Table myTable = new MapWinGIS.Table();
            //Define the data source of Table instance
            myTable.Open(@"D:\GISSampleData2\arabcntry.dbf", null);
            //Define the index of the field will used in symbology
            int myFieldIndex = 1;
            //Get the number of rows in the table
            int numberOfRows = myTable.NumRows;

            //Create an array to store the cell values of the field
            double[] myCellsValues = new double[numberOfRows];
            //Populate the array with cell values restored from the Table instance
            for (int i = 0; i < numberOfRows - 1; i++)
            {
                myCellsValues[i] =
                    System.Convert.ToDouble(myTable.get_CellValue(1, i));
            }
            //Get the minimum and maximum values
            double minValue = myCellsValues.Min();
            double maxValue = myCellsValues.Max();

            //Create a new instance for MapWinGIS.ShapefileColorScheme
            MapWinGIS.ShapefileColorScheme myScheme = new MapWinGIS.ShapefileColorScheme();
            //Set the layer handler to the MapWinGIS.ShapefileColorScheme instance
            myScheme.LayerHandle = intHandler;
            //Set the field index to use in symbology
            myScheme.FieldIndex = myFieldIndex;
            //Create a new instance for MapWinGIS.ShapefileColorBreak
            MapWinGIS.ShapefileColorBreak myBreak = new MapWinGIS.ShapefileColorBreak();
            //Set the minimum value in the field as a start value
            myBreak.StartValue = minValue;
            //Set the start color of the scheme
            myBreak.StartColor =
                (UInt32)(System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Aqua));
            //Set the maximum value in the field as an end value
            myBreak.EndValue = maxValue;
            //Set the end color of the sceme
            myBreak.EndColor =
                (UInt32)(System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.DarkBlue));
            //Add the break to the color scheme
            myScheme.Add(myBreak);
            //Upgrade display using the scheme
            axMap1.ApplyLegendColors(myScheme);
        }
Exemple #2
0
        /// <summary>
        /// 打开指定数据源的图层
        /// </summary>
        /// <param name="filename">文件名</param>
        /// <param name="callback"></param>
        /// <returns></returns>
        public bool Open(string filename, MapWinGIS.ICallback callback)
        {
            this.Close();

            if (filename.ToLower().EndsWith(".shp"))
            {
                MapWinGIS.Shapefile sf = new MapWinGIS.Shapefile();
                if (sf.Open(filename, callback))
                {
                    // 检查dbf是否存在
                    bool error = false;
                    if (!File.Exists(Path.ChangeExtension(sf.Filename, ".dbf")))
                    {
                        m_error = LayerSourceError.DbfIsMissing;
                        error   = true;
                    }

                    // 检查DBF记录数相匹配的形状的数量。
                    MapWinGIS.Table table = new MapWinGIS.Table();
                    table.Open(Path.ChangeExtension(sf.Filename, ".dbf"), null);
                    if (sf.NumShapes != table.NumRows)
                    {
                        m_error = LayerSourceError.DbfRecordCountMismatch;
                        error   = true;
                    }

                    table.Close();

                    if (error)
                    {
                        sf.Close();
                    }
                    else
                    {
                        m_shapefile = sf;
                    }
                    return(!error);
                }
                else
                {
                    m_error       = LayerSourceError.OcxBased;
                    m_ErrorString = sf.get_ErrorMsg(sf.LastErrorCode);
                }
            }
            else
            {
                bool asGrid = true;
                if (filename.ToLower().EndsWith(".tif"))
                {
                    asGrid = false;
                }

                // TODO: 可能更聪明的选择是在grid/image中使用应用程序设置
                if (asGrid)
                {
                    MapWinGIS.Grid grid = new MapWinGIS.Grid();
                    if (grid.Open(filename, MapWinGIS.GridDataType.UnknownDataType, false, MapWinGIS.GridFileType.UseExtension, callback))
                    {
                        m_grid = grid;
                        return(true);
                    }
                }

                // 尝试image
                MapWinGIS.Image image = new MapWinGIS.Image();
                if (image.Open(filename, MapWinGIS.ImageType.USE_FILE_EXTENSION, false, callback))
                {
                    m_image = image;
                    return(true);
                }
                else
                {
                    m_error       = LayerSourceError.OcxBased;
                    m_ErrorString = image.get_ErrorMsg(image.LastErrorCode);
                }
            }
            return(false);
        }