mapinfo操作(转载http://www.cnblogs.com/glacierh/archive/2008/08/07/1263044.html)

 /// <summary>
    /// 创建动态轨迹图层
    /// Glacier
    /// 2008年8月7日
    /// <param name="trackLayerTableName">图层表名</param>
    /// <param name="trackLayerName">图层名</param>
    /// <param name="firstPoint">点初始坐标</param>
    /// </summary>
    protected void CreateTrackLayer(string trackLayerTableName, string trackLayerName, DPoint firstPoint)
    {
        MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias];

        //创建临时图层
        MapInfo.Data.TableInfoMemTable tblInfoTemp = new MapInfo.Data.TableInfoMemTable(trackLayerTableName);
        MapInfo.Data.Table tblTemp = MapInfo.Engine.Session.Current.Catalog.GetTable(trackLayerTableName);
        if (tblTemp != null)
        {
            MapInfo.Engine.Session.Current.Catalog.CloseTable(trackLayerTableName);
        }

        tblInfoTemp.Columns.Add(MapInfo.Data.ColumnFactory.CreateFeatureGeometryColumn(myMap.GetDisplayCoordSys()));
        tblInfoTemp.Columns.Add(MapInfo.Data.ColumnFactory.CreateStyleColumn());
        tblTemp = MapInfo.Engine.Session.Current.Catalog.CreateTable(tblInfoTemp);

        FeatureLayer workLayer = new FeatureLayer(tblTemp, AnimationLayerName, AnimationLayerName);
        myMap.Layers.Add(workLayer);

        //向临时图层中添加初始点
        FeatureGeometry pfg = new MapInfo.Geometry.Point(workLayer.CoordSys, firstPoint.x, firstPoint.y) as FeatureGeometry;
        MapInfo.Styles.CompositeStyle cstyle = new MapInfo.Styles.CompositeStyle(new MapInfo.Styles.SimpleVectorPointStyle(52, System.Drawing.Color.Blue, 30));

        MapInfo.Data.Feature pft = new MapInfo.Data.Feature(tblTemp.TableInfo.Columns);
        pft.Geometry = pfg;
        pft.Style = cstyle;
        workLayer.Table.InsertFeature(pft);
    }
	
	
	
	
	
	
	/// <summary>
    /// 把原来的点偏移到新的位置以实现动态轨迹
    /// Glacier
    /// 2008年8月7日
    /// <param name="trackLayerTableName">图层表名</param>
    /// <param name="newPoint">点的新坐标</param>
    /// </summary>
    protected void UpdateTrack(string trackLayerTableName, DPoint newPoint)
    {
        MapInfo.Data.Table altb = MapInfo.Engine.Session.Current.Catalog.GetTable(trackLayerTableName);
        if (altb == null)
        {
            return;
        }

        //Change the positon of the existed feature.
        SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchWhere("");
        Feature ftr = MapInfo.Engine.Session.Current.Catalog.SearchForFeature(altb, si);
        if (ftr == null)
        {
            return;
        }
        DPoint offsetPoint = new DPoint(newPoint.x - ftr.Geometry.Centroid.x, newPoint.y - ftr.Geometry.Centroid.y);
        ftr.Geometry.GetGeometryEditor().OffsetByXY(offsetPoint.x, offsetPoint.y, DistanceUnit.Degree, DistanceType.Spherical);
        ftr.Geometry.EditingComplete();
        ftr.Update();
    }

 

实现动态轨迹的第二种方法是,先删除原有的点,再在新的位置添加一个新点。因为第一种方法求偏移过程中可能会产生误差,并且这种误差是会积累的。而这种方法相对来说会比较精确一点。代码如下:

 
   /// <summary>
    /// 把删除原有点并向图层中添加新点以实现动态轨迹
    /// Glacier
    /// 2008年8月7日
    /// <param name="trackLayerTableName">图层表名</param>
    /// <param name="newPoint">点的新坐标</param>
    /// </summary>
    protected void UpdateTrack(string trackLayerTableName, DPoint newPoint)
    {
        MapInfo.Data.Table altb = MapInfo.Engine.Session.Current.Catalog.GetTable(trackLayerTableName);
        if (altb == null)
        {
            return;
        }

        //Delete the existed feature and create a new one.
        SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchWhere("");
        Feature dftr = MapInfo.Engine.Session.Current.Catalog.SearchForFeature(altb, si);
        if (dftr == null)
        {
            return;
        }
        altb.DeleteFeature(dftr);
        MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias];
        FeatureGeometry pfg = new MapInfo.Geometry.Point(myMap.GetDisplayCoordSys(), new DPoint(newPoint.x, newPoint.y)) as FeatureGeometry;
        MapInfo.Styles.CompositeStyle cstyle = new MapInfo.Styles.CompositeStyle(new MapInfo.Styles.SimpleVectorPointStyle(52, System.Drawing.Color.Blue, 30));

        MapInfo.Data.Feature pft = new MapInfo.Data.Feature(altb.TableInfo.Columns);
        pft.Geometry = pfg;
        pft.Style = cstyle;
        altb.InsertFeature(pft);
    }


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值