Ejemplo n.º 1
0
        private void FillDropDown(string tableName, string colName)
        {
            MapInfo.Mapping.Map map = null;

            // Get the map
            if (MapInfo.Engine.Session.Current.MapFactory.Count == 0 ||
                (map = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias]) == null)
            {
                return;
            }

            DropDownList1.Items.Clear();
            MapInfo.Mapping.FeatureLayer fl = (MapInfo.Mapping.FeatureLayer)map.Layers[tableName];
            MapInfo.Data.Table           t  = fl.Table;
            MIDataReader tr;
            MIConnection con = new MIConnection();
            MICommand    tc  = con.CreateCommand();

            tc.CommandText = "select " + colName + " from " + t.Alias;
            con.Open();
            tr = tc.ExecuteReader();
            while (tr.Read())
            {
                DropDownList1.Items.Add(tr.GetString(0));
            }
            tc.Cancel();
            tc.Dispose();
            tr.Close();
            con.Close();
            //t.Close();
        }
Ejemplo n.º 2
0
        public FormFindSample()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //

            //
            // Create a connection object and open it.
            //
            this._miConnection = new MIConnection();
            _miConnection.Open();

            //
            // Create a command object to hold parameters and last command executed
            //
            this._miCommand = _miConnection.CreateCommand();

            buttonFind.Enabled = false;
            checkBoxUseCloseMatches.Checked = true;
            listBoxSearchResult.Visible     = false;
            textBoxMaxCloseMatches.Text     = "5";
        }
Ejemplo n.º 3
0
        private void listBoxSearchResult_DoubleClick(object sender, System.EventArgs e)
        {
            // get the selected object
            string selectedCloseMatch = (string)this.listBoxSearchResult.SelectedItem;
            // get the selected object index in the list as well since multiple matches
            // may have the same name - we can't just compare close match names.
            int selectedIndex = this.listBoxSearchResult.SelectedIndex;
            int currentIndex  = 0;

            // create a close match object
            FindCloseMatch closeMatch = null;

            // create an enumerator from the results
            FindCloseMatchEnumerator enumerator = _result.GetCloseMatchEnumerator();

            while (enumerator.MoveNext())
            {
                // if the selected name equals the enumerated name...
                if (currentIndex == selectedIndex && selectedCloseMatch.Equals(enumerator.Current.Name))
                {
                    // set the close match object
                    closeMatch = enumerator.Current;

                    // break out of the loop
                    break;
                }
                // else keep looking
                currentIndex++;
            }
            if (closeMatch != null)
            {
                // create the command string
                string command = "select obj from " + _searchTable.Alias + " where MI_Key = \'" + closeMatch.Key + "\'";

                // create the command object
                MICommand cmd = _miConnection.CreateCommand();
                cmd.CommandText = command;

                // create the reader by executing the command
                MIDataReader rdr = cmd.ExecuteReader();

                // read a row
                rdr.Read();

                // get the point
                MapInfo.Geometry.DPoint point = rdr.GetFeatureGeometry(0).Centroid;

                // Close the reader and dispose of the command.
                rdr.Close();
                cmd.Cancel();
                cmd.Dispose();

                // show point on a map
                showPointOnSearchTableMap(point.x, point.y);
            }
        }
Ejemplo n.º 4
0
 private void CleanUp()
 {
     if (_miCommand != null)
     {
         _miCommand.Dispose();
         _miCommand = null;
     }
     if (_miConnection != null)
     {
         _miConnection.Close();
         _miConnection = null;
     }
     Session.Current.Catalog.CloseAll();
     Session.Dispose();
 }
Ejemplo n.º 5
0
        private void showPointOnSearchTableMap(double x, double y)
        {
            MapInfo.Mapping.Map          map         = Session.Current.MapFactory.CreateEmptyMap(System.IntPtr.Zero, new Size(10, 10));
            MapInfo.Mapping.FeatureLayer searchLayer = new MapInfo.Mapping.FeatureLayer(_searchTable);
            map.Layers.Add(searchLayer);

            MapForm1 mapForm    = new MapForm1(map);
            Form     parentForm = this;

            // create a temp table and add a featurelayer for it (use map alias as table alias)
            // make the table hidden (maybe)
            MapInfo.Geometry.CoordSys coordSys = map.GetDisplayCoordSys();
            TableInfoMemTable         ti       = new TableInfoMemTable("temp");

            ti.Temporary = true;

            // add object column
            Column col;

            col          = new GeometryColumn(coordSys); // specify coordsys for object column
            col.Alias    = "obj";
            col.DataType = MIDbType.FeatureGeometry;
            ti.Columns.Add(col);

            // add style column
            col          = new Column();
            col.Alias    = "MI_Style";
            col.DataType = MIDbType.Style;
            ti.Columns.Add(col);

            Table pointTable = Session.Current.Catalog.CreateTable(ti);

            // I am using a Point example here. You can create a rectangle instead
            MapInfo.Geometry.FeatureGeometry      g  = new MapInfo.Geometry.Point(coordSys, x, y);
            MapInfo.Styles.SimpleVectorPointStyle vs = new MapInfo.Styles.SimpleVectorPointStyle(37, System.Drawing.Color.Red, 14);
            MapInfo.Styles.CompositeStyle         cs = new MapInfo.Styles.CompositeStyle(vs);

            MICommand cmd = _miConnection.CreateCommand();

            cmd.Parameters.Add("geometry", MIDbType.FeatureGeometry);
            cmd.Parameters.Add("style", MIDbType.Style);
            cmd.CommandText = "Insert Into temp (obj,MI_Style) values (geometry,style)";
            cmd.Prepare();
            cmd.Parameters[0].Value = g;
            cmd.Parameters[1].Value = cs;
            int nchanged = cmd.ExecuteNonQuery();

            cmd.Dispose();

            map.Layers.Add(new MapInfo.Mapping.FeatureLayer(pointTable));
            // another way: Map.Load(new MapTableLoader(table));

            // make the map encompass the entire search layer
            map.SetView(searchLayer);

            // size the map form
            mapForm.Size = new Size(500, 500);

            //Show the form like a dialog (modal)
            mapForm.ShowDialog(parentForm);

            pointTable.Close();
        }
