Ejemplo n.º 1
0
        private void PrepareData()
        {
            MapInfo.Data.Table mdbTable   = MapInfo.Engine.Session.Current.Catalog[SampleConstants.EWorldAlias];
            MapInfo.Data.Table worldTable = MapInfo.Engine.Session.Current.Catalog[SampleConstants.ThemeTableAlias];
            // worldTable is loaded by preloaded mapinfo workspace file specified in web.config.
            // and MS Access table in this sample is loaded manually.
            // we are not going to re-load it again once it got loaded because its content is not going to change in this sample.
            // we will get performance gain if we use Pooled MapInfo Session.
            // Note: It's better to put this MS Access table into pre-loaded workspace file,
            //       so we don't need to do below code.
            //       We manually load this MS Access in this sample for demonstration purpose.
            if (mdbTable == null)
            {
                System.Web.HttpServerUtility util = HttpContext.Current.Server;
                string dataPath = util.MapPath("");
                mdbTable = MapInfo.Engine.Session.Current.Catalog.OpenTable(System.IO.Path.Combine(dataPath, SampleConstants.EWorldTabFileName));

                string[] colAlias = SampleConstants.BoundDataColumns;
                // DateBinding columns
                Column col0 = MapInfo.Data.ColumnFactory.CreateDoubleColumn(colAlias[0]);
                col0.ColumnExpression = mdbTable.Alias + "." + colAlias[0];
                Column col1 = MapInfo.Data.ColumnFactory.CreateIntColumn(colAlias[1]);
                col1.ColumnExpression = mdbTable.Alias + "." + colAlias[1];
                Column col2 = MapInfo.Data.ColumnFactory.CreateIntColumn(colAlias[2]);
                col2.ColumnExpression = mdbTable.Alias + "." + colAlias[2];

                Columns cols = new Columns();
                cols.Add(col0);
                cols.Add(col1);
                cols.Add(col2);

                // Databind MS Access table data to existing worldTable.
                worldTable.AddColumns(cols, BindType.DynamicCopy, mdbTable, SampleConstants.SouceMatchColumn, Operator.Equal, SampleConstants.TableMatchColumn);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// <param name="strTable">表名</param>
        /// <param name="strLayer">图层名</param>
        /// </summary>
        public static bool CreateTempLayer(Map oMap, string strTable, string strLayer)
        {
            //确保当前目录下不存在同名表
            MapInfo.Data.Table tblTemp = MapInfo.Engine.Session.Current.Catalog.GetTable(strTable);
            if (tblTemp != null)
            {
                MapInfo.Engine.Session.Current.Catalog.CloseTable(strTable);
            }

            //指定表名建立表信息
            MapInfo.Data.TableInfoMemTable tblInfoTemp = new MapInfo.Data.TableInfoMemTable(strTable);
            //向表信息中添加可绘图列
            tblInfoTemp.Columns.Add(MapInfo.Data.ColumnFactory.CreateFeatureGeometryColumn(oMap.GetDisplayCoordSys()));
            tblInfoTemp.Columns.Add(MapInfo.Data.ColumnFactory.CreateStyleColumn());
            //向表信息中添加自定义列
            //tblInfoTemp.Columns.Add(MapInfo.Data.ColumnFactory.CreateIntColumn("index"));
            tblInfoTemp.Columns.Add(MapInfo.Data.ColumnFactory.CreateStringColumn("uid", 128));
            tblInfoTemp.Columns.Add(MapInfo.Data.ColumnFactory.CreateStringColumn("name", 255));

            //根据表信息创建临时表
            tblTemp = MapInfo.Engine.Session.Current.Catalog.CreateTable(tblInfoTemp);

            FeatureLayer tempLayer = new FeatureLayer(tblTemp, strLayer, strLayer);

            oMap.Layers.Add(tempLayer);
            return(true);
        }
Ejemplo n.º 3
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.º 4
0
        /// <summary>
        /// Handle a click of the Open Table button
        /// </summary>
        private void OpenTable_Click(object sender, System.EventArgs e)
        {
            string         filename = null;
            string         s;
            OpenFileDialog openFile = new OpenFileDialog();

            openFile.DefaultExt = "tab";
            // The Filter property requires a search string after the pipe ( | )
            openFile.Filter      = "MapInfo Tables (*.tab)|*.tab";
            openFile.Multiselect = false;
            openFile.ShowDialog();
            if (openFile.FileName.Length > 0)
            {
                MapInfo.Data.Table miTable = null;
                filename = openFile.FileName;
                if (Session.Current.TableSearchPath.FileExists(System.IO.Directory.GetCurrentDirectory(), filename, out s))
                {
                    miTable = Session.Current.Catalog.OpenTable(s);
                }
                else
                {
                    // try anyway, at least we will get an exception to report
                    miTable = Session.Current.Catalog.OpenTable(filename, "OpenTableTable");
                }

                _tableAlias = miTable.Alias;
                ResetTableEnum();
                SetGrid(_tableEnum.Current, this.showTableStructure.Checked);
                UpdateNavigationButtons();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Set the data from the specified table into the data grid.
        /// Show the table's scheme if showSchema is true.
        /// </summary>
        /// <param name="miTable"></param>
        /// <param name="showSchema"></param>
        private void SetGrid(MapInfo.Data.Table miTable, bool showSchema)
        {
            dataGrid.CaptionText       = miTable.Alias;
            this.miCommand.CommandText = "Select * from " + miTable.Alias;
            MapInfo.Data.MIDataReader miReader = this.miCommand.ExecuteReader();
            DataTable dt = new DataTable("Data");

            for (int i = 0; i < miReader.FieldCount; i++)
            {
                DataColumn dc = dt.Columns.Add(miReader.GetName(i));
            }
            while (miReader.Read())
            {
                DataRow dr = dt.NewRow();
                for (int i = 0; i < miReader.FieldCount; i++)
                {
                    dr[i] = miReader.GetValue(i);
                }
                dt.Rows.Add(dr);
            }
            if (showSchema)
            {
                dataGrid.DataSource = miReader.GetSchemaTable();
            }
            else
            {
                dataGrid.DataSource = dt;
            }
            miReader.Close();
        }
Ejemplo n.º 6
0
 private void DoShowRasterStyle(MapInfo.Data.Table table)
 {
     // Get Raster info from the table.
     MapInfo.Styles.RasterStyle rasterStyle = GetRasterStyle(table);
     MessageBox.Show(this, String.Format("Brightness = {0}\n Contrast = {1}\n",
                                         rasterStyle.Brightness,
                                         rasterStyle.Contrast));
 }
Ejemplo n.º 7
0
 private void DoShowRasterInfo(MapInfo.Data.Table table)
 {
     // Get Raster info from the table.
     MapInfo.Raster.RasterInfo rasterInfo = GetRasterInfo(table);
     MessageBox.Show(this, String.Format("imageHeight = {0}\n imageWidth = {1}\n",
                                         rasterInfo.Height,
                                         rasterInfo.Width));
 }
Ejemplo n.º 8
0
        private bool InitWorkingLayer()
        {
            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(false);
            }

            // Make sure the Find layer's MemTable exists
            MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.GetTable(_workingLayerName);
            if (table == null)
            {
                TableInfoMemTable ti = new TableInfoMemTable(_workingLayerName);
                ti.Temporary = true;
                // Add the Geometry column
                Column col = new MapInfo.Data.GeometryColumn(map.GetDisplayCoordSys());
                col.Alias    = "obj";
                col.DataType = MIDbType.FeatureGeometry;
                ti.Columns.Add(col);
                // Add the Style column
                col          = new MapInfo.Data.Column();
                col.Alias    = "MI_Style";
                col.DataType = MIDbType.Style;
                ti.Columns.Add(col);
                table = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti);
            }
            if (table == null)
            {
                return(false);
            }

            // Make sure the Find layer exists
            MapInfo.Mapping.FeatureLayer layer = (MapInfo.Mapping.FeatureLayer)map.Layers[_workingLayerName];
            if (layer == null)
            {
                layer = new MapInfo.Mapping.FeatureLayer(table, _workingLayerName, _workingLayerName);
                map.Layers.Insert(0, layer);
            }
            if (layer == null)
            {
                return(false);
            }

            // Delete the find object.  There should only be one object in this table.
            (layer.Table as ITableFeatureCollection).Clear();

            return(true);
        }
Ejemplo n.º 9
0
        // Create a LabelLayer and add it into the Group Layer collection with index 0.
        private LabelLayer CreateLabelLayer(Map myMap, MapInfo.Data.Table table, string caption)
        {
            LabelLayer ll = new LabelLayer("Label Layer for bound data", SampleConstants.NewLabelLayerAlias);
            // Insert this LabelLayer into the GroupLayer
            GroupLayer gLyr = GetTheGroupLayer();

            gLyr.Insert(0, ll);

            LabelSource ls = new LabelSource(table);

            ls.DefaultLabelProperties.Caption = caption;
            ll.Sources.Append(ls);
            return(ll);
        }
Ejemplo n.º 10
0
        private MapInfo.Data.Table OpenNativeTable(MapInfo.Data.NamedConnectionInfo nci, string tableName)
        {
            string fileName = tableName;
            string alias    = tableName + "_" + nci.Name;

            MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.GetTable(alias);
            if (table == null)
            {
                if (tableName.ToLower().IndexOf(".tab") <= 0)
                {
                    fileName = tableName + ".tab";
                }
                table = MapInfo.Engine.Session.Current.Catalog.OpenTable(nci.Name, alias, fileName);
            }
            return(table);
        }
Ejemplo n.º 11
0
        // Open a new table or use existing one.
        protected void OpenTableButton_Click(object sender, System.EventArgs e)
        {
            if (CheckBoxList1.SelectedValue == null || CheckBoxList1.SelectedValue.Length <= 0)
            {
                return;
            }
            WarningLabel.Visible = false;
            if (OpenTableTextBox.Text != null && OpenTableTextBox.Text.Trim().Length != 0)
            {
                string             tableName = OpenTableTextBox.Text.Trim();
                MapInfo.Data.Table table     = null;
                try
                {
                    table = this.OpenTable(CheckBoxList1.SelectedValue, tableName);
                    if (table != null)
                    {
                        string lyrAlias           = "alias_flyr_" + table.Alias;
                        MapInfo.Mapping.Map myMap = GetMapObj();
                        if (myMap == null)
                        {
                            return;
                        }
                        if (myMap.Layers[lyrAlias] != null)
                        {
                            myMap.Layers.Remove(lyrAlias);
                        }
                        FeatureLayer fLyr = new FeatureLayer(table, "LayerName_" + tableName, lyrAlias);
                        myMap.Layers.Insert(0, fLyr);

                        // Need to rebind again since a new table got opened.
                        BindOpenedTablesAliasToRepeater();
                    }
                    else
                    {
                        WarningLabel.Visible = true;
                    }
                }
                catch (Exception)
                {
                    WarningLabel.Visible = true;
                    if (table != null)
                    {
                        table.Close();
                    }
                }
            }
        }
Ejemplo n.º 12
0
        private MapInfo.Data.Table OpenDataBaseTable(MapInfo.Data.NamedConnectionInfo nci, string dbTableName)
        {
            String tableAlias = dbTableName + "_" + nci.Name.Replace(" ", "_").Replace(".", "_");

            MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.GetTable(tableAlias);
            // we need to create a new table if there is no table in the catalog.
            if (table == null)
            {
                TableInfoServer tis = new TableInfoServer("tableInfoServer_" + dbTableName);
                tis.ConnectString = nci.ConnectionString;
                tis.Query         = "select * from " + dbTableName;
                tis.Toolkit       = this.GetServerToolkit(nci);
                tis.CacheSettings = new CacheParameters(CacheOption.On);
                tis.Alias         = tableAlias;
                table             = MapInfo.Engine.Session.Current.Catalog.OpenTable(nci.Name, tis);
            }
            return(table);
        }
Ejemplo n.º 13
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);
            }
        }