本本

态度决定成败

导航

MapXtreme 创建永久表和临时表的方法

 

 

 

                    MapInfo.Data.TableInfoNative tableInfoNative = new MapInfo.Data.TableInfoNative("公交站点");

                    tableInfoNative.TablePath = "D:\\" + "公交站点" + ".TAB";

                    /*******1、3个特定且必须的列*******/
                    tableInfoNative.Columns.Add(MapInfo.Data.ColumnFactory.CreateIntColumn("ID"));
                    tableInfoNative.Columns.Add(MapInfo.Data.ColumnFactory.CreateStyleColumn());// 增加新的 Column 实例,该实例属于带有别名 "MI_Style" 的 Style 类型。(增加样式列)
                    tableInfoNative.Columns.Add(MapInfo.Data.ColumnFactory.CreateFeatureGeometryColumn("MI_Geometry", ucMapBus.Map.GetDisplayCoordSys()));// 增加 GeometryColumn 实例(特定几何体坐标系类)

                    tableInfoNative.Columns.Add(MapInfo.Data.ColumnFactory.CreateStringColumn("MI_Memo", 200));// 增加备注(一定要作为第三个字段,默认作为ToolTip 如何设置其他字段作为ToolTip 待研究 Xelen2011-5-17)

                    /*******2、公交元素相关列 *******/
                    tableInfoNative.Columns.Add(MapInfo.Data.ColumnFactory.CreateStringColumn("MI_Name", 30)); //增加名称列
                    tableInfoNative.Columns.Add(MapInfo.Data.ColumnFactory.CreateDoubleColumn("MI_Angle")); // 增加几何体类型(对应枚举 GeometryTypes)        
                    tableInfoNative.Columns.Add(MapInfo.Data.ColumnFactory.CreateStringColumn("MI_Road", 100)); // 增加道路名称列
                    tableInfoNative.Columns.Add(MapInfo.Data.ColumnFactory.CreateIntColumn("MI_LineId"));// 增加线路ID列
                    tableInfoNative.Columns.Add(MapInfo.Data.ColumnFactory.CreateStringColumn("MI_LineName", 100)); //增加线路名称列
                    tableInfoNative.Columns.Add(MapInfo.Data.ColumnFactory.CreateStringColumn("MI_Notes", 200)); //增加线路名称列
                  
                
                  

                    MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.CreateTable(tableInfoNative);
                    MapInfo.Mapping.FeatureLayer layer = new MapInfo.Mapping.FeatureLayer(table);
                    layer.Name = 公交站点";
                    ucMapBus.Map.Layers.Insert(0, layer);   //3、将表添加到地图


                    DataTable lineTable = Xelen.DAL.BaseData.GetLineIdNameInfos();

                    foreach (DataRow dr in lineTable.Rows)
                    {
                        int lineId = int.Parse(dr["LINE_ID"].ToString());
                        DataTable dtUpStations = Xelen.DAL.BaseData.GetStationPointInfos(lineId, Xelen.DAL.BaseData.GetLineStatus(lineId), true);

                        try
                        {

                            #region 增加站点链接线
                            //for (int pos = 0; pos <= mapStations.Length - 2; pos++)
                            //{
                            //    Feature f = new Feature(table.TableInfo.Columns);
                            //    // 1、线要素
                            //    f.Geometry = MultiCurve.CreateLine(map.GetDisplayCoordSys(), new DPoint(mapStations[pos].Longitude, mapStations[pos].Latitude), new DPoint(mapStations[pos + 1].Longitude, mapStations[pos + 1].Latitude));
                            //    //2.显示样式
                            //    MapInfo.Styles.SimpleLineStyle lStyle = new SimpleLineStyle(new LineWidth(6, LineWidthUnit.Point));
                            //    lStyle.Color = Color.GreenYellow;
                            //    lStyle.Interleaved = true;
                            //    f.Style = lStyle;
                            //    //3、添加其他信息
                            //    f["MI_KeyId"] = mapStations[pos].StationId;
                            //    f["MI_Name"] = mapStations[pos].Name;
                            //    f["MI_Road"] = mapStations[pos].Road;
                            //    f["MI_DName"] = mapStations[pos].DName;
                            //    f["MI_lineName"] = mapStations[pos].LineName;
                            //    f["MI_lineId"] = mapStations[pos].LineId;
                            //    f["MI_Memo"] = mapStations[pos].ToolTip;


                            //    table.InsertFeature(f);
                            //}
                            #endregion

                            #region 增加站点
                            foreach (DataRow drStation in dtUpStations.Rows)
                            {
                                MapInfo.Data.Feature f = new MapInfo.Data.Feature(table.TableInfo.Columns);
                                // 1、点要素
                                f.Geometry = new MapInfo.Geometry.Point(ucMapBus.Map.GetDisplayCoordSys(), new MapInfo.Geometry.DPoint(double.Parse(drStation["longitude"].ToString()), double.Parse(drStation["latitude"].ToString())));

                                //2.显示矢量样式
                                MapInfo.Styles.SimpleVectorPointStyle vStyle = new MapInfo.Styles.SimpleVectorPointStyle(53, System.Drawing.Color.Blue, 10);
                                f.Style = new MapInfo.Styles.CompositeStyle(vStyle);
        
                                //3、添加其他信息
                                f["ID"] = drStation["STATION_POINT_ID"].ToString();
                                f["MI_Memo"] = drStation["STATION_NAME"].ToString();
                                f["MI_Name"] = drStation["STATION_NAME"].ToString();
                                f["MI_Road"] = drStation["Road_Name"].ToString();
                                f["MI_Angle"] = double.Parse(drStation["Angle"].ToString());
                                f["MI_LineName"] = dr["Name"].ToString();
                                f["MI_LineId"] = lineId; //dr["Angle"].ToString();
                                f["MI_Notes"] = drStation["NOTES"].ToString();//mapStation.ToolTip;

                                table.InsertFeature(f);
                                ucMapBus.Map.Layers[0].Invalidate();
                            }
                            #endregion

                         
                        }
                        catch(Exception ex)
                        {
                            //MessageBox.Show(ex.Message);
                        }
                    }
                    //table.Refresh();
             
                    tableInfoNative.WriteTabFile();//保存为Tab文件

 

 

posted on 2012-10-20 16:19  本本  阅读(435)  评论(1)    收藏  举报