Mapinfo的一些用法

1、打开:

 MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.OpenTable(open.FileName);
this.mapControl1.Map.Load(new MapTableLoader(table));

2、
 选择点
 mapControl1.Map.GetDisplayCoordSys();

MapInfo.Geometry.DPoint dp = new MapInfo.Geometry.DPoint();
MapInfo.Geometry.DPoint dpout = new MapInfo.Geometry.DPoint();
dp.x = p.X;
dp.y = p.Y;
使用显示坐标转化到地图上的坐标
mapControl1.Map.DisplayTransform.FromDisplay(p, out dpout);

MapInfo.Data.MIConnection connection = new MapInfo.Data.MIConnection();
connection.Open();

This is the point of origin...
MapInfo.Geometry.DPoint dpt1 = new MapInfo.Geometry.DPoint(dpout.x, dpout.y);

'tablename' is the string alias of the table to perform the search on...'DoesTableExist' is a
function that can be written to check to be sure the table was open. A 'try...catch' could also be
used here.
string tablename = comboBoxView.Text; ;

get the table from the current catalog and assign to tab1
MapInfo.Data.Table tab1 = connection.Catalog.GetTable(tablename);
create a feature layer from tab1
MapInfo.Mapping.FeatureLayer f1 = new MapInfo.Mapping.FeatureLayer(tab1);
create a Distance object from the search radius and unit type -
 MapInfo.Geometry.Distance dist4 = new MapInfo.Geometry.Distance(200, MapInfo.Geometry.DistanceUnit.Meter);
Use the SearchInfoFactory class to return a search info based on search type. In this case -
SearchWithinDistance
Distance dist = new Distance();
dist.Value = 50;
dist.Unit = MapInfo.Geometry.DistanceUnit.Meter;
MapInfo.Data.SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchWithinDistance(dpt1, f1.CoordSys, dist, MapInfo.Data.ContainsType.Centroid);
The QueryDefinition (what to return), in this case - all columns '*'
si.QueryDefinition.Columns = new string[] { "*" };
Perform the search on the table, return an IResultSetFeatureCollection object...
MapInfo.Data.IResultSetFeatureCollection irfc = MapInfo.Engine.Session.Current.Catalog.Search(tablename, si);

int i = 0;
This IRFC can now be stepped through with a foreach loop...

ArrayList arrFea = new ArrayList();
foreach (MapInfo.Data.Feature f in irfc)
{
 And each cell in each returned feature can be accessed with a simple for loop...
 arrFea.Add(f);
 /*for (int j = 0; j < irfc.Columns.Count; j++)
{
print the contents of cell j in feature f to the console screen...

str += f[j].ToString();
}
  */
 i++;
}


3、添加数据
 MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.GetTable(strTableName);
CoordSys coordSys = map.GetDisplayCoordSys();
if (table == null)
{
 return;
}
创建点及其样式
FeatureGeometry geometry = new MapInfo.Geometry.Point(coordSys, x, y);
  = mapToolBarButtonLayerControl.Style;
SimpleVectorPointStyle vStyle = poiStyle;

 SimpleVectorPointStyle vStyle = poistyle;

 mapControl1.sty
 创建的点的样式、颜色和大小都在上条语句中修改

CompositeStyle cStyle = new MapInfo.Styles.CompositeStyle(vStyle);

MIConnection connection = new MIConnection();
MICommand cmd = connection.CreateCommand();

ArrayList arrCol = new ArrayList();
ArrayList arrValue = new ArrayList();
ArrayList arrProperty = new ArrayList();

cmd.Parameters.Add("geometry", MIDbType.FeatureGeometry);
cmd.Parameters.Add("style", MIDbType.Style);
foreach (string str in arrMapCol)
{

 if (str.ToLower().Equals("mi_geometry"))
 {
  /*
arrCol.Add(str);
arrValue.Add("geometry");
arrProperty.Add("geometry");
   */
  cmd.Parameters.Add("geometry", MIDbType.FeatureGeometry);

  continue;
 }
 if (str.ToLower().Equals("mi_style"))
 {
  continue;
  /*
arrCol.Add(str);
arrValue.Add("style");
arrProperty.Add("style");
   */
  cmd.Parameters.Add("style", MIDbType.Style);
 }
 if (dicData.ContainsKey(str))
 {
  arrCol.Add(str);
  arrValue.Add(str);

  cmd.Parameters.Add(str, dicData[str]);
 }


}
cmd.CommandText = "Insert Into " + strTableName + "(";


string s1 = "MI_Geometry,MI_Style,";
string s2 = "geometry,style,";
int i = 0;
for (; i < arrCol.Count - 1; i++)
{
 s1 += (string)arrCol[i] + ",";
 s2 += (string)arrValue[i] + ",";
}
cmd.CommandText += s1 + arrCol[i] + ") values (" + s2 + arrValue[i] + ")";

connection.Open();

cmd.Parameters[0].Value = geometry;
cmd.Parameters[1].Value = cStyle;

int nchanged = cmd.ExecuteNonQuery();

cmd.Dispose();
创建图层并将其插入到当前地图的最上层

/*
FeatureLayer fl = new FeatureLayer(table);
map.Layers.Insert(0, fl);
map.Center = new MapInfo.Geometry.DPoint(x, y);
 */
MapUtility.HighLightPoint(map, "minfotempmap", x, y);

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值