屏幕像素值与经纬度值的换算


 /// <summary>
        /// 像素值与经纬度值的换算
        /// </summary>
        /// <param name="activeView"></param>
        /// <param name="iDevUnit"></param>
        /// <returns></returns>
        public double calcMapScale(IActiveView activeView, double iDevUnit) //后面参数为像素值
        {
            double mapUnits = 0.01;
            IScreenDisplay pSd = activeView.ScreenDisplay;
            if (pSd != null)
            {
                //获取地图空间的像素宽度
                IDisplayTransformation pDtf = pSd.DisplayTransformation;
                tagRECT tagRect = pDtf.get_DeviceFrame();
                int iPixelWid = tagRect.right - tagRect.left;
                //获取当前地图视图的地理宽度
                IEnvelope pExtentEnve = activeView.Extent;
                mapUnits = pExtentEnve.Width / iPixelWid * iDevUnit;
            }
            return mapUnits;
        }

以下是大地坐标和经纬度之间的转换函数,可以用C语言实现: ```c #include <math.h> #define PI 3.14159265358979323846 // 大地坐标结构体 struct GeodeticCoordinate { double latitude; // 纬度,单位为度 double longitude; // 经度,单位为度 double altitude; // 海拔高度,单位为米 }; // 经纬度结构体 struct GeographicCoordinate { double latitude; // 纬度,单位为弧度 double longitude; // 经度,单位为弧度 }; // 大地坐标转经纬度 struct GeographicCoordinate geodetic_to_geographic(struct GeodeticCoordinate geodetic_coord) { double a = 6378137; // 地球长半轴,单位为米 double b = 6356752.314245; // 地球短半轴,单位为米 double e = sqrt(1 - pow(b/a, 2)); // 第一偏心率 double e2 = pow(e, 2); // 第二偏心率 double N = a / sqrt(1 - e2 * pow(sin(geodetic_coord.latitude * PI / 180), 2)); // 卯酉圈曲率半径 double X = (N + geodetic_coord.altitude) * cos(geodetic_coord.latitude * PI / 180) * cos(geodetic_coord.longitude * PI / 180); double Y = (N + geodetic_coord.altitude) * cos(geodetic_coord.latitude * PI / 180) * sin(geodetic_coord.longitude * PI / 180); double Z = (N * (1 - e2) + geodetic_coord.altitude) * sin(geodetic_coord.latitude * PI / 180); double p = sqrt(pow(X, 2) + pow(Y, 2)); double longitude = atan(Y / X); double latitude = atan(Z / p / (1 - e2)); double N1 = a / sqrt(1 - e2 * pow(sin(latitude), 2)); while (fabs(N - N1) > 1e-6) { N = N1; latitude = atan(Z / p / (1 - e2 * N / (N + geodetic_coord.altitude))); N1 = a / sqrt(1 - e2 * pow(sin(latitude), 2)); } struct GeographicCoordinate geographic_coord; geographic_coord.latitude = latitude; geographic_coord.longitude = longitude; return geographic_coord; } // 经纬度转大地坐标 struct GeodeticCoordinate geographic_to_geodetic(struct GeographicCoordinate geographic_coord) { double a = 6378137; // 地球长半轴,单位为米 double b = 6356752.314245; // 地球短半轴,单位为米 double e = sqrt(1 - pow(b/a, 2)); // 第一偏心率 double N = a / sqrt(1 - e * e * pow(sin(geographic_coord.latitude), 2)); // 卯酉圈曲率半径 double X = (N + geographic_coord.altitude) * cos(geographic_coord.latitude) * cos(geographic_coord.longitude); double Y = (N + geographic_coord.altitude) * cos(geographic_coord.latitude) * sin(geographic_coord.longitude); double Z = (N * (1 - e * e) + geographic_coord.altitude) * sin(geographic_coord.latitude); double p = sqrt(pow(X, 2) + pow(Y, 2)); double latitude = atan(Z / p); double longitude = atan(Y / X); double altitude = p / cos(latitude) - N; struct GeodeticCoordinate geodetic_coord; geodetic_coord.latitude = latitude / PI * 180; geodetic_coord.longitude = longitude / PI * 180; geodetic_coord.altitude = altitude; return geodetic_coord; } ``` 其中,`GeodeticCoordinate`表示大地坐标,`GeographicCoordinate`表示经纬度。`geodetic_to_geographic`函数将大地坐标转换为经纬度,`geographic_to_geodetic`函数将经纬度转换为大地坐标。需要注意的是,这里的角度单位为度和弧度,需要进行相应的转换。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值