Ejemplo n.º 6
0
        public FormFindSample()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //

            //
            // Create a connection object and open it.
            //
            this._miConnection = new MIConnection();
            _miConnection.Open();

            //
            // Create a command object to hold parameters and last command executed
            //
            this._miCommand = _miConnection.CreateCommand();

            buttonFind.Enabled = false;
            checkBoxUseCloseMatches.Checked = true;
            listBoxSearchResult.Visible = false;
            textBoxMaxCloseMatches.Text = "5";
        }
Ejemplo n.º 7
0
 private void CleanUp()
 {
     if ( _miCommand != null )
     {
         _miCommand.Dispose();
         _miCommand = null;
     }
     if ( _miConnection != null )
     {
         _miConnection.Close();
         _miConnection = null;
     }
     Session.Current.Catalog.CloseAll();
     Session.Dispose();
 }
Ejemplo n.º 8
0
        private string DetermineRemoteGeomType(FeatureLayer layer)
        {
            MapInfo.Data.Table   t     = layer.Table;
            MapInfo.Styles.Style style = null;

            MIConnection con = null;
            MICommand    cmd = null;
            MIDataReader dr  = null;

            try {
                con = new MIConnection();
                con.Open();
                cmd             = con.CreateCommand();
                cmd.CommandText = "select mi_style from \"" + t.Alias + "\"";
                cmd.CommandType = System.Data.CommandType.Text;
                dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    if (!dr.IsDBNull(0))
                    {
                        style = dr.GetStyle(0);
                        break;
                    }
                }
            }
            catch (MIException) {
                // e.g. if there is no mi_style column
            }
            finally {
                if (cmd != null)
                {
                    cmd.Dispose();
                    cmd = null;
                }
                if (dr != null)
                {
                    dr.Close();
                }
                if (con != null)
                {
                    con.Close();
                    con = null;
                }
            }

            if (style != null)
            {
                if (style is SimpleLineStyle)
                {
                    return("lclayerline.bmp");
                }
                else if (style is SimpleInterior || style is AreaStyle)
                {
                    return("lclayerregion.bmp");
                }
                else if (style is BasePointStyle)
                {
                    return("lclayerpoint.bmp");
                }
                else
                {
                    return("lclayer.bmp");
                }
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 9
0
        public MainForm()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            ToolBarSetup();

            //
            // Create a connection object and open it.
            //
            miConnection = new MIConnection();
            miConnection.Open();

            //
            // Create a command object to hold parameters and last command executed
            //
            miCommand = miConnection.CreateCommand();

            // Add a few default parameters
            CoordSysFactory CSysFactory = Session.Current.CoordSysFactory;
            CoordSys Robinson = CSysFactory.CreateFromPrjString("12, 62, 7, 0");
            CoordSys LatLong = CSysFactory.CreateFromPrjString("1, 0");
            CoordSys NAD83 = CSysFactory.CreateFromPrjString("1, 74");
            miCommand.Parameters.Add("RobinsonCSys", Robinson);
            miCommand.Parameters.Add("LatLongCSys", LatLong);
            miCommand.Parameters.Add("NAD83CSys", NAD83);

            // Set table search path to value sampledatasearch registry key
            // if not found, then use the sampledatasearchpath
            // if that is not found, then just use the app's current directory
            Microsoft.Win32.RegistryKey keyApp = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(@"SOFTWARE\MapInfo\MIDataExplorer");

            string s = (string)keyApp.GetValue("TableSearchPath");
            if (s == null || s.Length == 0)
            {
                Microsoft.Win32.RegistryKey keySamp = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(@"SOFTWARE\MapInfo\MapXtreme\6.6");
                s = (string)keySamp.GetValue("SampleDataSearchPath");
                if (s != null && s.Length > 0)
                {
                    if (s.EndsWith("\\")==false)
                    {
                        s += "\\";
                    }
                }
                else
                {
                    s = Environment.CurrentDirectory;
                }
                keySamp.Close();
            }
            keyApp.Close();

            Session.Current.TableSearchPath.Path = s;

            ProcessCommand("help"); // show commands

            // For sample app purposes, open states.tab
            if (Session.Current.TableSearchPath.FileExists("usa.tab"))
            {
                ProcessCommand("open usa.tab");
                // For sample app purposes, load states.sql if we can find it.
                string sFound;
                if (Session.Current.TableSearchPath.FileExists("sample.sql", out sFound))
                {
                    rtCommand.LoadFile(sFound, RichTextBoxStreamType.PlainText);
                }
                else
                {
                    // could not open a command file, but we want to show something
                    ProcessCommand("select * from usa");
                }
            }
        }