1

arcobjects 中是否有办法为图层获取唯一 ID?如果您按图层名称进行搜索,则可能存在重复项。

如果没有属性有没有办法生成一个ID?我尝试使用 GetHash() 但这并没有保持一致。

4

4 回答 4

2

存在用于设置或获取图层 ID 的 ArcObjects 接口。您应该查看 ILayerDescriptor:ID, http: //resources.esri.com/help/9.3/ArcGISDesktop/ArcObjects/esriCarto/ILayerDescriptor_ID.htm

这是一个 VBA 片段,它显示了如何使用它:

Public Sub layerInfo()

Dim app As IApplication '
Set app = Application

Dim mxDoc As IMxDocument
Set mxDoc = app.Document

Dim myMap As IMap
Set myMap = mxDoc.ActiveView

Dim mapServer As IMxdServer
Set mapServer = New MxdServer

'''Point to your .mxd...
mapServer.Start ("D:\Test.mxd")

Dim myArray As IArray
Set myArray = mapServer.LayerDescriptors(myMap.Name)

MsgBox myArray.Count

Dim x As ILayerDescriptor
Dim intX As Integer
intX = 0

For intX = 0 To myArray.Count - 1
Set x = myArray.Element(intX)
MsgBox x.ID
MsgBox x.Name
Next

End Sub
于 2009-08-14T11:50:28.963 回答
1

它并不漂亮,但过去我在图层描述中附加了一个 guid。像这样的东西:

<LAYER guid='a9843c88-3caa-4953-ad96-ca9990b410e9' revision='1' />

我有一个浮动的 DLL,它会将这些 xml 片段插入 MXD 的每一层(前面有足够的 cr/lf 以将 xml 片段从 ArcMap Layer Prop 对话框中的图层描述中滚动出来)。

7z 文件中有一个帮助文件(文档很少,因为我在做其他事情): http ://code.google.com/p/umbriel/downloads/list

于 2009-08-13T20:26:18.790 回答
1

我喜欢使用 GUID 的想法。然后可以将其存储在 ModelName 属性中,该属性是自定义对象开发人员用来保证对象名称独立于真实名称或别名的工具。

在http://geographika.co.uk/?p=58有更多细节和示例代码

于 2009-09-26T17:00:13.717 回答
0

简单的。使用 COM 的一个副作用以及 vtable 的布局方式是,您可以使用层本身的内存地址作为唯一标识符。在许多 ESRI GeoDatabase 和 Carto 代码本身的实现中,这个技巧被到处使用。

于 2009-08-18T20:18:43.007 回答