博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

MapXtreme 更新点,如果点不存在,创建

Posted on 2011-03-05 01:28  VcBuilder  阅读(444)  评论(1)    收藏  举报

许多网文谈到移动点有二种办法,一是删除后建立,二是通过前后点的偏移。

经过试验发现,可以采用更新坐标点的办法,实现点的移动,其他图元以此类推。(在MapXtreme 6.8下测试通过)

// 更新点,如果点不存在,则创建
public void UpdatePoint(string tableName, string ID, DPoint dPoint, short pCode, int pSize, Color color, string myLabel)
{
MapInfo.Mapping.Map myMap
= MapInfo.Engine.Session.Current.MapFactory[mapControl1.Map.Alias];
FeatureLayer workLayer
= (MapInfo.Mapping.FeatureLayer)myMap.Layers[tableName + ""];
MapInfo.Data.Table table
= workLayer.Table;

FeatureGeometry point
= new MapInfo.Geometry.Point(workLayer.CoordSys, dPoint);

SearchInfo si
= MapInfo.Data.SearchInfoFactory.SearchWhere("type='点' and index=" + "'" + ID + "'");
Feature feature
= MapInfo.Engine.Session.Current.Catalog.SearchForFeature(table, si);
if (feature == null)
{
SimpleVectorPointStyle spsPoint
= new MapInfo.Styles.SimpleVectorPointStyle(pCode, color, pSize);
CompositeStyle pointStyle
= new MapInfo.Styles.CompositeStyle(spsPoint);

Feature pointRow
= new MapInfo.Data.Feature(table.TableInfo.Columns);
pointRow.Geometry
= point;
pointRow.Style
= pointStyle;

pointRow[
"type"] = "";
pointRow[
"index"] = ID;
pointRow[
"value"] = myLabel;
table.InsertFeature(pointRow);
}
else
{
feature.Geometry
= point;
feature[
"value"] = myLabel;
feature.Update();
}
}