FeatureService.UpdateFeatures() 与 MgLayer.UpdateFeatures()的区别

在MapGuide开发中你可能注意到有两个相关的函数可以用来更新数据,他们是FeatureService.UpdateFetures() 和 MgLayer.UpdateFeatures(),那么这两个函数有什么区别吗?大家先看下面两段代码:

首先看使用FeatureService.UpdateFeatures的代码片段:

MgMap map = new MgMap(siteConnection);
map.Open(resService, "Sheboygan");

MgLayer layer = map.GetLayers().GetItem("Parcels") as MgLayer;
MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
commands.Add(new MgDeleteFeatures("Parcels", selectString));
MgResourceIdentifier resId = new MgResourceIdentifier("Library://Exercise/Data/Parcels.FeatureSource");
featService.UpdateFeatures(resId, commands, false);

还有这个使用MgLayer.UpdateFeatures()的代码片段:

MgMap map = new MgMap(siteConnection);
map.Open(resService, "Sheboygan");

MgLayer layer = map.GetLayers().GetItem("Parcels") as MgLayer;
MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
commands.Add(new MgDeleteFeatures("Parcels", selectString));
layer.UpdateFeatures(commands);

这两段代码都是没问题的。实际上对于Parcel这样可以表示成图层的数据源来说,这两段代码是等效的。第一种FeatureService.UpdateFeature()是更底层的API,适用于MapGuide OpenSource 1.0以来的所有版本。为了简化图层对应的数据源的操作,比如在某图层上增加一些要素,后来的MapGuide版本中提供了新的API -- MgLayer.UpdateFeature(). 不过从概念上来讲,图层本身并不包含数据,图层只是数据源的一种表现形式,真正的数据是保存在数据源Datasource里面的。所以这个新API的实现也是调用了底层MgFeatureService.UpdateFeatures()而已。对于可以表现为图层的数据源的更新,这两种方法都可以。

但对于不能表现为图层的数据源的更新,那就只能用MgFeatureService了,比如你需要对数据源中的某个数据表进行操作,而这个数据表没有Geometry字段不能表示为图层,那就只能用MgFeatureService了。总结,如果为了兼容那么就用MgFeatureService.UpdateFeatures(). 。如果为了简单就用MgLayer.UpdateFeatures().

题外话,对于这样的纯数据表的操作,你当然可以用ADO.NET的纯数据库操作方法,不过FDO(MgFeatureServier)也没问题哦,FDO其实也是一种数据库访问层,无论是对GIS数据源还是普通的数据源而言,FDO都可以的 :)

原文地址:https://www.cnblogs.com/junqilian/p/2870907.html