Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Extract Coordinates from File and add them to a Map Polygon

Extract Coordinates from File and add them to a Map Polygon

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 1.1k Views
  • 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.
  • D Offline
    D Offline
    deleted122
    wrote on last edited by
    #1

    Hello there,
    i got some problems with the QMapPolygon.
    I add coordinates manually (using a mouse area) this works fine (i can see the Polygon), i then give these coordinates to cpp and save them to a file. Fine this works smoothly too, but if i want to load these coordinates from the file, give them to QML and add them to the MapPolygon i got some problems.
    I am using QMap to display the map and the map plugin from here maps
    I hope you can help me

    My .txt file with the coordinates looks like this:
    48° 11' 49.7" N, 10° 22' 43.2" E
    48° 1' 55.6" N, 11° 3' 55.1" E
    48° 17' 58.4" N, 11° 1' 16.9" E
    48° 44' 49.4" N, 10° 40' 11.3" E
    48° 49' 10.0" N, 10° 18' 45.9" E
    48° 37' 12.5" N, 10° 5' 15.1" E
    48° 18' 51.0" N, 10° 5' 34.8" E

    The relevant code in Cpp:

    /void Coords::getfromFile()
    {
        QFile file("out.txt");
        file.open(QIODevice::ReadOnly | QIODevice::Text);
        QTextStream out(&file);
        QString text;
        liste.clear();
        while ( !out.atEnd() )
        {
        text = out.readLine();
        liste.append(text);               //liste is  QList<QString> liste
        }
        file.close();
        if(liste.isEmpty()==true)
        {
            qDebug() << "Error File empty";
        }
        emit getfromSignal(liste,liste.length());
    }
    

    The relevant QML part:

    Button{
                    id: loadPolygon
                    text: "Load Markers"
                    anchors.right: parent.right
                    anchors.top: savePolygon.bottom
                    onClicked:
                    {
                        coords.getfromFile()      //here the cpp function gets called
    
                    }
                }
    
                Connections {
                        id:cppConnection
                        target: coords
                        ignoreUnknownSignals: true
                        onSavetoSignal: {
                            savePolygon.visible = false
                        }
                        onGetfromSignal: {
                            var path = list     //list is the QList liste from cpp 
                            var i = 0
                            console.log(length)     //length is the liste.length() from cpp
    
                            for(i;i<(length-2);i++)
                            {
                                console.log(i)
                                console.log(path[i])
                                polygon.addCoordinate(path[i])
                            }
                            polygon.path = path
                            console.log(path[0])
                            console.log(path[1])
                            console.log(path[2])
                            polygon.visible = true
    
                        }
    

    The code compiles without errors but when i try to execute i always get some outputs from the console like this:
    qml: 7
    qml: 0
    qml: 48° 11' 49.7" N, 10° 22' 43.2" E
    qml: 1
    qml: 48° 1' 55.6" N, 11° 3' 55.1" E
    qml: 2
    qml: 48° 17' 58.4" N, 11° 1' 16.9" E
    qml: 3
    qml: 48° 44' 49.4" N, 10° 40' 11.3" E
    qml: 4
    qml: 48° 49' 10.0" N, 10° 18' 45.9" E
    qml: 48° 11' 49.7" N, 10° 22' 43.2" E
    qml: 48° 1' 55.6" N, 11° 3' 55.1" E
    qml: 48° 17' 58.4" N, 11° 1' 16.9" E
    QPainterPath::addRect: Adding rect where a parameter is NaN or Inf, ignoring call

    from then the console keeps logging
    QPainterPath::addRect: Adding rect where a parameter is NaN or Inf, ignoring call
    if i move the map or anything.

    You guys have any ideas what i should change?

    thanks guys.

    A 1 Reply Last reply
    0
    • D deleted122

      Hello there,
      i got some problems with the QMapPolygon.
      I add coordinates manually (using a mouse area) this works fine (i can see the Polygon), i then give these coordinates to cpp and save them to a file. Fine this works smoothly too, but if i want to load these coordinates from the file, give them to QML and add them to the MapPolygon i got some problems.
      I am using QMap to display the map and the map plugin from here maps
      I hope you can help me

      My .txt file with the coordinates looks like this:
      48° 11' 49.7" N, 10° 22' 43.2" E
      48° 1' 55.6" N, 11° 3' 55.1" E
      48° 17' 58.4" N, 11° 1' 16.9" E
      48° 44' 49.4" N, 10° 40' 11.3" E
      48° 49' 10.0" N, 10° 18' 45.9" E
      48° 37' 12.5" N, 10° 5' 15.1" E
      48° 18' 51.0" N, 10° 5' 34.8" E

      The relevant code in Cpp:

      /void Coords::getfromFile()
      {
          QFile file("out.txt");
          file.open(QIODevice::ReadOnly | QIODevice::Text);
          QTextStream out(&file);
          QString text;
          liste.clear();
          while ( !out.atEnd() )
          {
          text = out.readLine();
          liste.append(text);               //liste is  QList<QString> liste
          }
          file.close();
          if(liste.isEmpty()==true)
          {
              qDebug() << "Error File empty";
          }
          emit getfromSignal(liste,liste.length());
      }
      

      The relevant QML part:

      Button{
                      id: loadPolygon
                      text: "Load Markers"
                      anchors.right: parent.right
                      anchors.top: savePolygon.bottom
                      onClicked:
                      {
                          coords.getfromFile()      //here the cpp function gets called
      
                      }
                  }
      
                  Connections {
                          id:cppConnection
                          target: coords
                          ignoreUnknownSignals: true
                          onSavetoSignal: {
                              savePolygon.visible = false
                          }
                          onGetfromSignal: {
                              var path = list     //list is the QList liste from cpp 
                              var i = 0
                              console.log(length)     //length is the liste.length() from cpp
      
                              for(i;i<(length-2);i++)
                              {
                                  console.log(i)
                                  console.log(path[i])
                                  polygon.addCoordinate(path[i])
                              }
                              polygon.path = path
                              console.log(path[0])
                              console.log(path[1])
                              console.log(path[2])
                              polygon.visible = true
      
                          }
      

      The code compiles without errors but when i try to execute i always get some outputs from the console like this:
      qml: 7
      qml: 0
      qml: 48° 11' 49.7" N, 10° 22' 43.2" E
      qml: 1
      qml: 48° 1' 55.6" N, 11° 3' 55.1" E
      qml: 2
      qml: 48° 17' 58.4" N, 11° 1' 16.9" E
      qml: 3
      qml: 48° 44' 49.4" N, 10° 40' 11.3" E
      qml: 4
      qml: 48° 49' 10.0" N, 10° 18' 45.9" E
      qml: 48° 11' 49.7" N, 10° 22' 43.2" E
      qml: 48° 1' 55.6" N, 11° 3' 55.1" E
      qml: 48° 17' 58.4" N, 11° 1' 16.9" E
      QPainterPath::addRect: Adding rect where a parameter is NaN or Inf, ignoring call

      from then the console keeps logging
      QPainterPath::addRect: Adding rect where a parameter is NaN or Inf, ignoring call
      if i move the map or anything.

      You guys have any ideas what i should change?

      thanks guys.

      A Offline
      A Offline
      ambershark
      wrote on last edited by
      #2

      @Gigamens So I haven't used QML before (purely C++ side of Qt), but from what I looked at your coordinates from the file are not in a format that you can just pass into polygon.path.

      From the docs it looks like you need something like:

      Location {
          coordinate {
              latitude: -27.5
              longitude: 153.1
          }
      }
      

      There are no allowances that I can see for things like the degree symbol, or ' or ". Likewise I don't see any indicators for directions like N/E/etc. Those seem to be handled with negatives numbers.

      So my guess is you are feeding bad data into the path. Try using the input that it expects and save your files using those values.

      I may be totally off base here since I don't use QML though. ;)

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      1 Reply Last reply
      0

      • Login

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