Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to change (longitude, latitude) to QGraphicsItem(x,y) ?
Forum Updated to NodeBB v4.3 + New Features

How to change (longitude, latitude) to QGraphicsItem(x,y) ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 489 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • sonichyS Offline
    sonichyS Offline
    sonichy
    wrote on last edited by
    #1

    I have already get the point(longitude, latitude) of gpx file, how to draw them on QGrahpicsScene ?
    替代文字

    QFile file(filePath);
    if(!file.open(QFile::ReadOnly))
        return;
    QDomDocument doc;
    if (!doc.setContent(&file)) {
        file.close();
        return;
    }
    file.close();
    
    QTreeWidgetItem *TWI_root = new QTreeWidgetItem(ui->treeWidget);
    TWI_root->setText(0, QFileInfo(filePath).fileName());
    TWI_root->setIcon(0, QIcon::fromTheme("application-gpx+xml", QIcon(":/icon.png")));
    
    QDomElement root = doc.documentElement();
    QDomNodeList DNL = root.elementsByTagName("trkpt");
    QPainterPath PP;
    for (int i=0; i<DNL.count(); i++) {
        QDomNode DN = DNL.at(i);
        if (DN.isElement()) {
            QDomElement DE = DN.toElement();
            qreal lon = DE.attribute("lon").toDouble();
            qreal lat = DE.attribute("lat").toDouble();
            QTreeWidgetItem *TWI_point = new QTreeWidgetItem(TWI_root);
            TWI_point->setText(0, QString("%1").arg(lon, 0, 'f', 14) + "," + QString("%1").arg(lat, 0, 'f', 14));
            TWI_point->setIcon(0, QIcon(":/marker.png"));
            QGraphicsEllipseItem *GEI = new QGraphicsEllipseItem(lon, lat, 5, 5);
            GEI->setFlags(QGraphicsItem::ItemIsSelectable);
            scene->addItem(GEI);
            if (i == 0)
                PP.moveTo(lon, lat);
            else
                PP.lineTo(lon, lat);
        }
    }
    QPen pen(Qt::blue, 1);
    QGraphicsPathItem *GPI = scene->addPath(PP, pen);
    GPI->setFlags(QGraphicsItem::ItemIsSelectable);
    

    https://github.com/sonichy

    Pl45m4P 1 Reply Last reply
    0
    • sonichyS sonichy

      I have already get the point(longitude, latitude) of gpx file, how to draw them on QGrahpicsScene ?
      替代文字

      QFile file(filePath);
      if(!file.open(QFile::ReadOnly))
          return;
      QDomDocument doc;
      if (!doc.setContent(&file)) {
          file.close();
          return;
      }
      file.close();
      
      QTreeWidgetItem *TWI_root = new QTreeWidgetItem(ui->treeWidget);
      TWI_root->setText(0, QFileInfo(filePath).fileName());
      TWI_root->setIcon(0, QIcon::fromTheme("application-gpx+xml", QIcon(":/icon.png")));
      
      QDomElement root = doc.documentElement();
      QDomNodeList DNL = root.elementsByTagName("trkpt");
      QPainterPath PP;
      for (int i=0; i<DNL.count(); i++) {
          QDomNode DN = DNL.at(i);
          if (DN.isElement()) {
              QDomElement DE = DN.toElement();
              qreal lon = DE.attribute("lon").toDouble();
              qreal lat = DE.attribute("lat").toDouble();
              QTreeWidgetItem *TWI_point = new QTreeWidgetItem(TWI_root);
              TWI_point->setText(0, QString("%1").arg(lon, 0, 'f', 14) + "," + QString("%1").arg(lat, 0, 'f', 14));
              TWI_point->setIcon(0, QIcon(":/marker.png"));
              QGraphicsEllipseItem *GEI = new QGraphicsEllipseItem(lon, lat, 5, 5);
              GEI->setFlags(QGraphicsItem::ItemIsSelectable);
              scene->addItem(GEI);
              if (i == 0)
                  PP.moveTo(lon, lat);
              else
                  PP.lineTo(lon, lat);
          }
      }
      QPen pen(Qt::blue, 1);
      QGraphicsPathItem *GPI = scene->addPath(PP, pen);
      GPI->setFlags(QGraphicsItem::ItemIsSelectable);
      
      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @sonichy

      Hi,

      do you want to translate your lat / long value to coordinates (x, y values) of your scene?

      https://stackoverflow.com/questions/14034455/translating-lat-long-to-actual-screen-x-y-coordinates-on-a-equirectangular-map


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      sonichyS 1 Reply Last reply
      2
      • Pl45m4P Pl45m4

        @sonichy

        Hi,

        do you want to translate your lat / long value to coordinates (x, y values) of your scene?

        https://stackoverflow.com/questions/14034455/translating-lat-long-to-actual-screen-x-y-coordinates-on-a-equirectangular-map

        sonichyS Offline
        sonichyS Offline
        sonichy
        wrote on last edited by
        #3

        @Pl45m4 The method is not fit.
        The key problem is the number is too small, I find another way : Differential Amplification. The shape is correct.

        QDomElement root = doc.documentElement();
        QDomNodeList DNL = root.elementsByTagName("trkpt");
        QPainterPath PP;
        qreal lonc=0, latc=0;
        for (int i=0; i<DNL.count(); i++) {
            QDomNode DN = DNL.at(i);
            if (DN.isElement()) {
                QDomElement DE = DN.toElement();
                qreal lon = DE.attribute("lon").toDouble();
                qreal lat = DE.attribute("lat").toDouble();
                if (i == 0) { // first point as reference point
                    lonc = lon;  
                    latc = lat;
                } else { // Differential then Amplification
                    qreal x = (lon - lonc) * 10000; 
                    qreal y = - (lat - latc) * 10000; // direction is opposite, add -
                    PP.lineTo(x, y);
                }
            }
        }
        QPen pen(Qt::blue, 1);
        QGraphicsPathItem *GPI = scene->addPath(PP, pen);
        GPI->setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable);
        

        替代文字

        https://github.com/sonichy

        1 Reply Last reply
        0
        • Kent-DorfmanK Offline
          Kent-DorfmanK Offline
          Kent-Dorfman
          wrote on last edited by Kent-Dorfman
          #4

          @sonichy said in How to change (longitude, latitude) to QGraphicsItem(x,y) ?:

          QGraphicsEllipseItem

          correctly projecting geographic coordinates onto a flat view widget is a whole lot more complicated than you are considering. You need to consider the shape of the reference spheroid and datum standard used in taking the original readings, then it's usually easiest to deal with calculations once they have been converted from arc-degrees to UTM, thus then allowing the use of the pythagorean theorem to calculate points. See great circle algorithm. You're mapping a curved surface onto a flat projection so you have to consider orthographic distortion also....lots involved in doing it correctly...look up gdal package to automate some of it.

          I light my way forward with the fires of all the bridges I've burned behind me.

          1 Reply Last reply
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved