Score
0
Watch 35 Star 90 Fork 39

iOceanPlus_Modules / Module_Qt_GeographyC++GPL-2.0

Create your Gitee Account
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
基于Qt的GUI库开发的地理信息模块,处理了180度经线的问题,提供:矩形、圆形、多边形、线段、折线、扇形、扇环类。提供了日出日落计算时间等方法。 spread retract

Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

Qt_Geography

项目类关系图见下: 类图

功能1:地理多边形

封装Qt的QGeoCircle、QGeoRectangle和QPolygonF类,成为地理多边形、地理圆形和地理矩形,共同的基类为MyQtGeoShapeBase。
提供一个常用功能:查询某个坐标是否在某个地理形状内。
当从西向东运动的时候,经度值逐渐增大,直到东经180度后突变为-180度(西经用复数表示),然后再逐渐增长到-179度,-178度,以此类推。当一个空间区域跨东经180度的时候,进行特殊处理,判断覆盖范围。下图是地球上的经度划分:

经度

如下图所示,是一个横跨180度经度线的多边形区域,绿色点是海上的目标。通过提供的GeoShapes库,可以生成多边形空间对象,判断某个坐标点是否在该多边形内。

横跨国际日期变更线的多边形区域

功能2:地理扇形及扇环

在地理圆形的基础上进一步封装为地理扇形,地理扇形的基础上封装为地理扇环。

功能3:空间距离计算及日出日落计算

  • 计算两个经纬度间的距离(great circle)
  • 计算给定经纬度给定日期的日出日落时间

基类接口

virtual bool containsPoint(QGeoCoordinate geoCoordinate, Qt::FillRule fillRule=Qt::OddEvenFill) =0;
qint32 getGeoShapObjectID() const;
void setGeoShapObjectID(const qint32 &value);  
virtual qreal distanceFromPointInMeters(const QGeoCoordinate &geoCoordPoint)=0;

多边形类接口

// use x to represent longitude, y to represent latitude.
// Note the difference from QGeoCoordinate: first parameter is latitude, second parameter is longitude.
explicit MyQtGeoPolygon(QVector<QPointF> paramGeoPointsInDegreesBeforeTranslate, bool *ok,QObject *parent = 0);
virtual bool containsPoint(QGeoCoordinate geoCoordinate, Qt::FillRule fillRule=Qt::OddEvenFill) ;
QPolygonF getPolygonFTranslated() const;
QVector<QPointF> getGeoPointsInDegreesBeforeTranslate() const;
QVector<QPointF> getGeoPointsInDegreeAfterTranslate() const;

矩形类接口

explicit MyQtGeoRectangle(const QGeoCoordinate &bottomLeft, const QGeoCoordinate &topRight, bool *ok, QObject *parent = 0);
virtual bool containsPoint(QGeoCoordinate geoCoordinate, Qt::FillRule fillRule=Qt::OddEvenFill) ;
QGeoRectangle getGeoRectangle() const;
void setGeoRectangle(const QGeoRectangle &value);

圆形类接口

explicit MyQtGeoCircle(const QGeoCoordinate &center, qreal radiusInMeters,bool *ok,QObject *parent = 0);
virtual bool containsPoint(QGeoCoordinate geoCoordinate, Qt::FillRule fillRule=Qt::OddEvenFill) ;
QGeoCircle getGeoCircle() const;
void setGeoCircle(const QGeoCircle &value);

扇形类接口

explicit  MyQtGeoCircularSector(const QGeoCoordinate &center, const qreal &radiusInMeters,bool *ok,const qint32 &geoShapeObjectID, const QString &name, const double &startDirectionInDegree,const double &endDirectionInDegree,  QObject *parent = 0);
virtual bool containsPoint(QGeoCoordinate geoCoordinate, Qt::FillRule fillRule=Qt::OddEvenFill) ;
virtual Enum_MyQtGeoShapeType getGeoShapeType() const;

扇环类接口

explicit  MyQtGeoAnnularSector(const QGeoCoordinate &center, const qreal &radiusInMeters,bool *ok,const qint32 
&geoShapeObjectID, const QString &name, const double &startDirectionInDegree, const double &endDirectionInDegree,
 const float &radiusInnerInKM, QObject *parent = 0);
virtual bool containsPoint(QGeoCoordinate geoCoordinate, Qt::FillRule fillRule=Qt::OddEvenFill) ;
virtual Enum_MyQtGeoShapeType getGeoShapeType() const;  

线段类接口

explicit MyQtGeoLineSegment(const QGeoCoordinate &geoCoordStart, const QGeoCoordinate &geoCoordEnd, bool *ok,
                                const   qint32 &geoShapeObjectID, const QString &name, QObject *parent = 0);
virtual bool containsPoint(const QGeoCoordinate &geoCoordinate, Qt::FillRule fillRule=Qt::OddEvenFill)=0 ; //To be implemented
virtual qreal distanceFromPointInMeters(const QGeoCoordinate &geoCoordPoint); //To be implemented
virtual Enum_MyQtGeoShapeType getGeoShapeType() const;
qreal getLineLength() const;

Geography接口

static  qreal GetDistance(double lat1, double lng1, double lat2, double lng2);
static  qreal GetAzimuth(double lat1, double lng1, double lat2, double lng2);
static  float calculateSunriseAsUTCHour(int year, int month, int day, float lat, float lng);
static  float calculateSunsetAsUTCHour(int year, int month, int day, float lat, float lng);

使用示例

构造一个跨过东经180度线的矩形,然后判断(20,180)这一个点是否在区域内。

QGeoCoordinate coorBottomLeft(10,160); //第一个参数是纬度,第二个参数是经度
QGeoCoordinate coorUpperRight(40,-160);
MyQtGeoRectangle *myGeoRect=new MyQtGeoRectangle (coorBottomLeft,coorUpperRight,&ok);
qDebug()<<myGeoRect->getGeoRectangle().bottomLeft()<<myGeoRect->getGeoRectangle().bottomRight();
MyQtGeoShapeBase *myShape=myGeoRect;
QGeoCoordinate pFTestb(20,180);
qDebug()<<myShape->containsPoint(pFTestb);

Comments ( 3 )

Sign in for post a comment

C++
1
https://gitee.com/iOceanPlus_Modules/Qt_GeoPolygon.git
git@gitee.com:iOceanPlus_Modules/Qt_GeoPolygon.git
iOceanPlus_Modules
Qt_GeoPolygon
Module_Qt_Geography
master

Search