编程语言
首页 > 编程语言> > C# ARCGIS ENGINE 根据经纬度和距离画圆

C# ARCGIS ENGINE 根据经纬度和距离画圆

作者:互联网

1.距离转换为经纬度的差值

        ARCGIS ENGINE创建圆的Element时,函数除了要求经纬度,还需要以度为单位的半径,在有些应用中只有距离(米)数据,这时需要将距离转换为度。

    public static class GISCOMMONFUNC
    {
        private const double EARTH_RADIUS = 6378137;//地球半径
        private const double PI = 3.14159265358979323; //圆周率
        private const double R = 6371229;             //地球的半径

        private static double rad(double d)
        {
            return d * Math.PI / 180.0;
        }

        /// <summary>
        /// 从经纬度计算两点距离
        /// </summary>
        /// <param name="lat1"></param>
        /// <param name="lng1"></param>
        /// <param name="lat2"></param>
        /// <param name="lng2"></param>
        /// <returns></returns>
        public static double GetDistance(double lat1, double lng1, double lat2, double lng2)
        {
            double radLat1 = rad(lat1);
            double radLat2 = rad(lat2);
            double a = radLat1 - radLat2;
            double b = rad(lng1) - rad(lng2);

            double s = 2 * Math.Asin(Math.Sqrt(Math.Pow(Math.Sin(a / 2), 2) +
             Math.Cos(radLat1) * Math.Cos(radLat2) * Math.Pow(Math.Sin(b / 2), 2)));
            s = s * EARTH_RADIUS;
            s = Math.Round(s * 10000) / 10000;
            return s;
        }

        /// <summary>
        /// 根据经纬度和距离计算经度差值
        /// </summary>
        /// <param name="longt1"></param>
        /// <param name="lat1"></param>
        /// <param name="distance"></param>
        /// <returns></returns>
        public static double getLongt(double longt1, double lat1, double distance)
        {
            double a = (180 * distance) / (PI * R * Math.Cos(lat1 * PI / 180));
            return a;
        }

        /// <summary>
        /// 根据经纬度和距离计算纬度差值
        /// </summary>
        /// <param name="longt1"></param>
        /// <param name="lat1"></param>
        /// <param name="distance"></param>
        /// <returns></returns>
        public static double getLat(double longt1, double lat1, double distance)
        {
            double a = (180 * distance) / (PI * R * Math.Cos(lat1 * PI / 180));
            return a;
        }
    }

参考文献:

java经纬度距离换算,根据距离算经纬度差值_weixin_34038652的博客-CSDN博客icon-default.png?t=LA92https://blog.csdn.net/weixin_34038652/article/details/92086540?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522163712290116780264073372%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=163712290116780264073372&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-6-92086540.pc_search_result_control_group&utm_term=%E8%B7%9D%E7%A6%BB%E7%AE%97%E7%BB%8F%E7%BA%AC%E5%BA%A6&spm=1018.2226.3001.4187根据两点经纬度计算距离_tiao321的专栏-CSDN博客icon-default.png?t=LA92https://blog.csdn.net/tiao321/article/details/7899556?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522163712164916780262555095%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=163712164916780262555095&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduend~default-1-7899556.pc_search_result_control_group&utm_term=%E7%BB%8F%E7%BA%AC%E5%BA%A6%E7%AE%97%E8%B7%9D%E7%A6%BB&spm=1018.2226.3001.4187

2.ARCGIS ENGINE上画圆

        根据经纬度和距离计算可以分别计算出经度角度差和纬度角度差,通常是不相等的,较为精确的做法是画椭圆,但要求不高的场合下(如纬度不高),用圆也可以。

        userclass是自定义类,有经度、纬度、距离等成员。

//删除原来的element
if (pLElement != null)
{
    graphicsContainer.DeleteElement(pLElement);
    axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pLElement, null);
}

//创建区域样式
ILineSymbol pLineSymbol = new SimpleLineSymbolClass();//产生一个线符号对象
pLineSymbol.Width = 2;
IRgbColor color = new RgbColor();
color.Red = 0;
color.Green = 0;
color.Blue = 255;
pLineSymbol.Color = color;
IFillSymbol pFillSymbol = new SimpleFillSymbolClass();//设置填充符号的属性
color.Transparency = 0;
pFillSymbol.Color = color;
pFillSymbol.Outline = pLineSymbol;

//创建圆形
IPoint point = new PointClass();
point.X = userclass.longitude;
point.Y = userclass.latitude;
double radius = GISCOMMONFUNC.getLongt(userclass.longitude, userclass.latitude,userclass.range_horizon);//半径
IConstructCircularArc pConstructCircularArc = new CircularArcClass();
pConstructCircularArc.ConstructCircle(point, radius, false);
ICircularArc pArc = pConstructCircularArc as ICircularArc;

//构建ring对象
ISegment pSegment1 = pArc as ISegment; //通过ISegmentCollection构建Ring对象
ISegmentCollection pSegCollection = new RingClass();
object o = Type.Missing; //添加Segement对象即圆
pSegCollection.AddSegment(pSegment1, ref o, ref o); //QI到IRing接口封闭Ring对象,使其有效
IRing pRing = pSegCollection as IRing;
pRing.Close(); //通过Ring对象使用IGeometryCollection构建Polygon对象

//设置element的几何结构
IGeometryCollection pGeometryColl = new PolygonClass();
pGeometryColl.AddGeometry(pRing, ref o, ref o); //构建一个CircleElement对象
pLElement = new CircleElementClass();
pLElement.Geometry = pGeometryColl as IGeometry;
//设置element的样式
IFillShapeElement pFillShapeElement = pLElement as IFillShapeElement;
pFillShapeElement.Symbol = pFillSymbol;

//显示到地图
graphicsContainer.AddElement(pLElement, 0);
axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pLElement, null);

参考文献:

Arcgis---画圆_新博客:https://aping-dev.com/-CSDN博客icon-default.png?t=LA92https://blog.csdn.net/u012319493/article/details/77930993

标签:ENGINE,经纬度,C#,double,E7%,画圆,2522%,new,Math
来源: https://blog.csdn.net/weixin_45700726/article/details/121375429