Esempio n. 1
0
QGeoCoordinate TrackRecorder::trackPointAt(int index) {
    if(index < m_points.length()) {
        return m_points.at(index).coordinate();
    } else {
        return QGeoCoordinate();
    }
}
QGeoCoordinate OpenstreetmapMapProvider::pixelToCoord(const QPoint& point,
    int zoomLevel) const
{
    return QGeoCoordinate(tiley2lat(point.y() / (double)TILE_DIMENSION,
               zoomLevel),
               tilex2long(point.x() / (double)TILE_DIMENSION, zoomLevel));
}
QGeoCoordinate QGraphicsGeoMap::center() const
{
    if (d_ptr->mapData)
        return d_ptr->mapData->center();

    return QGeoCoordinate();
}
static void calculatePeripheralPoints(QList<QGeoCoordinate> &path, const QGeoCoordinate &center, qreal distance, int steps)
{
    // Calculate points based on great-circle distance
    // Calculation is the same as GeoCoordinate's atDistanceAndAzimuth function
    // but tweaked here for computing multiple points

    // pre-calculate
    qreal latRad = qgeocoordinate_degToRad(center.latitude());
    qreal lonRad = qgeocoordinate_degToRad(center.longitude());
    qreal cosLatRad = std::cos(latRad);
    qreal sinLatRad = std::sin(latRad);
    qreal ratio = (distance / (qgeocoordinate_EARTH_MEAN_RADIUS * 1000.0));
    qreal cosRatio = std::cos(ratio);
    qreal sinRatio = std::sin(ratio);
    qreal sinLatRad_x_cosRatio = sinLatRad * cosRatio;
    qreal cosLatRad_x_sinRatio = cosLatRad * sinRatio;

    for (int i = 0; i < steps; ++i) {
        qreal azimuthRad = 2 * M_PI * i / steps;
        qreal resultLatRad = std::asin(sinLatRad_x_cosRatio
                                   + cosLatRad_x_sinRatio * std::cos(azimuthRad));
        qreal resultLonRad = lonRad + std::atan2(std::sin(azimuthRad) * cosLatRad_x_sinRatio,
                                       cosRatio - sinLatRad * std::sin(resultLatRad));
        qreal lat2 = qgeocoordinate_radToDeg(resultLatRad);
        qreal lon2 = qgeocoordinate_radToDeg(resultLonRad);
        if (lon2 < -180.0) {
            lon2 += 360.0;
        } else if (lon2 > 180.0) {
            lon2 -= 360.0;
        }
        path << QGeoCoordinate(lat2, lon2, center.altitude());
    }
}
/*!
    Returns the coordinate corresponding to the point in the viewport at \a
    screenPosition.

    An invalid QGeoCoordinate will be returned if \a screenPosition is invalid
    or is not within the current viewport.
*/
QGeoCoordinate QGraphicsGeoMap::screenPositionToCoordinate(QPointF screenPosition) const
{
    if (d_ptr->mapData)
        return d_ptr->mapData->screenPositionToCoordinate(screenPosition);

    return QGeoCoordinate();
}
Esempio n. 6
0
MapView::MapView(QWidget *parent) :
    QGraphicsView(parent)
{
    QGraphicsScene* scene = new QGraphicsScene(this);
    setScene(scene);
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setInteractive(true);

    QGeoServiceProvider *serviceProvider = new QGeoServiceProvider("nokia");
    QGeoMappingManager *manager = serviceProvider->mappingManager();

    geo_map = new Map(manager);
    connect(geo_map, SIGNAL(markerClicked(QStringList)), SIGNAL(markerClicked(QStringList)));
    geo_map->setMapType(QGraphicsGeoMap::StreetMap);
    geo_map->setCenter(QGeoCoordinate(0.0, 0.0));
    geo_map->setZoomLevel(5);
    scene->addItem(geo_map);

    track = new QGeoMapPolylineObject;
    QPen pen(Qt::red);
    pen.setWidth(3);
    track->setPen(pen);
    track->setZValue(1);
    setMouseTracking(true);
}
Esempio n. 7
0
QGeoCoordinate QGeoProjection::mercatorToCoord(const QDoubleVector2D &mercator)
{
    const double pi = M_PI;

    double fx = mercator.x();
    double fy = mercator.y();

    if (fy < 0.0)
        fy = 0.0;
    else if (fy > 1.0)
        fy = 1.0;

    double lat;

    if (fy == 0.0)
        lat = 90.0;
    else if (fy == 1.0)
        lat = -90.0;
    else
        lat = (180.0 / pi) * (2.0 * std::atan(std::exp(pi * (1.0 - 2.0 * fy))) - (pi / 2.0));

    double lng;
    if (fx >= 0) {
        lng = realmod(fx, 1.0);
    } else {
        lng = realmod(1.0 - realmod(-1.0 * fx, 1.0), 1.0);
    }

    lng = lng * 360.0 - 180.0;

    return QGeoCoordinate(lat, lng, 0.0);
}
Esempio n. 8
0
/*!
    Translates this geo rectangle by \a degreesLatitude northwards and \a
    degreesLongitude eastwards.

    Negative values of \a degreesLatitude and \a degreesLongitude correspond to
    southward and westward translation respectively.

    If the translation would have caused the geo rectangle to cross a pole the
    geo rectangle will be translated until the top or bottom edge of the geo rectangle
    touches the pole but not further.
*/
void QGeoRectangle::translate(double degreesLatitude, double degreesLongitude)
{
    // TODO handle dlat, dlon larger than 360 degrees

    Q_D(QGeoRectangle);

    double tlLat = d->topLeft.latitude();
    double tlLon = d->topLeft.longitude();
    double brLat = d->bottomRight.latitude();
    double brLon = d->bottomRight.longitude();

    if ((tlLat != 90.0) || (brLat != -90.0)) {
        tlLat += degreesLatitude;
        brLat += degreesLatitude;
    }

    if ( (tlLon != -180.0) || (brLon != 180.0) ) {
        tlLon += degreesLongitude;
        brLon += degreesLongitude;
    }

    if (tlLon < -180.0)
        tlLon += 360.0;
    if (tlLon > 180.0)
        tlLon -= 360.0;

    if (brLon < -180.0)
        brLon += 360.0;
    if (brLon > 180.0)
        brLon -= 360.0;

    if (tlLat > 90.0)
        tlLat = 90.0;

    if (tlLat < -90.0)
        tlLat = -90.0;

    if (brLat > 90.0)
        brLat = 90.0;

    if (brLat < -90.0)
        brLat = -90.0;

    d->topLeft = QGeoCoordinate(tlLat, tlLon);
    d->bottomRight = QGeoCoordinate(brLat, brLon);
}
/*!
    Returns the coordinate that is reached by traveling \a distance meters
    from the current coordinate at \a azimuth (or bearing) along a great-circle.
    There is an assumption that the Earth is spherical for the purpose of this
    calculation.

    The altitude will have \a distanceUp added to it.

    Returns an invalid coordinate if this coordinate is invalid.
*/
QGeoCoordinate QGeoCoordinate::atDistanceAndAzimuth(qreal distance, qreal azimuth, qreal distanceUp) const
{
    if (!isValid())
        return QGeoCoordinate();

    double resultLon, resultLat;
    QGeoCoordinatePrivate::atDistanceAndAzimuth(*this, distance, azimuth,
                                                &resultLon, &resultLat);

    if (resultLon > 180.0)
        resultLon -= 360.0;
    else if (resultLon < -180.0)
        resultLon += 360.0;

    double resultAlt = d->alt + distanceUp;
    return QGeoCoordinate(resultLat, resultLon, resultAlt);
}
Esempio n. 10
0
    void distanceTo_data()
    {
        QTest::addColumn<QGeoCoordinate>("c1");
        QTest::addColumn<QGeoCoordinate>("c2");
        QTest::addColumn<qreal>("distance");

        QTest::newRow("invalid coord 1")
                << QGeoCoordinate() << BRISBANE << qreal(0.0);
        QTest::newRow("invalid coord 2")
                << BRISBANE << QGeoCoordinate() << qreal(0.0);
        QTest::newRow("brisbane -> melbourne")
                << BRISBANE << MELBOURNE << qreal(1374820.1618767744);
        QTest::newRow("london -> new york")
                << LONDON << NEW_YORK << qreal(5570538.4987236429);
        QTest::newRow("north pole -> south pole")
                << NORTH_POLE << SOUTH_POLE << qreal(20015109.4154876769);
    }
