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); }
void GPSDisplay::debugPositionUpdate() { #if MAPPER_DEVELOPMENT_BUILD if (! visible) return; QTime now = QTime::currentTime(); float offset = now.msecsSinceStartOfDay() / (float)(10 * 1000); float accuracy = 12 + 7 * qSin(2 + offset); float altitude = 400 + 10 * qSin(1 + 0.1f * offset); MapCoordF coord(30 * qSin(0.5f * offset), 30 * qCos(0.53f * offset)); emit mapPositionUpdated(coord, accuracy); if (georeferencing.isValid() && ! georeferencing.isLocal()) { bool ok; LatLon latLon = georeferencing.toGeographicCoords(coord, &ok); if (ok) { emit latLonUpdated(latLon.latitude(), latLon.longitude(), altitude, accuracy); } } gps_updated = true; tracking_lost = false; has_valid_position = true; latest_gps_coord = coord; latest_gps_coord_accuracy = accuracy; updateMapWidget(); #endif }
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); }
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); }
LatLon ConventionalCoordinateSystem::coord2latlon(const Coordinate &crdSource) const { LatLon pl = _projection->coord2latlon(crdSource); if (!pl.isValid()) return llUNDEF; if (abs(pl.lon()) > 90) return llUNDEF; return pl; }
Coordinate ConventionalCoordinateSystem::coord2coord(const ICoordinateSystem &sourceCs, const Coordinate &crdSource) const { if (sourceCs->isEqual(*this)) return crdSource; LatLon ll = sourceCs->coord2latlon(crdSource); if ( ll.isValid()) { return latlon2coord(ll); } return Coordinate(); }
Coordinate ConventionalCoordinateSystem::coord2coord(const ICoordinateSystem &sourceCs, const Coordinate &crdSource) const { //TODO isLatLon guard doesn't consider latlon cs other than WGS84! if (sourceCs->id() == id()) // the 'real'isEqual test is too expensive here, as this method can be called 100000's of times (resample) return crdSource; LatLon ll = sourceCs->isLatLon() ? LatLon(crdSource.y,crdSource.x) : sourceCs->coord2latlon(crdSource); if ( ll.isValid()) { return isLatLon() ? ll : latlon2coord(ll); } return Coordinate(); }
Pixel Camera::translateLatLon(LatLon latlon) { CvMat* latlonHomogeneous = cvCreateMat(3, 1, CV_32FC1); cvmSet(latlonHomogeneous, 0, 0, latlon.getLat()); cvmSet(latlonHomogeneous, 1, 0, latlon.getLon()); cvmSet(latlonHomogeneous, 2, 0, 1.0); CvMat* pixelHomogeneous = cvCreateMat(3, 1, CV_32FC1); cvMatMul(inverse, latlonHomogeneous, pixelHomogeneous); int x = (int)(cvmGet(pixelHomogeneous, 0, 0) / cvmGet(pixelHomogeneous, 2, 0)); int y = (int)(cvmGet(pixelHomogeneous, 1, 0) / cvmGet(pixelHomogeneous, 2, 0)); Pixel pixel(x, y); return pixel; }
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; }
// slot void GeoreferencingDialog::projectionChanged() { ScopedMultiSignalsBlocker block( crs_selector, lat_edit, lon_edit ); if (georef->getState() == Georeferencing::Normal) { const std::vector< QString >& parameters = georef->getProjectedCRSParameters(); auto temp = CRSTemplateRegistry().find(georef->getProjectedCRSId()); if (!temp || temp->parameters().size() != parameters.size()) { // The CRS id is not there anymore or the number of parameters has changed. // Enter as custom spec. crs_selector->setCurrentCRS(CRSTemplateRegistry().find("PROJ.4"), { georef->getProjectedCRSSpec() }); } else { crs_selector->setCurrentCRS(temp, parameters); } } LatLon latlon = georef->getGeographicRefPoint(); double latitude = latlon.latitude(); double longitude = latlon.longitude(); lat_edit->setValue(latitude); lon_edit->setValue(longitude); QString osm_link = QString("http://www.openstreetmap.org/?lat=%1&lon=%2&zoom=18&layers=M"). arg(latitude).arg(longitude); QString worldofo_link = QString("http://maps.worldofo.com/?zoom=15&lat=%1&lng=%2"). arg(latitude).arg(longitude); link_label->setText( tr("<a href=\"%1\">OpenStreetMap</a> | <a href=\"%2\">World of O Maps</a>"). arg(osm_link). arg(worldofo_link) ); QString error = georef->getErrorText(); if (error.length() == 0) status_field->setText(tr("valid")); else status_field->setText(QString("<b style=\"color:red\">") % error % "</b>"); }
Coordinate ConventionalCoordinateSystem::coord2coord(const ICoordinateSystem &sourceCs, const Coordinate &crdSource) const { //TODO isLatLon guard doesn't consider latlon cs other than WGS84! if (sourceCs->id() == id()) // the 'real'isEqual test is too expensive here, as this method can be called 100000's of times (resample) return crdSource; LatLon ll = sourceCs->isLatLon() ? LatLon(crdSource.y,crdSource.x) : sourceCs->coord2latlon(crdSource); if (ll.isValid()) { if (hasType(sourceCs->ilwisType(), itCONVENTIONALCOORDSYSTEM)) { const IConventionalCoordinateSystem & srcCs = sourceCs.as<ConventionalCoordinateSystem>(); if (srcCs->datum().get() && datum().get() && !srcCs->datum()->equal(*datum().get())) { // different datums given, datum shift needed ll = srcCs->datum()->llToWGS84(ll, *srcCs->ellipsoid().ptr()); ll = datum()->llFromWGS84(ll, *ellipsoid().ptr()); } } return isLatLon() ? ll : latlon2coord(ll); } return Coordinate(); }
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(); } }
Coordinate ProjectionImplementationInternal::latlon2coord(const LatLon &ll) const { if (_coordinateSystem->projection().isValid() && ll.isValid()) { LatLon pl(ll); if (pl.lat() > M_PI_2) pl.lat(Angle(M_PI_2, true)); else if (pl.lat() < -M_PI_2) pl.lat(Angle(-M_PI_2, true)); pl.lon( pl.lon()-_centralMeridian); Coordinate xy = ll2crd(pl); if (xy != crdUNDEF) return crdUNDEF; Coordinate crd; crd.x = xy.x * _maxis + _easting; crd.y = xy.y * _maxis + _northing; return crd; } else return crdUNDEF; }
Vector3 Utilities::latLonToECEF(LatLon latLon) { scene::LatLonAlt lla(latLon.getLat(), latLon.getLon()); return latLonToECEF(lla); }
Coordinate PlateCaree::ll2crd(const LatLon &ll) const { return Coordinate(ll.lon(), ll.lat()); }
void SubGridLayer::calcEnvelope(Coordinate& cmin, Coordinate& cmax) const { cmin = layerManager()->rootLayer()->zoomEnvelope().min_corner(); cmax = layerManager()->rootLayer()->zoomEnvelope().max_corner(); if (!cmin.isValid() || !cmax.isValid()) return; ICoordinateSystem screenCsy = layerManager()->rootLayer()->screenCsy(); if (!screenCsy.isValid()) return; if (screenCsy->isUnknown()) // cant do any extra calcs with unknown return; bool isLatLon = screenCsy->isLatLon(); if (isLatLon) { if (cmin.y <= -89) cmin.y = -89; if (cmin.x < -180) cmin.x = -180; if (cmax.y >= 89) cmax.y = 89; if (cmax.x > 180) cmax.x = 180; } else { LatLon llmin = screenCsy->coord2latlon(cmin); LatLon llmax = screenCsy->coord2latlon(cmax); if (llmin.isValid() && llmax.isValid()) { if (llmin.Lat() <= -85) cmin.y = screenCsy->latlon2coord(LatLon(-85, llmin.Lon())).y; if (llmin.Lon() < -180) cmin.x = screenCsy->latlon2coord(LatLon(llmin.Lat(), -180)).x; if (llmax.Lat() > 85) cmax.y = screenCsy->latlon2coord(LatLon(85, llmax.Lon())).y; if (llmax.Lon() > 180) cmax.x = screenCsy->latlon2coord(LatLon(llmax.Lat(), 180)).x; } } }