用ArcMap.VBA代码表示如下:
----------------------------------------------------------------------------------
Private Sub projectUsage()
'wanxiangqian@163.com, 2007-10-29
'Set up spatial references
Dim facSR As SpatialReferenceEnvironment
Set facSR = New SpatialReferenceEnvironment
Dim srcSR As IGeographicCoordinateSystem
Set srcSR = facSR.CreateGeographicCoordinateSystem(esriSRGeoCS_Xian1980) 'esriSRSpheroid_Xian1980
Dim destSR As IProjectedCoordinateSystem
Set destSR = facSR.CreateProjectedCoordinateSystem(esriSRProjCS_Xian1980_GK_CM_111E)
'Set up Point for transforming
Dim pt As IPoint
Set pt = New Point
pt.x = 111
pt.y = 30
Set pt.SpatialReference = srcSR
pt.Project destSR
MsgBox "(" & pt.x & "," & pt.y & ")"
Set pt.SpatialReference = destSR
pt.Project srcSR
MsgBox "(" & pt.x & "," & pt.y & ")"
End Sub
----------------------------------------------------------------------------------
找到esriSRProjCS_Xian1980_GK_CM_111E、esriSRGeoCS_Xian1980、esriSRSpheroid_Xian1980这些常量可不容易!
有IProjectedCoordinateSystemEdit接口,但如下所示的方法全然看不懂该传什么值给它,帮助文件也没有任何补偿,很难学习!
public void Define (
ref object Name,
ref object Alias,
ref object Abbreviation,
ref object Remarks,
ref object useage,
ref object gcs,
ref object projectedUnit,
ref object Projection,
ref object parameters
);
下面是帮助文件对参数列表的说明:
Name To indicate that this parameter is undefined, first define a variable object Missing = Type.Missing; then pass this in as ref Missing.
Alias To indicate that this parameter is undefined, first define a variable object Missing = Type.Missing; then pass this in as ref Missing.
Abbreviation To indicate that this parameter is undefined, first define a variable object Missing = Type.Missing; then pass this in as ref Missing.
Remarks To indicate that this parameter is undefined, first define a variable object Missing = Type.Missing; then pass this in as ref Missing.
useage To indicate that this parameter is undefined, first define a variable object Missing = Type.Missing; then pass this in as ref Missing.
gcs To indicate that this parameter is undefined, first define a variable object Missing = Type.Missing; then pass this in as ref Missing.
projectedUnit To indicate that this parameter is undefined, first define a variable object Missing = Type.Missing; then pass this in as ref Missing.
Projection To indicate that this parameter is undefined, first define a variable object Missing = Type.Missing; then pass this in as ref Missing.
parameters To indicate that this parameter is undefined, first define a variable object Missing = Type.Missing; then pass this in as ref Missing.
——不明确每个参数的类型。
教训:接口上使用VARIANT作为数据类型,一定要在帮助文件里说明实际的数据类型。因为此时接口的prototype不能传递任何信息,全靠应用域知识。