显点画线

创建了一行代码,使用 MultiCurve 类中的 CreateLine 方法。以下代码是使用该方法的示例:
using MapInfo.Geometry;
MultiCurve multiCurve 
= new MultiCurve(longLatNad83);
multiCurve 
= MapInfo.Geometry.MultiCurve.CreateLine(longLatNad83, dpoints[0], dpoints[1]);



几何体创建后,需要将几何体添加到地图中,然后才能显示、选择、标注该几何体,或在
该几何体上执行任何与地图有关的其它操作。
以下代码示例说明了如何执行该操作:
using MapInfo.Geometry;
using MapInfo.Mapping;
using MapInfo.Data;
using MapInfo.Styles;
/// <summary>
/// Creates a temporary table, adds a Point feature, and displays
/// it on a map. This example uses wldcty25 as a template, so you'll
/// need to have world.gst open in a map control.
/// NOTE X and Y positions depend on the coordinate system!
/// </// summary>
/// <param name="x">X position</param>
/// <param name="y">Y position</param>

private void showPointOnMap(double x, double y)
{
Map map 
= mapControl1.Map;
//uses wldcty25 as a template
Table table =
MapInfo.Engine.Session.Current.Catalog.GetTable(
"wldcty25");
// create a temp table and add a featurelayer for it
CoordSys coordSys = map.GetDisplayCoordSys();
TableInfoMemTable tableInfo 
= new TableInfoMemTable("temp");
tableInfo.Temporary 
= true;
// add geometry column
Column column;
// specify coordsys for object column
column = new GeometryColumn(coordSys);
column.Alias 
= "MI_Geometry";
column.DataType 
= MIDbType.FeatureGeometry;
tableInfo.Columns.Add(column);
// add style column
column = new Column();
column.Alias 
= "MI_Style";
column.DataType 
= MIDbType.Style;
tableInfo.Columns.Add(column);
Table pointTable 
= Session.Current.Catalog.CreateTable(tableInfo);
// Set the location and display style of the point
FeatureGeometry geometry = new MapInfo.Geometry.Point
(coordSys, x, y);
SimpleVectorPointStyle vStyle 
= new SimpleVectorPointStyle
(
37, System.Drawing.Color.Red, 14);
CompositeStyle cStyle 
= new MapInfo.Styles.CompositeStyle(vStyle);
//Update the table with the location and style of the new feature
MICommand cmd = miConnection.CreateCommand();
cmd.Parameters.Add(
"geometry",MIDbType.FeatureGeometry);
cmd.Parameters.Add(
"style",MIDbType.Style);
cmd.CommandText 
= "Insert Into temp (MI_Geometry,MI_Style) 
values (geometry,style)";
cmd.Prepare();
cmd.Parameters[
0].Value = geometry;
cmd.Parameters[
1].Value = cStyle;
int nchanged = cmd.ExecuteNonQuery();
cmd.Dispose();
//add the table to the map
map.Layers.Add(new MapInfo.Mapping.FeatureLayer(pointTable));
}



以下是新的代码行
//根据名称搜索
SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchWhere("Country like '%" + txtName.Text + "%'");
IResultSetFeatureCollection ifs 
= MapInfo.Engine.Session.Current.Catalog.Search("world",si);

if (ifs.Count <=0
{
 
return;
}


//缩放到选择图元范围
MapMain.Map.SetView(ifs.Envelope);
MapMain.Map.Scale 
= MapMain.Map.Scale * 2;

//高亮显示
MapInfo.Engine.Session.Current.Selections.DefaultSelection.Clear();
MapInfo.Engine.Session.Current.Selections.DefaultSelection.Add(ifs);
//高亮显示也就是取默认值,默认值为高亮显示的

//输出查询信息
ListBox1.Items.Clear();
ListBox1.Items.Add(
"图层: " + ifs.BaseTable.Alias.ToString());
foreach (Feature feature in ifs)
{
 
//显示每个选择图元的属性数据
 foreach (Column column in feature.Columns)
 
{
  ListBox1.Items.Add(
"  " + column.ToString() + " = " + feature[column.ToString()].ToString());
 }

 ListBox1.Items.Add(
"____________________________");
}

posted on 2006-07-06 09:53  口俞克木公  阅读(639)  评论(0编辑  收藏  举报

导航