Beispiel #1
0
        //查询所在区域
        private String FindMapInRegion(double x, double y, String tableName, String colName)
        {
            String ret = "";

            try
            {
                MapInfo.Data.MIConnection connection = new MapInfo.Data.MIConnection();
                connection.Open();
                MapInfo.Data.MICommand command = connection.CreateCommand();
                command.CommandText = "Select * from " + tableName + " where MI_Point(@x, @y, @cs) within obj";
                command.Parameters.Add("@x", x);
                command.Parameters.Add("@y", y);
                command.Parameters.Add("@cs", this.mapControl.Map.GetDisplayCoordSys());
                command.Prepare();
                MapInfo.Data.IResultSetFeatureCollection irfc = command.ExecuteFeatureCollection();
                if (irfc.Count > 0)
                {
                    ret = irfc[0][colName].ToString();
                }
                command.Dispose();
                connection.Close();
            }
            catch { }
            return(ret);

            /*
             * Feature ftr1 = new Feature(tableTemp.TableInfo.Columns);
             * ftr1.Geometry = new MapInfo.Geometry.Point(mapControl.Map.GetDisplayCoordSys(), new DPoint(113.70, 23.04)) as FeatureGeometry;
             * MapInfo.Data.SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchWithinFeature(ftr1, ContainsType.Geometry);
             * si.QueryDefinition.Columns = null;
             * MapInfo.Data.IResultSetFeatureCollection irfc = MapInfo.Engine.Session.Current.Catalog.Search("chinagl_guide", si);
             * if(irfc.Count > 0)
             *  MessageBox.Show(irfc[0]["Name"].ToString());
             * else MessageBox.Show("null");*/
        }
Beispiel #2
0
        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            UpdateNavigationButtons();
            this.components = new System.ComponentModel.Container();

            //
            // Create a command object to hold parameters and last command executed
            //
            this.miConnection = new MIConnection();
            miConnection.Open();
            this.miCommand = miConnection.CreateCommand();
        }
Beispiel #3
0
        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            UpdateNavigationButtons();
            this.components = new System.ComponentModel.Container();

            //
            // Create a command object to hold parameters and last command executed
            //
            this.miConnection = new MIConnection();
            miConnection.Open();
            this.miCommand = miConnection.CreateCommand();
        }
Beispiel #4
0
 private void SetDataGrid(DataGrid dataGrid, string commandText, bool bShowSchema)
 {
     MapInfo.Data.MIConnection miConnection = new MIConnection();
     miConnection.Open();
     MapInfo.Data.MICommand miCommand = miConnection.CreateCommand();
     miCommand.CommandText = commandText;
     MapInfo.Data.MIDataReader miReader = null;
     try
     {
         miReader = miCommand.ExecuteReader();
         if (bShowSchema)
         {
             dataGrid.DataSource = miReader.GetSchemaTable();
         }
         else
         {
             DataTable dt = new DataTable("Data");
             for (int index = 0; index < miReader.FieldCount; index++)
             {
                 DataColumn dc = dt.Columns.Add(miReader.GetName(index));
             }
             while (miReader.Read())
             {
                 DataRow dr = dt.NewRow();
                 for (int index = 0; index < miReader.FieldCount; index++)
                 {
                     dr[index] = miReader.GetValue(index);
                 }
                 dt.Rows.Add(dr);
             }
             dataGrid.DataSource = dt;
         }
     }
     catch (Exception)
     {
         SelectClauseTextBox.Text += " ***Wrong select clause, try it.***";
     }
     finally
     {
         if (miReader != null)
         {
             miReader.Close();
         }
     }
 }