在MapXtreme 2005中,查找图元提供了非常多的方法,也非常容易实现,这里总结了三种方法。
(1)Search方法是非常强大的,可以实现几乎所有的查找,这也是最常用的查找方式。示例代码如下:
复制内容到剪贴板
代码:
/**//// <summary>
/// 通过Search方法查找图元
/// Design by Glacier
/// 2008年8月6日
/// <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查找图元
/// Design by Glacier
/// 2008年8月6日
/// <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>
/// 通过Sql语句查找图元
/// Design by Glacier
/// 2008年8月6日
/// <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);
}
}
}
(1)Search方法是非常强大的,可以实现几乎所有的查找,这也是最常用的查找方式。示例代码如下:
复制内容到剪贴板
代码:
/**//// <summary>
/// 通过Search方法查找图元
/// Design by Glacier
/// 2008年8月6日
/// <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查找图元
/// Design by Glacier
/// 2008年8月6日
/// <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>
/// 通过Sql语句查找图元
/// Design by Glacier
/// 2008年8月6日
/// <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添加标记和删除标记
2009-03-30 16:23 1791新增2个pointselectiontool, clientc ... -
添加数据库中的经纬度信息
2009-03-30 16:22 1746C# Code: 复制内容到剪贴板 代码: MapInfo ... -
MapXtreme 2005自定义图层控制代码(WEB)
2009-03-30 16:21 1554虽然MapXtreme 2005 6.7.1提供了图层控制的控 ... -
MapxTreme测试:绘制图标和文字标注
2009-03-30 16:19 3657代码: using System; using System ... -
mapxtreme 2004 改变feature颜色
2009-03-30 16:18 15551.C# code: 复制内容到剪贴板 代码: MapI ... -
MapxTreme2005地图打印
2009-03-30 16:18 1189MapxTreme2005地图打印 一、语言: c# net2 ... -
在C#应用中如何读取存在ORACLE(或SQL Server)中的MapInfo表
2009-03-30 16:17 1218using MapInfo.Data; ... -
MapXtreme 2005查找图元方法,web的
2009-03-30 16:16 1761先添加一个TextBox和 DropDownList控件 复 ... -
MapXtreme点取地图获得信息
2009-03-30 16:15 1867拖一个pointselectiontool到页面, 修改属性 ... -
MapXtreme查看整个地图的代码
2009-03-30 16:14 907Map map = mapControl1.Map; IMap ... -
MapXtreme 2005 鹰眼源代码
2009-03-30 16:13 1762研究了一段时间的MapXtreme2005 v6.6, 实现了 ... -
实现手动画线
2009-03-30 16:12 1208为了实现在地图上手动画线的功能,煞费了一翻苦心,不过最后实现的 ... -
Web页面中实现鼠标中键缩放
2009-03-30 16:11 1506在MapXtreme 2005中,在Windows应用程序中自 ... -
两种方法实现动态轨迹
2009-03-30 16:11 1352在GIS中,动态轨迹的实现是非常有用的,可用GPS定位,热点跟 ... -
添加标注图层
2009-03-30 16:08 1157在MapXtreme 2005中添加标注图层是非常容易的,只要 ... -
向图层中添加线段
2009-03-30 16:07 916向图层中添加线段和向图层中添加点是一样的,其本质都是向图层中添 ... -
向图层中添加点
2009-03-30 16:06 1002在添加点之前先要在地图上创建一个临时图层,创建临时图层请参考《 ... -
mapxtreme2005 改变选中的图元样式
2009-03-30 16:05 1060MapInfo.Styles.CompositeStyle c ... -
Mapxtreme2005 两点之间画直线
2009-03-30 16:04 1120private void DrawLine(MapInfo.D ... -
mapxtreme2005 创建各种样式
2009-03-30 16:04 1108public MapInfo.Styles.Composite ...
相关推荐
土元俗称土鳖虫.doc
土鳖虫的功效与作用土鳖虫的临床应用.doc
土鳖虫采集和加工.doc
《土鳖虫LHAZQ》PPT课件.ppt
土鳖虫的功效作用及禁忌.pdf
土鳖虫提取液对人胃低分化腺癌细胞BGC.docx
养殖中华药鳖虫土元乐享财富人生.doc
2021年土元行业需求分析及前景投资报告.pptx
土元行业(2021-2026)企业市场突围战略分析与建议.docx
2021年度土元行业人力资源效能分析报告(市场招聘用工).pdf
食品饮料类营养保健行业土元领域分析报告(研究报告).pdf
土元公司(行业)薪酬管理制度方案-薪酬设计方案资料文集系列.docx
2020年食品饮料营养保健行业土元领域行业分析报告(市场调查报告).pdf
土元是我国传统医学中常用的原料,圆柱型土元是苏土元在养殖过程中发现的变异品种。本研究分析了圆柱型土元的一般营养成分,并用圆柱型土元对高脂血症模型小鼠进行降血脂活性评价。Balb/c雄性小鼠分别喂食标准饲料、...