Posted on 2006-06-01 11:46
东人EP 阅读(838)
评论(3) 编辑 收藏 引用 所属分类:
MapInfo
向地图中加入点程序代码
// 由桌面坐标转换为地理坐标
System.Drawing.PointF DisplayPoint = new PointF(e.X,e.Y);
MapInfo.Geometry.DPoint MapPoint = new MapInfo.Geometry.DPoint();
MapInfo.Geometry.DisplayTransform converter = this.mapControl1.Map.DisplayTransform;
converter.FromDisplay(DisplayPoint, out MapPoint);
this.statusBar1.Text = "Cursor Location: " + MapPoint.x.ToString() + ", " + MapPoint.y.ToString();
MapInfo.Geometry.Point pnt = new MapInfo.Geometry.Point(this.mapControl1.Map.GetDisplayCoordSys(), MapPoint);
Table table = Session.Current.Catalog.OpenTable(@"C:\Map\CHCTY_2K.tab");
MapInfo.Styles.SimpleVectorPointStyle vs = new MapInfo.Styles.SimpleVectorPointStyle();
MapInfo.Styles.CompositeStyle cs = new MapInfo.Styles.CompositeStyle(null, null, null, vs);
Feature f = new Feature(pnt, cs);
//MapInfo.Data.Key k = table.InsertFeature(f);
// 打开需要编辑的表
Table table = Session.Current.Catalog.OpenTable(@"C:\Map\CHCTY_2K.tab");
// 定义列集合
Columns cols = new Columns();
cols.Add(ColumnFactory.CreateFeatureGeometryColumn(mapControl1.Map.GetDisplayCoordSys()));
cols.Add(ColumnFactory.CreateStringColumn("Place_Name", 40));
cols.Add(ColumnFactory.CreateStringColumn("Country", 40));
cols.Add(ColumnFactory.CreateStringColumn("Latitude", 20));
cols.Add(ColumnFactory.CreateStringColumn("Longitude", 20));
cols.Add(ColumnFactory.CreateStyleColumn());
// 定义图形特征
MapInfo.Geometry.FeatureGeometry fg = new MapInfo.Geometry.Point(mapControl1.Map.GetDisplayCoordSys(), new DPoint(pnt.X, pnt.Y)) as FeatureGeometry;
// 定义图形特征类型
MapInfo.Styles.SimpleVectorPointStyle vs = new MapInfo.Styles.SimpleVectorPointStyle(35, Color.Chocolate, 15);
MapInfo.Styles.CompositeStyle cs = new MapInfo.Styles.CompositeStyle(null, null, null, vs);
string strLatitude;
string strLongitude;
this.TransformCoordSysToDMS(pnt.X, pnt.Y, out strLongitude, out strLatitude);
// 写入其他信息窗体
InformationForm infoForm = new InformationForm(strLongitude, strLatitude);
infoForm.ShowDialog();
// 为插入的记录付值
object[] sValue = new object[6]{fg, infoForm.Place_Name, infoForm.Country, infoForm.Latitude, infoForm.Longitude, cs};
Feature fe = new Feature(cols, sValue);
table.InsertFeature(fe);