Esempio n. 1
0
LatLon MapWidget::pointToLatLon(QPointF point)
{
    qreal z = static_cast<qreal>(1 << m_zoom);
    qreal lat = (2 * atan(exp((0.5 - point.y() / z / 256) * 2 * M_PI)) - M_PI / 2) * 180 / M_PI;
    qreal lon = point.x() / z / 256 * 360.0 - 180.0;
    return LatLon(lat, lon);
}
Esempio n. 2
0
LatLon TilesMap::coordinateForTile(const QPointF &tile)
{
    qreal zn = static_cast<qreal>(1 << m_zoom);
    qreal n = M_PI - 2 * M_PI * tile.y() / zn;
    qreal lat = 180.0 / M_PI * atan(0.5 * (exp(n) - exp(-n)));
    qreal lon = tile.x() / zn * 360.0 - 180.0;
    return LatLon(lat, lon);
}
Esempio n. 3
0
void GeoreferencingDialog::latLonEdited()
{
	const QSignalBlocker block1(keep_geographic_radio), block2(keep_projected_radio);
	double latitude  = lat_edit->value();
	double longitude = lon_edit->value();
	georef->setGeographicRefPoint(LatLon(latitude, longitude), !grivation_locked);
	keep_geographic_radio->setChecked(true);
	reset_button->setEnabled(true);
}
Esempio n. 4
0
// Searches the kd tree starting at the given depth and the given node for the
// node with the value closest to point. It updates guess, guessID, and bestDist
// with the results.
void search_kdTree(unsigned depth, kdNode* tree, const LatLon& point, LatLon& guess, unsigned& guessID, double& bestDist) {
    if (tree == NULL)
        return;
    double squared_distance = find_squared_distance_between_two_points(tree->position, point);
    if (squared_distance < bestDist) {
        bestDist = squared_distance;
        guess = tree->position;
        guessID = tree->id;
    }
    bool goRight = false;
    if (depth % 2) { // odd
        if ( tree->position.lon < point.lon)
            goRight = true;
    } else {
        if ( tree->position.lat < point.lat)
            goRight = true;
    }
    if (goRight == true)
        search_kdTree(depth + 1, tree->right, point, guess, guessID, bestDist);
    else 
        search_kdTree(depth + 1, tree->left, point, guess, guessID, bestDist);
    LatLon treeLon = LatLon(point.lat, tree->position.lon);
    LatLon pointLon = LatLon(point.lat, point.lon);
    LatLon treeLat = LatLon(tree->position.lat, point.lon);
    LatLon pointLat = LatLon(point.lat, point.lon);
    if ((tree->left != NULL && tree->left->position.lat == tree->position.lat) || (tree->right != NULL && tree->right->position.lat == tree->position.lat) ||
        (tree->left != NULL && tree->left->position.lon == tree->position.lon) || (tree->right != NULL && tree->right->position.lon == tree->position.lon) ||
        ((depth % 2) && (find_squared_distance_between_two_points(treeLon, pointLon) <= bestDist)) ||
        ((!(depth % 2)) && (find_squared_distance_between_two_points(treeLat, pointLat) <= bestDist))) {
        if (goRight == true) {
            search_kdTree(depth + 1, tree->left, point, guess, guessID, bestDist);
        } else {
            search_kdTree(depth + 1, tree->right, point, guess, guessID, bestDist);
        }
        }
    return;
}
Esempio n. 5
0
LatLon Spherical::getLocation_rad() const {
  double la, lo;
  double y1, x1, z1;

  double wx, wy, xx, yy, yz, xz, x2, y2, z2;
  x2 = x + x;
  y2 = y + y;
  z2 = z + z;
  xx = x * x2;
  xz = x * z2;
  yy = y * y2;
  yz = y * z2;
  wx = w * x2;
  wy = w * y2;

  x1 = xz + wy;

  y1 = yz - wx;

  z1 = 1.0f - (xx + yy);

  la = asin(y1);

  // scale latitudinal ring to unit size
  lo = sqrt(1.0 - (y1 * y1));
  lo = x1 / lo;
  // calculate longitude
  lo = asin(lo);
  if(z1 < 0) {
    lo = pi - lo;
  } else if(x1 < 0) {
    lo = (2 * pi) + lo;
  }

  LatLon ll = LatLon();
  ll.Latitude = la;
  ll.Longatude = lo;
  return ll;
}
Esempio n. 6
0
template<> LatLon Init::undefined<LatLon>()
{
    return LatLon(Init::undefined<double>(), Init::undefined<double>());
}
bool OsmAnd::FavoriteLocationsGpxCollection_P::loadFrom(QXmlStreamReader& xmlReader)
{
	std::shared_ptr< FavoriteLocation > newItem;
	QList< std::shared_ptr< FavoriteLocation > > newItems;

	while (!xmlReader.atEnd() && !xmlReader.hasError())
	{
		xmlReader.readNext();
		const auto tagName = xmlReader.name();
		if (xmlReader.isStartElement())
		{
			if (tagName == QLatin1String("wpt"))
			{
				if (newItem)
				{
					LogPrintf(LogSeverityLevel::Warning, "Malformed favorites GPX file: unpaired <wpt>");
					return false;
				}

				bool ok = true;
				const double lat = xmlReader.attributes().value(QLatin1String("lat")).toDouble(&ok);
				if (!ok)
				{
					LogPrintf(LogSeverityLevel::Warning, "Malformed favorites GPX file: invalid latitude");
					return false;
				}
				const double lon = xmlReader.attributes().value(QLatin1String("lon")).toDouble(&ok);
				if (!ok)
				{
					LogPrintf(LogSeverityLevel::Warning, "Malformed favorites GPX file: invalid longitude");
					return false;
				}

				newItem.reset(new FavoriteLocation(LatLon(lat, lon)));
			}
			else if (tagName == QLatin1String("name"))
			{
				if (!newItem)
				{
					LogPrintf(LogSeverityLevel::Warning, "Malformed favorites GPX file: unpaired <name>");
					return false;
				}

				newItem->setTitle(xmlReader.readElementText());
			}
			else if (tagName == QLatin1String("category"))
			{
				if (!newItem)
				{
					LogPrintf(LogSeverityLevel::Warning, "Malformed favorites GPX file: unpaired <category>");
					return false;
				}

                const auto& group = xmlReader.readElementText();
                if (!group.isEmpty())
                    newItem->setGroup(group);
			}
			else if (tagName == QLatin1String("color"))
			{
				if (!newItem)
				{
					LogPrintf(LogSeverityLevel::Warning, "Malformed favorites GPX file: unpaired <color>");
					return false;
				}

				bool ok = false;
				const auto color = Utilities::parseColor(xmlReader.readElementText(), ColorARGB(), &ok);
				if (!ok)
				{
					LogPrintf(LogSeverityLevel::Warning, "Malformed favorites GPX file: invalid color");
					continue;
				}

				newItem->setColor(static_cast<ColorRGB>(color));
			}
            else if (tagName == QLatin1String("color"))
            {
                if (!newItem)
                {
                    LogPrintf(LogSeverityLevel::Warning, "Malformed favorites GPX file: unexpected <hidden/>");
                    return false;
                }

                newItem->setIsHidden(true);
            }
		}
		else if (xmlReader.isEndElement())
		{
			if (tagName == QLatin1String("wpt"))
			{
				if (!newItem)
				{
					LogPrintf(LogSeverityLevel::Warning, "Malformed favorites GPX file: unpaired </wpt>");
					return false;
				}

				newItems.push_back(newItem);
				newItem.reset();
			}
		}
	}
	if (xmlReader.hasError())
	{
		LogPrintf(
            LogSeverityLevel::Warning,
            "XML error: %s (%" PRIi64 ", %" PRIi64 ")",
            qPrintable(xmlReader.errorString()),
            xmlReader.lineNumber(),
            xmlReader.columnNumber());
		return false;
	}

	{
		QWriteLocker scopedLocker(&_collectionLock);

		doClearFavoriteLocations();
		appendFrom(newItems);

		notifyCollectionChanged();
	}

	return true;
}
Esempio n. 8
0
bool TemplateImage::postLoadConfiguration(QWidget* dialog_parent, bool& out_center_in_view)
{
	Q_UNUSED(out_center_in_view);
	
	if (getTemplateFilename().endsWith(".gif", Qt::CaseInsensitive))
		QMessageBox::warning(dialog_parent, tr("Warning"), tr("Loading a GIF image template.\nSaving GIF files is not supported. This means that drawings on this template won't be saved!\nIf you do not intend to draw on this template however, that is no problem."));
	
	TemplateImageOpenDialog open_dialog(this, dialog_parent);
	open_dialog.setWindowModality(Qt::WindowModal);
	while (true)
	{
		if (open_dialog.exec() == QDialog::Rejected)
			return false;
		
		if (open_dialog.isGeorefRadioChecked() && !map->getGeoreferencing().isValid())
		{
			// Make sure that the map is georeferenced;
			// use the center coordinates of the image as initial reference point.
			calculateGeoreferencing();
			QPointF template_coords_center = georef->toProjectedCoords(MapCoordF(0.5 * (image.width() - 1), 0.5 * (image.height() - 1)));
			bool template_coords_probably_geographic =
				template_coords_center.x() >= -90 && template_coords_center.x() <= 90 &&
				template_coords_center.y() >= -90 && template_coords_center.y() <= 90;
			
			Georeferencing initial_georef(map->getGeoreferencing());
			if (template_coords_probably_geographic)
				initial_georef.setGeographicRefPoint(LatLon(template_coords_center.y(), template_coords_center.x()));
			else
				initial_georef.setProjectedRefPoint(template_coords_center);
			initial_georef.setState(Georeferencing::ScaleOnly);
			
			GeoreferencingDialog dialog(dialog_parent, map, &initial_georef, false);
			if (template_coords_probably_geographic)
				dialog.setKeepGeographicRefCoords();
			else
				dialog.setKeepProjectedRefCoords();
			if (dialog.exec() == QDialog::Rejected)
				continue;
		}
		
		if (open_dialog.isGeorefRadioChecked() && available_georef == Georeferencing_WorldFile)
		{
			// Let user select the coordinate reference system, as this is not specified in world files
			SelectCRSDialog dialog(map, dialog_parent, true, false, true, tr("Select the coordinate reference system of the coordinates in the world file"));
			if (dialog.exec() == QDialog::Rejected)
				continue;
			temp_crs_spec = dialog.getCRSSpec();
		}
		
		break;
	}
	
	is_georeferenced = open_dialog.isGeorefRadioChecked();	
	if (is_georeferenced)
		calculateGeoreferencing();
	else
	{
		transform.template_scale_x = open_dialog.getMpp() * 1000.0 / map->getScaleDenominator();
		transform.template_scale_y = transform.template_scale_x;
		
		//transform.template_x = main_view->getPositionX();
		//transform.template_y = main_view->getPositionY();
		
		updateTransformationMatrices();
	}
	
	return true;
}