Esempio n. 11
0
void
TestEphemeride::test_Ephemeride()
{
  Ephemeride ephemeride;
  ephemeride.set_date(QDate(2016, 1, 1));
  ephemeride.set_coordinate(QGeoCoordinate(48.87, 2.67));
  qInfo() << ephemeride.sunrise() << ephemeride.solar_noon() << ephemeride.sunset();
}
Esempio n. 12
0
void tst_QGeoCircle::areaComparison_data()
{
    QTest::addColumn<QGeoShape>("area");
    QTest::addColumn<QGeoCircle>("circle");
    QTest::addColumn<bool>("equal");

    QGeoCircle c1(QGeoCoordinate(10.0, 0.0), 10.0);
    QGeoCircle c2(QGeoCoordinate(20.0, 10.0), 20.0);
    QGeoRectangle b(QGeoCoordinate(10.0, 0.0), QGeoCoordinate(0.0, 10.0));

    QTest::newRow("default constructed") << QGeoShape() << QGeoCircle() << false;
    QTest::newRow("c1 c1") << QGeoShape(c1) << c1 << true;
    QTest::newRow("c1 c2") << QGeoShape(c1) << c2 << false;
    QTest::newRow("c2 c1") << QGeoShape(c2) << c1 << false;
    QTest::newRow("c2 c2") << QGeoShape(c2) << c2 << true;
    QTest::newRow("b c1") << QGeoShape(b) << c1 << false;
}
Esempio n. 13
0
    void azimuthTo_data()
    {
        QTest::addColumn<QGeoCoordinate>("c1");
        QTest::addColumn<QGeoCoordinate>("c2");
        QTest::addColumn<qreal>("azimuth");

        QTest::newRow("invalid coord 1")
                << QGeoCoordinate() << BRISBANE << qreal(0.0);
        QTest::newRow("invalid coord 2")
                << BRISBANE << QGeoCoordinate() << qreal(0.0);
        QTest::newRow("brisbane -> melbourne")
                << BRISBANE << MELBOURNE << qreal(211.1717286649);
        QTest::newRow("london -> new york")
                << LONDON << NEW_YORK << qreal(288.3388804508);
        QTest::newRow("north pole -> south pole")
                << NORTH_POLE << SOUTH_POLE << qreal(180.0);
    }
