地理座標系変換による座標変換

'地理座標系変換
Public Sub Project()

    Dim pMxDocument As IMxDocument
    Set pMxDocument = ThisDocument
    
    Dim pGCS_Tokyo As ISpatialReference
    Set pGCS_Tokyo = fncSpatialReference(esriSRGeoCSType.esriSRGeoCS_Tokyo, True)
    
    Dim pGCS_JGD_2000 As ISpatialReference
    Set pGCS_JGD_2000 = fncSpatialReference(esriSRGeoCS3Type.esriSRGeoCS_JapanGeodeticDatum2000, True)
    
    Dim pPoint As IPoint
    Set pPoint = New Point
    Dim pGeometry As IGeometry2
    Set pGeometry = pPoint
    pPoint.PutCoords 135, 35
    Set pPoint.SpatialReference = pGCS_Tokyo
    
'    pGeometry.ProjectEx pGCS_JGD_2000, esriTransformForward, CreateTKY2JGD_NTv2Transformation, True, 0, 0
    pGeometry.ProjectEx pGCS_JGD_2000, esriTransformForward, CreateGeoTransformationTKYJGD, True, 0, 0
    
    Dim dd As Long
    Dim mm As Long
    Dim ss As Double
    
    DD2DMS pPoint.x, dd, mm, ss
    Debug.Print dd, mm, ss
    
    DD2DMS pPoint.y, dd, mm, ss
    Debug.Print dd, mm, ss

End Sub

Function fncSpatialReference(valType As Long, blnGeographic As Boolean) As ISpatialReference
 
 'DeveloperHelpから以下を参照
 
 '地理座標系(pcsType)
 'esriSRGeoCSType Contains
 'esriSRGeoCS2Type Constants
 'esriSRGeoCS3Type Constants
 
 '投影座標系(gcsType)
 'esriSRProjCSType Constants
 'esriSRProjCS2Type Constants
 'esriSRProjCS3Type Constants
 'esriSRProjCS4Type Constants
 
 '例
'valType = esriSRProjCS4Type.esriSRProjCS_JGD2000_Japan_Zone_9     'JGD2000 平面直角座標系第9系
'valType = esriSRGeoCS3Type.esriSRGeoCS_JapanGeodeticDatum2000    'JGD2000 地理座標系
 
 Dim pSpatialReferenceFactory As ISpatialReferenceFactory
 Set pSpatialReferenceFactory = New SpatialReferenceEnvironment
 
 If blnGeographic = True Then
     Dim pGeographicCoordinateSystem As IGeographicCoordinateSystem
     Set pGeographicCoordinateSystem = pSpatialReferenceFactory.CreateGeographicCoordinateSystem(valType)
     
     Set fncSpatialReference = pGeographicCoordinateSystem
     
 Else
     Dim pProjectedCoordinateSystem As IProjectedCoordinateSystem
     Set pProjectedCoordinateSystem = pSpatialReferenceFactory.CreateProjectedCoordinateSystem(valType)
 
     Set fncSpatialReference = pProjectedCoordinateSystem
 End If

'XY座標精度の設定(9.2以降は設定必須)
Dim pSpatialReferenceResolution  As ISpatialReferenceResolution
Set pSpatialReferenceResolution = fncSpatialReference
pSpatialReferenceResolution.SetDefaultXYResolution

'XY許容値の設定(9.2以降は設定必須)
Dim pSpatialReferenceTolerance  As ISpatialReferenceTolerance
Set pSpatialReferenceTolerance = fncSpatialReference
pSpatialReferenceTolerance.SetDefaultXYTolerance
 
End Function


'NTv2Transformation(TKY2JGD)の作成
Public Function CreateTKY2JGD_NTv2Transformation() As IGeoTransformation
    Dim pGridTransformation As IGridTransformation
    Set pGridTransformation = New NTv2Transformation
    
    pGridTransformation.Name = "Tokyo_To_JGD2000_TKY2JGD"
    pGridTransformation.GridDatasetName = "Dataset_japan/tky2jgd.gsb"
    pGridTransformation.Load

    
    Set CreateTKY2JGD_NTv2Transformation = pGridTransformation

End Function


'GeocentricTranslationの作成
'3 パラメータ変換(地心変換)
Public Function CreateGeoTransformationTKYJGD() As IGeoTransformation
    Dim pSpatialReferenceFactory As ISpatialReferenceFactory
    Set pSpatialReferenceFactory = New SpatialReferenceEnvironment
    
    '定数による作成
    Dim pGeocentricTranslation As IGeocentricTranslation
    Set pGeocentricTranslation = pSpatialReferenceFactory.CreateGeoTransformation(esriSRGeoTransformation3Type.esriSRGeoTransformation_Tokyo_To_JGD_2000_1)
    
'    Set pGeocentricTranslation = New GeocentricTranslation
'    pGeocentricTranslation.Name = "Tokyo_To_JGD_2000_1"
'    pGeocentricTranslation.PutParameters -146.414, 507.337, 680.507

    Set CreateGeoTransformationTKYJGD = pGeocentricTranslation

End Function


Private Function DD2DMS(ByRef DecimalDegree As Double, ByRef Degree As Long, ByRef Minute As Long, ByRef Second As Double, Optional Reverce As Boolean = False)
    '十進経緯から度分秒に変換
    If Reverce = False Then
        Dim pLatLonFormat As ILatLonFormat
        Set pLatLonFormat = New LatLonFormat
        pLatLonFormat.GetDMS DecimalDegree, Degree, Minute, Second
    
    '度分秒から十進経緯度に変換
    Else
        DecimalDegree = Degree + Minute / 60 + Second / 3600
    
    End If

End Function