MapXtreme for .net 学习总结(二)
2009-05-09 10:34
197 查看
在MapXtreme 2005中,查找图元提供了非常多的方法,也非常容易实现,这里总结了三种方法。
(1)Search方法是非常强大的,可以实现几乎所有的查找,这也是最常用的查找方式。示例代码如下:
(2)通过构造Find对象,进行查找。示例代码如下:
(3)能过构造Sql语句进行查找,示例代码如下:
(1)Search方法是非常强大的,可以实现几乎所有的查找,这也是最常用的查找方式。示例代码如下:
/// <summary> /// 通过Search方法查找图元 /// <param name="tableName">查找的表名</param> /// <param name="columnName">查找的列名</param> /// <param name="strKey">查找的关键字</param> /// </summary> public static void SearchWithSearch(string tableName, string columnName, string strKey) { MapInfo.Mapping.Map map = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias]; SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchWhere(columnName + " like '%" + strKey + "%'"); IResultSetFeatureCollection ifs = MapInfo.Engine.Session.Current.Catalog.Search(tableName, si); MapInfo.Engine.Session.Current.Selections.DefaultSelection.Clear(); if (ifs.Count <= 0) { lbSearch.Text = "Cannot find the point"; } else { //高亮显示 MapInfo.Engine.Session.Current.Selections.DefaultSelection.Add(ifs); lbSearch.Text = ""; if (ifs.Count == 1) { map.Center = new DPoint(ifs[0].Geometry.Centroid.x, ifs[0].Geometry.Centroid.y); MapInfo.Geometry.Distance d = new MapInfo.Geometry.Distance(0.5, map.Zoom.Unit); } else { map.SetView(ifs.Envelope); } //设置高亮显示的样式 //((SimpleInterior)MapInfo.Engine.Session.Current.Selections.DefaultSelection.Style.AreaStyle.Interior).BackColor = System.Drawing.Color.Red; //((SimpleInterior)MapInfo.Engine.Session.Current.Selections.DefaultSelection.Style.AreaStyle.Interior).ForeColor = System.Drawing.Color.Green; //输出查询信息 ListBox1.Items.Clear(); foreach (Feature feature in ifs) { ListBox1.Items.Add(feature["name"].ToString()); } } }
(2)通过构造Find对象,进行查找。示例代码如下:
/**//// <summary> /// 通过Find查找图元 /// <param name="layerName">查找的图层名</param> /// <param name="columnName">查找的列名</param> /// <param name="strKey">查找的关键字</param> /// </summary> public static void SearchWithFind(string layerName, string columnName, string strKey) { Find find = null; MapInfo.Mapping.Map map = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias]; // Do the find MapInfo.Mapping.FeatureLayer findLayer = (MapInfo.Mapping.FeatureLayer)map.Layers[PointLayerName]; find = new Find(findLayer.Table, findLayer.Table.TableInfo.Columns[columnName]); FindResult findResult = find.Search(strFind); if (findResult.ExactMatch) { // Set the map's center and zoom map.Center = new DPoint(findResult.FoundPoint.X, findResult.FoundPoint.Y); MapInfo.Geometry.Distance d = new MapInfo.Geometry.Distance(2, map.Zoom.Unit); map.Zoom = d; lbSearch.Text = ""; } else { lbSearch.Text = "Cannot find the Point"; } find.Dispose(); }
(3)能过构造Sql语句进行查找,示例代码如下:
/**//// <summary> /// <param name="tableName">查找的表名</param> /// <param name="columnName">查找的列名</param> /// <param name="strKey">查找的关键字</param> /// </summary> public static void SearchWithSql(string tableName, string columnName, string strKey) { MapInfo.Data.MIConnection miConnection = new MIConnection(); miConnection.Open(); MapInfo.Data.MICommand miCommand = miConnection.CreateCommand(); miCommand.CommandText = "select * from " + tableName + " where " + columnName + " like '%'+@name+'%'"; miCommand.Parameters.Add("@name", strKey); IResultSetFeatureCollection ifs = miCommand.ExecuteFeatureCollection(); MapInfo.Engine.Session.Current.Selections.DefaultSelection.Clear(); MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias]; if (ifs.Count <= 0) { lbSearch.Text = "Cannot find the point"; } else { //高亮显示 lbSearch.Text = ""; MapInfo.Engine.Session.Current.Selections.DefaultSelection.Add(ifs); if (ifs.Count == 1) { myMap.Center = new DPoint(ifs[0].Geometry.Centroid.x, ifs[0].Geometry.Centroid.y); MapInfo.Geometry.Distance d = new MapInfo.Geometry.Distance(0.5, myMap.Zoom.Unit); myMap.Zoom = d; } else { myMap.SetView(ifs.Envelope); } } }
相关文章推荐
- MapXtreme for .net 学习总结(一)
- MapXtreme 2005 For .Net 学习笔记
- MyBatis For .NET学习-问题总结
- 黑马程序员之ADO.NET学习笔记:ADO.NET学习总结
- 每日学习总结:CSS:Clear属性的用法、重复交易提示框、弹出提示框后页面变形、asp.net调用smtp服务发送邮件问题
- MyBatis For .NET学习笔记[2]:配置环境
- 学习asp.net小模块总结
- 深度学习,A fast learning algorithm for deep belief nets
- 学习ASP.NET的总结(二)
- ASP.NET中 存储过程-Procedure 使用 学习总结
- MyBatis For .NET学习- 初识MyBatis
- arcgis server for .NET学习转载3
- arcgis server for .NET学习转载6
- AS3 remoting For .NET学习(一)
- English for Accounting----学习总结
- 黑马程序员---关于对ADO.Net学习的总结
- asp.net天轰穿视频学习总结
- github 和 github for windows 学习使用总结
- ASP.NET 2.0 URL Rewrite 学习总结
- 关于学习asp.net的一些总结