Esempio n. 14
0
    void atDistanceAndAzimuth_data()
    {
        QTest::addColumn<QGeoCoordinate>("origin");
        QTest::addColumn<qreal>("distance");
        QTest::addColumn<qreal>("azimuth");
        QTest::addColumn<QGeoCoordinate>("result");

        QTest::newRow("invalid coord")
            << QGeoCoordinate()
            << qreal(1000.0)
            << qreal(10.0)
            << QGeoCoordinate();
        if (sizeof(qreal) == sizeof(double)) {
            QTest::newRow("brisbane -> melbourne")
                << BRISBANE
                << qreal(1374820.1618767744)
                << qreal(211.1717286649)
                << MELBOURNE;
            QTest::newRow("london -> new york")
                << LONDON
                << qreal(5570538.4987236429)
                << qreal(288.3388804508)
                << NEW_YORK;
            QTest::newRow("north pole -> south pole")
                << NORTH_POLE
                << qreal(20015109.4154876769)
                << qreal(180.0)
                << SOUTH_POLE;
        } else {
            QTest::newRow("brisbane -> melbourne")
                << BRISBANE
                << qreal(1374820.1618767744)
                << qreal(211.1717286649)
                << QGeoCoordinate(-37.8142515084775, 144.963170622944);
            QTest::newRow("london -> new york")
                << LONDON
                << qreal(5570538.4987236429)
                << qreal(288.3388804508)
                << QGeoCoordinate(40.7145220608416, -74.0071216045375);
            QTest::newRow("north pole -> south pole")
                << NORTH_POLE
                << qreal(20015109.4154876769)
                << qreal(180.0)
                << QGeoCoordinate(-89.9999947369857, -90.0);
        }
    }
