OSGEarth的测量分析

我的测量有距离测量、面积测量、高度测量。
测量的结果显示都为一个PlaceNode,可以实时的显示测量的结果。
使用方式为:

pPlaceNode = new osgEarth::Annotation::PlaceNode(
            MapNode, osgEarth::GeoPoint::GeoPoint(), "", textStyle);
pPlaceNode->setDynamic(true);
pPlaceNode->setText("测量结果");
pPlaceNode->setPosition(osgEarth::GeoPoint::GeoPoint(SRS, pos("经纬度")));
  • 长度的计算方式使用OSGEarth提供的方式osgEarth::GeoMath::distance()
  • 高度的测量直接两个点的高度差即可;
  • 面积的测量,比较麻烦,考虑到需要计算球面的面积,因而需要实现计算方式。附上一个从网上找到的计算方式,由于忘记了原网站,请见谅!

    网上内容,非原创算法
    for (int i = 0; i < iCount; i++)
        {
            if (i == 0)
            {
                //换算成弧度;
                dLowX = osg::DegreesToRadians(points.at(iCount - 1).x());
                dLowY = osg::DegreesToRadians(points.at(iCount - 1).y());
                dMiddleX = osg::DegreesToRadians(points.at(0).x());
                dMiddleY = osg::DegreesToRadians(points.at(0).y());
                dHighX = osg::DegreesToRadians(points.at(1).x());
                dHighY = osg::DegreesToRadians(points.at(1).y());
            }
            else if (i == iCount - 1)
            {
                dLowX = osg::DegreesToRadians(points.at(iCount - 2).x());
                dLowY = osg::DegreesToRadians(points.at(iCount - 2).y());
                dMiddleX = osg::DegreesToRadians(points.at(iCount - 1).x());
                dMiddleY = osg::DegreesToRadians(points.at(iCount - 1).y());
                dHighX = osg::DegreesToRadians(points.at(0).x());
                dHighY = osg::DegreesToRadians(points.at(0).y());
            }
            else
            {
                dLowX = osg::DegreesToRadians(points.at(i - 1).x());
                dLowY = osg::DegreesToRadians(points.at(i - 1).y());
                dMiddleX = osg::DegreesToRadians(points.at(i).x());
                dMiddleY = osg::DegreesToRadians(points.at(i).y());
                dHighX = osg::DegreesToRadians(points.at(i + 1).x());
                dHighY = osg::DegreesToRadians(points.at(i + 1).y());
            }
            AM = cos(dMiddleY) * cos(dMiddleX);
            BM = cos(dMiddleY) * sin(dMiddleX);
            CM = sin(dMiddleY);
            AL = cos(dLowY) * cos(dLowX);
            BL = cos(dLowY) * sin(dLowX);
            CL = sin(dLowY);
            AH = cos(dHighY) * cos(dHighX);
            BH = cos(dHighY) * sin(dHighX);
            CH = sin(dHighY);
    
            dCoefficientL = (AM*AM + BM*BM + CM*CM) / (AM*AL + BM*BL + CM*CL);
            dCoefficientH = (AM*AM + BM*BM + CM*CM) / (AM*AH + BM*BH + CM*CH);
    
            dALtangent = dCoefficientL * AL - AM;
            dBLtangent = dCoefficientL * BL - BM;
            dCLtangent = dCoefficientL * CL - CM;
            dAHtangent = dCoefficientH * AH - AM;
            dBHtangent = dCoefficientH * BH - BM;
            dCHtangent = dCoefficientH * CH - CM;
    
            dAngleCos = (dAHtangent * dALtangent + dBHtangent * dBLtangent + dCHtangent * dCLtangent) /
                (sqrt(dAHtangent * dAHtangent + dBHtangent * dBHtangent + dCHtangent * dCHtangent) *
                sqrt(dALtangent * dALtangent + dBLtangent * dBLtangent + dCLtangent * dCLtangent));
    
            dAngleCos = acos(dAngleCos);
    
            dANormalLine = dBHtangent * dCLtangent - dCHtangent * dBLtangent;
            dBNormalLine = 0 - (dAHtangent * dCLtangent - dCHtangent * dALtangent);
            dCNormalLine = dAHtangent * dBLtangent - dBHtangent * dALtangent;
    
            if (AM != 0)
            {
                dOrientationValue = dANormalLine / AM;
            }
            else if (BM != 0)
            {
                dOrientationValue = dBNormalLine / BM;
            }
            else
            {
                dOrientationValue = dCNormalLine / CM;
            }
            if (dOrientationValue > 0)
            {
                dSum1 += dAngleCos;
                iCount1++;
            }
            else
            {
                dSum2 += dAngleCos;
                iCount2++;
            }
        }
        if (dSum1 > dSum2)
        {
            dSum = dSum1 + (2 * osg::PI*iCount2 - dSum2);
        }
        else
        {
            dSum = (2 * osg::PI*iCount1 - dSum1) + dSum2;
        }
    
        dTotalArea = (dSum - (iCount - 2)*osg::PI)* osg::WGS_84_RADIUS_EQUATOR *
            osg::WGS_84_RADIUS_EQUATOR;
    }

你可能感兴趣的:(C++/Qt,OSG)