Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        private void table_properties_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < tb.NumFields; i++)
            {
                dgv.Columns.Add(Convert.ToString(i), tb.Field[i].Name);
            }

            for (int i = 0; i < tb.NumRows; i++)
            {
                DataGridViewRow row = (DataGridViewRow)dgv.Rows[0].Clone();
                for (int j = 0; j < tb.NumFields; j++)
                {
                    row.Cells[j].Value = tb.get_CellValue(j, i);
                }
                dgv.Rows.Add(row);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Showing values
        /// </summary>
        private void ShowValues(int FieldIndex)
        {
            _noEvents = true;
            dgvValues.Rows.Clear();

            if (_shapefile.NumFields - 1 < FieldIndex)
            {
                _noEvents = false;
                return;
            }

            MapWinGIS.Table tbl = _shapefile.Table;
            object          obj = null;
            SortedDictionary <object, int> hashTable = new SortedDictionary <object, int>();

            bool isString = (_shapefile.get_Field(FieldIndex).Type == MapWinGIS.FieldType.STRING_FIELD);

            if (true)
            {
                this.Cursor = Cursors.WaitCursor;

                for (int i = 0; i < tbl.NumRows; i++)
                {
                    obj = tbl.get_CellValue(FieldIndex, i);
                    if (hashTable.ContainsKey(obj))
                    {
                        hashTable[obj] += 1;
                    }
                    else
                    {
                        hashTable.Add(obj, 1);
                    }
                }
                int[]    values = hashTable.Values.ToArray();
                object[] keys   = hashTable.Keys.ToArray();

                dgvValues.Rows.Add(values.Length);
                for (int i = 0; i < values.Length; i++)
                {
                    if (isString)
                    {
                        dgvValues[1, i].Value = "\"" + keys[i].ToString() + "\"";
                    }
                    else
                    {
                        dgvValues[1, i].Value = keys[i].ToString();
                    }
                    dgvValues[0, i].Value = values[i];
                }

                this.Cursor = Cursors.Default;
            }
            else

            // field stats: aren't used currently
            {
                // for numeric fields we shall provide statistics
                dgvValues.Rows.Add(7);
                dgvValues[0, 0].Value = "Avg";
                dgvValues[0, 1].Value = "StDev";
                dgvValues[0, 2].Value = "0%";
                dgvValues[0, 3].Value = "25%";
                dgvValues[0, 4].Value = "50%";
                dgvValues[0, 5].Value = "75%";
                dgvValues[0, 6].Value = "100%";

                List <object> list = new List <object>();
                for (int i = 0; i < tbl.NumRows; i++)
                {
                    list.Add((object)tbl.get_CellValue(FieldIndex, i));
                }
                list.Sort();

                int quater = list.Count / 4;
                for (int i = 0; i < list.Count; i++)
                {
                    if (i == quater)
                    {
                        dgvValues[1, 3].Value = list[i];
                    }
                    else if (i == quater * 2)
                    {
                        dgvValues[1, 4].Value = list[i];
                    }
                    else if (i == quater * 3)
                    {
                        dgvValues[1, 5].Value = list[i];
                    }
                }

                dgvValues[1, 0].Value = (float)tbl.get_MeanValue(FieldIndex);
                dgvValues[1, 1].Value = (float)tbl.get_StandardDeviation(FieldIndex);
                dgvValues[1, 2].Value = tbl.get_MinValue(FieldIndex);
                dgvValues[1, 6].Value = tbl.get_MaxValue(FieldIndex);
            }

            dgvValues.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
            _noEvents = false;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Inserts shapes with the given indices in the specified table.
        /// </summary>
        /// <returns>Number of inserted shapes. -1 if the table doesn't exist.</returns>
        public int InsertShapes(MapWinGIS.Shapefile sf, string tableName, int[] indices)
        {
            this.CheckConnection();

            int count = 0;

            using (DbTransaction dbTrans = m_connection.BeginTransaction())
            {
                using (DbCommand cmd = this.CreateCommand())
                {
                    DbParameter param = this.CreateBinaryParameter();
                    param.SourceColumn  = "Geometry";
                    param.ParameterName = "@Geometry";
                    cmd.Parameters.Add(param);

                    // generating sql and parameters
                    int    fieldCount = sf.NumFields;
                    string sql        = "INSERT INTO [" + tableName + "] ([Geometry], ";
                    string values     = "VALUES (?, ";

                    for (int j = 0; j < fieldCount; j++)
                    {
                        param = this.CreateParameter();

                        MapWinGIS.Field fld = sf.get_Field(j);
                        switch (fld.Type)
                        {
                        case MapWinGIS.FieldType.STRING_FIELD:

                            param.DbType = DbType.StringFixedLength;
                            param.Size   = fld.Width;
                            break;

                        case MapWinGIS.FieldType.INTEGER_FIELD:
                            param.DbType = DbType.Int32;
                            break;

                        case MapWinGIS.FieldType.DOUBLE_FIELD:
                            param.DbType = DbType.Double;
                            break;
                        }

                        param.ParameterName = "@p" + j.ToString();
                        param.SourceColumn  = fld.Name;
                        cmd.Parameters.Add(param);

                        sql    += "[" + fld.Name + "]";
                        sql    += (j == fieldCount - 1) ? ") " : ", ";
                        values += (j == fieldCount - 1) ? "?)" : "?, ";
                    }
                    cmd.CommandText = sql + values;
                    cmd.Transaction = dbTrans;
                    cmd.Connection  = m_connection;
                    System.Diagnostics.Debug.Print(cmd.CommandText);

                    // adding new records
                    DbParameterCollection paramters = cmd.Parameters;
                    MapWinGIS.Table       table     = sf.Table;
                    int maxSize = 0;
                    int percent = 0;

                    for (int i = 0; i < sf.NumShapes; i++)
                    {
                        if (m_callback != null && m_showCallback)
                        {
                            int newPercent = (int)((double)i / (double)(sf.NumShapes - 1) * 100.0);
                            if (newPercent != percent)
                            {
                                m_callback.Progress("", newPercent, "Exporting shapes...");
                                percent = newPercent;
                            }
                        }

                        object          data  = null;
                        MapWinGIS.Shape shape = sf.get_Shape(i);

                        if (shape.ExportToBinary(ref data))
                        {
                            if ((data as byte[]).Length > maxSize)
                            {
                                maxSize = (data as byte[]).Length;
                            }

                            paramters[0].Value = data as byte[];
                            for (int j = 0; j < fieldCount; j++)
                            {
                                paramters[j + 1].Value = table.get_CellValue(j, i);
                            }
                            if (cmd.ExecuteNonQuery() != 0)
                            {
                                count++;
                            }
                        }
                    }

                    if (m_callback != null && m_showCallback)
                    {
                        m_callback.Progress("", 100, "");
                    }
                }
                dbTrans.Commit();
            }
            return(count);
        }