Esempio n. 15
0
/*!
    Sets the height of this geo rectangle in degrees to \a degreesHeight.

    If \a degreesHeight is less than 0.0 or if this geo rectangle is invalid
    this function does nothing. To set up the values of an invalid
    geo rectangle based on the center, width and height you should use
    setCenter() first in order to make the geo rectangle valid.

    If the change in height would cause the geo rectangle to cross a pole
    the height is adjusted such that the geo rectangle only touches the pole.

    This change is done such that the center coordinate is still at the
    center of the geo rectangle, which may result in a geo rectangle with
    a smaller height than might otherwise be expected.

    If \a degreesHeight is greater than 180.0 then 180.0 is used as the height.
*/
void QGeoRectangle::setHeight(double degreesHeight)
{
    if (!isValid())
        return;

    if (degreesHeight < 0.0)
        return;

    if (degreesHeight >= 180.0) {
        degreesHeight = 180.0;
    }

    Q_D(QGeoRectangle);

    double tlLon = d->topLeft.longitude();
    double brLon = d->bottomRight.longitude();

    QGeoCoordinate c = center();

    double tlLat = c.latitude() + degreesHeight / 2.0;
    double brLat = c.latitude() - degreesHeight / 2.0;

    if (tlLat > 90.0) {
        brLat = 2* c.latitude() - 90.0;
        tlLat = 90.0;
    }

    if (tlLat < -90.0) {
        brLat = -90.0;
        tlLat = -90.0;
    }

    if (brLat > 90.0) {
        tlLat = 90.0;
        brLat = 90.0;
    }

    if (brLat < -90.0) {
        tlLat = 2 * c.latitude() + 90.0;
        brLat = -90.0;
    }

    d->topLeft = QGeoCoordinate(tlLat, tlLon);
    d->bottomRight = QGeoCoordinate(brLat, brLon);
}
Esempio n. 16
0
QGeoCoordinate TrackRecorder::trackCenter() {
    // Keep also current position in view
    qreal minLon = qMin(m_minLon, (qreal)m_currentPosition.longitude());
    qreal maxLon = qMax(m_maxLon, (qreal)m_currentPosition.longitude());
    qreal minLat = qMin(m_minLat, (qreal)m_currentPosition.latitude());
    qreal maxLat = qMax(m_maxLat, (qreal)m_currentPosition.latitude());

    return QGeoCoordinate((minLat+maxLat)/2, (minLon+maxLon)/2);
}
Esempio n. 17
0
    void addTestData_info()
    {
        QTest::addColumn<QGeoPositionInfo>("info");

        QTest::newRow("invalid") << QGeoPositionInfo();

        QTest::newRow("coord") << QGeoPositionInfo(QGeoCoordinate(-27.3422,150.2342), QDateTime());
        QTest::newRow("datetime") << QGeoPositionInfo(QGeoCoordinate(), QDateTime::currentDateTime());

        QList<QGeoPositionInfo::Attribute> attributes = tst_qgeopositioninfo_getAttributes();
        QList<qreal> values = tst_qgeopositioninfo_qrealTestValues();
        for (int i=0; i<attributes.count(); i++) {
            for (int j=0; j<values.count(); j++) {
                QTest::newRow(qPrintable(QString("Attribute %1 = %2").arg(attributes[i]).arg(values[j])))
                        << infoWithAttribute(attributes[i], values[j]);
            }
        }
    }
