Exemplo n.º 1
0
QPointF TilesMap::tileForCoordinate(LatLon coord)
{
    qreal zn = static_cast<qreal>(1 << m_zoom);
    qreal tx = (coord.lon() + 180.0) / 360.0;
    qreal ty = (1.0 - log(tan(coord.lat() * M_PI / 180.0)
                          + 1.0 / cos(coord.lat() * M_PI / 180.0)) / M_PI) / 2.0;
    return QPointF(tx * zn, ty * zn);
}
Exemplo n.º 2
0
Coordinate ProjectionImplementationProj4::latlon2coord(const LatLon &ll) const
{
    if ( _pjBase == 0 || _pjLatlon == 0) {
        int *err = pj_get_errno_ref();
        if (*err != 0){
            QString error(pj_strerrno(*err));
            error = "projection error:" + error;
            kernel()->issues()->log(error);
        }
        return Coordinate();
    }

    double x = ll.lon().radians();
    double y = ll.lat().radians();
    int err = pj_transform(_pjLatlon, _pjBase, 1, 1, &x, &y, NULL );
    if ( err != 0) {
        QString error(pj_strerrno(err));
        error = "projection error:" + error;
        kernel()->issues()->log(error);
        return Coordinate();
    }

    if ( _outputIsLatLon) {
        //return Coordinate(Degrees(y,false).degrees(),Degrees(x, false).degrees());
        return Coordinate(x * RAD_TO_DEG, y * RAD_TO_DEG);
    }
    return Coordinate(x,y);
}
Exemplo n.º 3
0
QPointF MapWidget::latLonToPoint(LatLon latlon)
{
    qreal x = (latlon.lon() + 180.0) / 360.0;
    qreal y = (M_PI - log(tan(M_PI / 4 + latlon.lat() * (M_PI / 180.0) / 2))) / (2 * M_PI);
    qreal z = static_cast<qreal>(1 << m_zoom);
    return QPointF(x * z * 256, y * z * 256);
}
LatLon ProjectionImplementationInternal::coord2latlon(const Ilwis::Coordinate &crdSource) const
{
    if (_coordinateSystem->projection().isValid() && crdSource != crdUNDEF) {
        Coordinate xy((crdSource.x - _easting) / _maxis, (crdSource.y - _northing) / _maxis);

        LatLon pl = crd2ll(xy);
        if (!pl.isValid())
            return llUNDEF;
        if (abs(pl.lat()) > 90)
            return llUNDEF;
        pl.lon( pl.lon() + _centralMeridian);
        return pl;
    }
    else
        return llUNDEF;

}
Exemplo n.º 5
0
void MapWidget::mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton) {
        m_pressPos = m_movePos = event->pos();
    }
    else if (event->button() == Qt::RightButton) {
        QPoint delta = event->pos() - QPoint(width() / 2, height() / 2);
        LatLon coord = pointToLatLon(latLonToPoint(m_center) + delta);

        QLineEdit *edit;
        edit = m_pointDialog->findChild<QLineEdit *>("latitudeEdit");
        edit->setText(QString().setNum(coord.lat(), 'f', 6));
        edit = m_pointDialog->findChild<QLineEdit *>("longitudeEdit");
        edit->setText(QString().setNum(coord.lon(), 'f', 6));
        edit = m_pointDialog->findChild<QLineEdit *>("nameEdit");
        edit->setText("");
        edit->setFocus();

        m_pointDialog->setWindowTitle("Add Point");
        m_pointDialog->open();
    }
}
Exemplo n.º 6
0
Coordinate PlateCaree::ll2crd(const LatLon &ll) const
{
    return Coordinate(ll.lon(), ll.lat());
}