FAQ
ArcObjects で測地線に基づく距離の計測をしたい

ナレッジ番号:5338 | 登録日:2023/07/26 | 更新日:2024/11/21

概要

測地線に基づいて地理座標系(経緯度)で指定した 2 点間の距離を求める方法を示します。

サンプル コード

始点(pPointFrom)と終点(pPointTo)にぞれぞれ十進経緯度で座標値を指定してください。測地系を変更したい場合は、CreateGeographicCoordinateSystem メソッドの引数を変更してください(日本測地系:4301、日本測地系2000:4612、日本測地系2011:104020、WGS84:4326)。

//地理座標系の定義
Type t = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
ISpatialReferenceFactory pSpatialReferenceFactory = (ISpatialReferenceFactory)Activator.CreateInstance(t);
ISpatialReference pSpatialReference = pSpatialReferenceFactory.CreateGeographicCoordinateSystem(4326); //WGS 1984

//始点経緯度の指定
IPoint pPointFrom = new PointClass();
pPointFrom.SpatialReference = pSpatialReference;
pPointFrom.PutCoords(135, 35);

//終点経緯度の指定
IPoint pPointTo = new PointClass();
pPointTo.SpatialReference = pSpatialReference;
pPointTo.PutCoords(130, 35);

//距離単位の定義
ILinearUnit pLinearUnit  = new LinearUnitClass();
ILinearUnitEdit pLinearUnitEdit = (ILinearUnitEdit)pLinearUnit;
pLinearUnitEdit.Define("Meter", "", "", "", 1);  //メートル

IGeometryServer2 pGeometryServer = new GeometryServerClass();
double length = pGeometryServer.GetDistanceGeodesic(pSpatialReference, pPointFrom, pPointTo, pLinearUnit);

MessageBox.Show(length.ToString());
'地理座標系の定義
Dim t As Type = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment")
Dim pSpatialReferenceFactory As ISpatialReferenceFactory = CType(Activator.Create(t), ISpatialReferenceFactory)
Dim pSpatialReference As ISpatialReference = pSpatialReferenceFactory.CreateGeographicCoordinateSystem(4326)’WGS 1984

'始点
Dim pPointFrom As IPoint = New PointClass()
pPointFrom.SpatialReference = pSpatialReference
pPointFrom.PutCoords(135, 35)

'終点
Dim pPointTo As IPoint = New PointClass()
pPointTo.SpatialReference = pSpatialReference
pPointTo.PutCoords(130, 35)

'距離単位の定義
Dim pLinearUnit As ILinearUnit = New LinearUnitClass()
Dim pLinearUnitEdit As ILinearUnitEdit = CType(pLinearUnit, ILinearUnitEdit)
pLinearUnitEdit.Define("Meter", "", "", "", 1)  'メートル

Dim pGeometryServer As IGeometryServer2 = New GeometryServerClass()
Dim length As Double = pGeometryServer.GetDistanceGeodesic(pSpatialReference, pP, pPointTo, pLinearUnit)

MessageBox.Show(length.ToString())

メタデータ

機能

種類

製品