Esempio n. 18
0
void tst_QGeoBoundingCircle::contains_data()
{
    QTest::addColumn<QGeoCoordinate>("center");
    QTest::addColumn<qreal>("radius");
    QTest::addColumn<QGeoCoordinate>("probe");
    QTest::addColumn<bool>("result");

    QTest::newRow("own centre") << QGeoCoordinate(1,1) << qreal(100.0) <<
                                   QGeoCoordinate(1,1) << true;
    QTest::newRow("over the hills") << QGeoCoordinate(1,1) << qreal(100.0) <<
                                       QGeoCoordinate(30, 40) << false;
    QTest::newRow("at 0.5*radius") << QGeoCoordinate(1,1) << qreal(100.0) <<
                                      QGeoCoordinate(1.00015374,1.00015274) << true;
    QTest::newRow("at 0.99*radius") << QGeoCoordinate(1,1) << qreal(100.0) <<
                                       QGeoCoordinate(1.00077538, 0.99955527) << true;
    QTest::newRow("at 1.01*radius") << QGeoCoordinate(1,1) << qreal(100.0) <<
                                       QGeoCoordinate(1.00071413, 0.99943423) << false;
}
/*
    This property holds the width of this georectangle (in degrees).
*/
void GeoRectangleValueType::setWidth(double width)
{
    QGeoRectangle r = v;

    if (!r.isValid())
        r.setCenter(QGeoCoordinate(0.0, 0.0));

    r.setWidth(width);
    v = r;
}
Esempio n. 20
0
WidgetGPS::WidgetGPS(QWidget *parent) :
    QGraphicsView(parent)
{
    coordinatesList.clear();
    myScene = new QGraphicsScene(this);
    this->setScene(myScene);
    this->addCoordinates(QGeoCoordinate(0,0));
    targetCoordinate.setLatitude(0);
    targetCoordinate.setLongitude(0);
}
Esempio n. 21
0
QPoint GeoMap::coordinateToOffscreenPosition (QGeoCoordinate coordinate)
{
    QPoint pixelPosition;
    QGeoCoordinate originCoordinate = screenPositionToCoordinate(QPointF(0,0));
    QGeoCoordinate differenceFromOrigin = QGeoCoordinate (originCoordinate.latitude() - coordinate.latitude(), coordinate.longitude() - originCoordinate.longitude());

    pixelPosition = QPoint(differenceFromOrigin.longitude() * pixelsPerDegreeLongitude, differenceFromOrigin.latitude() * pixelsPerDegreeLatitude);

    return pixelPosition;
}
/*!
    Returns the center of this bounding box.
*/
QGeoCoordinate QGeoBoundingBox::center() const
{
    if (!isValid())
        return QGeoCoordinate();

    double cLat = (d_ptr->topLeft.latitude() + d_ptr->bottomRight.latitude()) / 2.0;

    double cLon = (d_ptr->bottomRight.longitude() + d_ptr->topLeft.longitude()) / 2.0;
    if (d_ptr->topLeft.longitude() > d_ptr->bottomRight.longitude()) {
        cLon = cLon - 180.0;
    }

    if (cLon < -180.0)
        cLon += 360.0;
    if (cLon > 180.0)
        cLon -= 360.0;

    return QGeoCoordinate(cLat, cLon);
}
bool LocationValueTypeProvider::create(int type, int argc, const void *argv[], QVariant *v)
{
    if (type == qMetaTypeId<QGeoCoordinate>()) {
        if (argc == 2) {
            const float *a = reinterpret_cast<const float *>(argv[0]);
            const float *b = reinterpret_cast<const float *>(argv[1]);
            *v = QVariant::fromValue(QGeoCoordinate(*a, *b));
            return true;
        } else if (argc == 3) {
            const float *a = reinterpret_cast<const float *>(argv[0]);
            const float *b = reinterpret_cast<const float *>(argv[1]);
            const float *c = reinterpret_cast<const float *>(argv[2]);
            *v = QVariant::fromValue(QGeoCoordinate(*a, *b, *c));
            return true;
        }
    }

    return false;
}
Esempio n. 24
0
void Ut_Location::testConstructorQGeoPositionInfo()
{
  QGeoPositionInfo thisPositionInfo( QGeoCoordinate( 60.16183, 24.88256 ), QDateTime( QDate( 1965, 11, 11 ) ) );
  Location subject( thisPositionInfo );

  QString x( "2549182" );
  QString y( "6672569" );
  QCOMPARE( subject.x(), x );
  QCOMPARE( subject.y(), y );
}
/*
    This property holds the height of this georectangle (in degrees).
*/
void GeoRectangleValueType::setHeight(double height)
{
    QGeoRectangle r = v;

    if (!r.isValid())
        r.setCenter(QGeoCoordinate(0.0, 0.0));

    r.setHeight(height);
    v = r;
}
Esempio n. 26
0
QGeoCoordinate SlippyCoordinates::toGps(){


    double lon_deg = MercatorPos().x() * 360.0 - 180.0;

    double lat_rad = atan(sinh(M_PI * (1 - 2 * MercatorPos().y())));
    double lat_deg = lat_rad * 180.0 / M_PI;

    return QGeoCoordinate(lat_deg, lon_deg);

}
/*!
    \property QGeoMapPolygonObject::path
    \brief This property holds the ordered list of coordinates which define the
    polygon to be drawn by this polygon object.

    The default value of this property is an empty list of coordinates.

    The coordinates should be listed in the order in which they would be
    traversed when traveling around the border of the polygon.

    Invalid coordinates in the list will be ignored, and if the list of
    coordinates contains less than 3 valid coordinates then the polygon object
    will not be displayed.

    \since 1.1
*/
void QGeoMapPolygonObject::setPath(const QList<QGeoCoordinate> &path)
{
    if (d_ptr->path != path) {
        d_ptr->path = path;
        if (path.size() != 0)
            setOrigin(path.at(0));
        else
            setOrigin(QGeoCoordinate());
        emit pathChanged(emit d_ptr->path);
    }
}
Esempio n. 28
0
void Geocode::initialized(bool success) {
  if (!success) {
    qmlInfo(this) << "Error initializing geocoding";
    setActive(false);
    return;
  }

  if (m_pending.isValid()) {
    search(m_pending.longitude(), m_pending.latitude());
    m_pending = QGeoCoordinate();
  }
}
Esempio n. 29
0
    void atDistanceAndAzimuth_data()
    {
        QTest::addColumn<QGeoCoordinate>("origin");
        QTest::addColumn<qreal>("distance");
        QTest::addColumn<qreal>("azimuth");
        QTest::addColumn<QGeoCoordinate>("result");

        QTest::newRow("invalid coord")
            << QGeoCoordinate() 
            << qreal(1000.0) 
            << qreal(10.0) 
            << QGeoCoordinate();
        QTest::newRow("brisbane -> melbourne")
            << BRISBANE 
            << qreal(1374820.1618767744)
            << qreal(211.1717286649)
// the following platforms use float for qreal
#if !defined(QT_NO_FPU) && !defined(QT_ARCH_ARM) && !defined(QT_ARCH_WINDOWSCE) && !defined(QT_ARCH_SYMBIAN) 
            << MELBOURNE;
#else
            << QGeoCoordinate(-37.8142515084775, 144.963170622944);
Esempio n. 30
0
/*!
    Returns the center of this geo rectangle.
*/
QGeoCoordinate QGeoRectangle::center() const
{
    if (!isValid())
        return QGeoCoordinate();

    Q_D(const QGeoRectangle);

    double cLat = (d->topLeft.latitude() + d->bottomRight.latitude()) / 2.0;

    double cLon = (d->bottomRight.longitude() + d->topLeft.longitude()) / 2.0;
    if (d->topLeft.longitude() > d->bottomRight.longitude()) {
        cLon = cLon - 180.0;
    }

    if (cLon < -180.0)
        cLon += 360.0;
    if (cLon > 180.0)
        cLon -= 360.0;

    return QGeoCoordinate(cLat, cLon);
}