/// <summary> /// Tests the expression typed by user, showing syntax errors /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnTest_Click(object sender, EventArgs e) { MapWinGIS.Table tbl = _shapefile.Table; if (richTextBox1.Text == string.Empty) { MessageBox.Show("No expression is entered", "MapWindow 4", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { object result = null; string err = string.Empty; //if (tbl.ParseExpression(richTextBox1.Text, ref err)) if (tbl.Query(richTextBox1.Text, ref result, ref err)) { lblResult.ForeColor = Color.Green; int[] arr = result as int[]; if (arr != null) { lblResult.Text = "Number of shapes = " + arr.Length.ToString(); // updating shapefile selection if (_selectionMode) { ArrayList options = new ArrayList(); options.Add("1 - New selection"); options.Add("2 - Add to selection"); options.Add("3 - Exclude from selection"); options.Add("4 - Invert in selection"); string s = string.Format("Number of shapes = {0}. Choose the way to update selection", arr.Length); //int option = MapWindow.Controls.Dialogs.ChooseOptions(options, 0, s, "Update selection"); // updating selection //if (option != -1) //{ //_mapWin.View.UpdateSelection(_layerHandle, ref arr, (SelectionOperation)option); //_mapWin.View.Redraw(); //} } } } else { if (err.ToLower() == "selection is empty") { lblResult.ForeColor = Color.Blue; lblResult.Text = err; } else { lblResult.ForeColor = Color.Red; lblResult.Text = err; } } } }
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); }
/// <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); }
public table_properties(MapWinGIS.Table _table) { InitializeComponent(); tb = _table; }
/// <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; }
/// <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); }
/// <summary> /// 触发项目投影改变时事件 /// </summary> public void FireOnUpdateTableJoin(string filename, string fieldNames, string joinOptions, MapWinGIS.Table tableToFill) { if (OnUpdateTableJoin != null) { OnUpdateTableJoin(filename, fieldNames, joinOptions, tableToFill); } }