MapXtreme 2005学习(6):两种方法实现动态轨迹
摘要:图层表名称<;初始点坐标<;DPoint firstPoint){MapInfo.Mapping.MapmyMap=MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias];
在GIS中,动态轨迹的实现是非常有用的,可用GPS定位,热点跟踪等。在本例中,先创建一个用于呈现动态轨迹的临时图层,并在图层上添加一个点表示位体的位置。代码如下:
![MapXtreme 2005学习(6):两种方法实现动态轨迹第1张](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//// <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)
![MapXtreme 2005学习(6):两种方法实现动态轨迹第1张](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias];
![MapXtreme 2005学习(6):两种方法实现动态轨迹第3张](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//创建临时图层
MapInfo.Data.TableInfoMemTable tblInfoTemp = new MapInfo.Data.TableInfoMemTable(trackLayerTableName);
MapInfo.Data.Table tblTemp = MapInfo.Engine.Session.Current.Catalog.GetTable(trackLayerTableName);
if (tblTemp != null)
![MapXtreme 2005学习(6):两种方法实现动态轨迹第20张](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
MapInfo.Engine.Session.Current.Catalog.CloseTable(trackLayerTableName);
}
![MapXtreme 2005学习(6):两种方法实现动态轨迹第3张](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
tblInfoTemp.Columns.Add(MapInfo.Data.ColumnFactory.CreateFeatureGeometryColumn(myMap.GetDisplayCoordSys()));
tblInfoTemp.Columns.Add(MapInfo.Data.ColumnFactory.CreateStyleColumn());
tblTemp = MapInfo.Engine.Session.Current.Catalog.CreateTable(tblInfoTemp);
![MapXtreme 2005学习(6):两种方法实现动态轨迹第3张](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
FeatureLayer workLayer = new FeatureLayer(tblTemp, AnimationLayerName, AnimationLayerName);
myMap.Layers.Add(workLayer);
![MapXtreme 2005学习(6):两种方法实现动态轨迹第3张](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//向临时图层中添加初始点
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));
![MapXtreme 2005学习(6):两种方法实现动态轨迹第3张](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
MapInfo.Data.Feature pft = new MapInfo.Data.Feature(tblTemp.TableInfo.Columns);
pft.Geometry = pfg;
pft.Style = cstyle;
workLayer.Table.InsertFeature(pft);
}实现动态轨迹的第一种方法是,对原来点的坐标的位置进行偏移,从实现位置的更新。代码如下:
![MapXtreme 2005学习(6):两种方法实现动态轨迹第1张](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//// <summary>
/// 把原来的点偏移到新的位置以实现动态轨迹
/// Glacier
/// 2008年8月7日
/// <param name="trackLayerTableName">图层表名</param>
/// <param name="newPoint">点的新坐标</param>
/// </summary>
protected void UpdateTrack(string trackLayerTableName, DPoint newPoint)
![MapXtreme 2005学习(6):两种方法实现动态轨迹第1张](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
MapInfo.Data.Table altb = MapInfo.Engine.Session.Current.Catalog.GetTable(trackLayerTableName);
if (altb == null)
![MapXtreme 2005学习(6):两种方法实现动态轨迹第20张](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return;
}
![MapXtreme 2005学习(6):两种方法实现动态轨迹第3张](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//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)
![MapXtreme 2005学习(6):两种方法实现动态轨迹第20张](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
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();
}实现动态轨迹的第二种方法是,先删除原有的点,再在新的位置添加一个新点。因为第一种方法求偏移过程中可能会产生误差,并且这种误差是会积累的。而这种方法相对来说会比较精确一点。代码如下:
![MapXtreme 2005学习(6):两种方法实现动态轨迹第1张](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//// <summary>
/// 把删除原有点并向图层中添加新点以实现动态轨迹
/// Glacier
/// 2008年8月7日
/// <param name="trackLayerTableName">图层表名</param>
/// <param name="newPoint">点的新坐标</param>
/// </summary>
protected void UpdateTrack(string trackLayerTableName, DPoint newPoint)
![MapXtreme 2005学习(6):两种方法实现动态轨迹第1张](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
MapInfo.Data.Table altb = MapInfo.Engine.Session.Current.Catalog.GetTable(trackLayerTableName);
if (altb == null)
![MapXtreme 2005学习(6):两种方法实现动态轨迹第20张](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return;
}
![MapXtreme 2005学习(6):两种方法实现动态轨迹第3张](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//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)
![MapXtreme 2005学习(6):两种方法实现动态轨迹第20张](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
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));
![MapXtreme 2005学习(6):两种方法实现动态轨迹第3张](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
MapInfo.Data.Feature pft = new MapInfo.Data.Feature(altb.TableInfo.Columns);
pft.Geometry = pfg;
pft.Style = cstyle;
altb.InsertFeature(pft);
}免责声明:文章转载自《MapXtreme 2005学习(6):两种方法实现动态轨迹》仅用于学习参考。如对内容有疑问,请及时联系本站处理。
上篇Mongodb 笔记03 查询、索引浅谈pipreqs组件(自动生成需要导入的模块信息) 和 virtualenv(虚拟环境)下篇
宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=