原始线要素类为地理坐标系,如何获取以米为单位的距离?

要素类坐标系为CGCS2000地理坐标系,在ArcMap中加载该要素类,用Measure工具选择Geodesic,Distance单位选中Meters,进行测量即可获取以米为单位的长度。Engine中如何获取该以米为单位的长度?
已邀请:

朱新颖

赞同来自: 鹿果一夏

【解决办法】:
可以使用IPolycurveGeodetic.get_LengthGeodetic();方法,将要量测的IPolyline转为IPolycurveGeodetic即可。
测试代码如下:


            IPolyline polyline = feature.Shape as IPolyline;
         
            IPolycurveGeodetic polycurve = polyline as IPolycurveGeodetic;
            ILinearUnitEdit linearUnitEdit = new LinearUnitClass();

            //Define the properties for the linear unit 
            object name = Meter;
            object alias = Meter;
            object abbreviation = M;
            object remarks = Meter is the linear unit;
            object metersPerUnit = 1;
            linearUnitEdit.Define(ref name, ref alias, ref abbreviation, ref remarks, ref metersPerUnit);
            ILinearUnit pLU = linearUnitEdit as ILinearUnit;

            double distance = polycurve.get_LengthGeodetic(esrType.esriGeodeticTypeGeodesic,pLU);

鹿果一夏

赞同来自:

正解,但是貌似多边形的会有内存泄漏问题
int indexTBMJ = disCursor.FindField("TBMJ");
ILinearUnit linearUnit = DefineLinearUnit();
int count = 1;
foreach (var feature in disCursor.AsEnumerable())
{
var polygon = feature.Shape as IPolygon;
IAreaGeodetic areaGeodetic = (IAreaGeodetic)polygon;
double geodeticArea = areaGeodetic.AreaGeodetic[esriGeodeticType.esriGeodeticTypeGeodesic, linearUnit];
feature.Value[indexTBMJ] = geodeticArea;
disCursor.UpdateFeature(feature);
polygon.SetEmpty();
(areaGeodetic as IPolygon).SetEmpty();
Marshal.FinalReleaseComObject(areaGeodetic);
Marshal.FinalReleaseComObject(polygon);

if (count % 100000 == 0)
Console.WriteLine($"{prefix}计算要素{count}个,耗时:{stopwatch.Elapsed}");
count++;
}
以上代码内存一直上涨,不会回收

要回复问题请先登录注册