Unsolved XML to map MapPolyline
-
Hello,
I have to draw Polyline from xml file and with 2 lines coordinate, I know how to do example
<ArpLat>43.587778</ArpLat>
<ArpLong>1.498611</ArpLong>But in some case , in the XML, I have a list of coordinates:
<Geometrie>50.132778,6.138056
50.138056,6.125556
50.145833,6.116111
50.155000,6.121944
50.161111,6.116944
50.166667,6.122500
50.172222,6.112500
50.172500,6.109722
50.174722,6.083056
50.164722,6.081111
50.160278,6.076944
50.157778,6.068611
50.157778,6.062778
50.162222,6.055278
50.162500,6.054167
50.166389,6.037500
50.170278,6.032222
50.183056,6.030000
50.184167,6.027222
50.185000,6.025556
50.184722,6.022222
50.184722,6.020278
50.177222,5.996111
50.176944,5.975000
50.171944,5.962500
50.159722,5.964444
50.158611,5.967500
50.153889,5.961944
50.134722,5.958333
50.125000,5.916944
50.120000,5.904722
50.112500,5.897222
50.104722,5.896389
50.097222,5.891944
50.091667,5.888611
50.083889,5.890833
50.079722,5.888889
50.076389,5.882500
50.076389,5.873333
50.069722,5.859444
50.063889,5.856111
50.059444,5.857222
50.051111,5.868889
50.047778,5.869167
50.038333,5.857778
50.034444,5.857778
50.024722,5.850278
50.016111,5.824444
50.013056,5.821111
50.002500,5.823333
50.000833,5.824722
50.000000,5.825278
49.994722,5.828889
49.994444,5.828889
49.990833,5.839722
49.981111,5.834444
49.979722,5.833889
49.975278,5.821111
49.974722,5.815278
49.972222,5.811389
49.967500,5.813333
49.963889,5.807222
49.965833,5.795556
49.964167,5.786389
49.960556,5.780278
49.949722,5.771944
49.941389,5.775556
49.934167,5.770556
49.930833,5.763056
49.917778,5.762778
49.915556,5.758611
49.910000,5.748889
49.899722,5.734444
49.892222,5.749167
49.891389,5.761944
49.887222,5.772222
49.880000,5.782222
49.878056,5.783611
49.875000,5.785278
49.873611,5.781667
49.871667,5.777222
49.871944,5.775000
49.872500,5.770000
49.873333,5.762222
49.873611,5.758611
49.873611,5.758056
49.871111,5.753611
49.861389,5.760556
49.856944,5.751111
49.850556,5.750833
49.844167,5.747778
49.840000,5.739722
49.837500,5.742500
49.831111,5.749722
49.818889,5.748889
49.814722,5.752500
49.795556,5.753889
49.797778,5.770556
49.796667,5.781389
49.801111,5.788889
49.763889,5.814722
49.756111,5.820000
49.753333,5.824444
49.749444,5.831111
49.743889,5.831667
49.733889,5.828056
49.728333,5.829722
49.724167,5.845833
49.728611,5.857500
49.728611,5.865278
49.726111,5.872500
49.711667,5.886667
49.710556,5.887500
49.698611,5.867500
49.687222,5.864444
49.679722,5.860278
49.679167,5.859722
49.669444,5.900000
49.665278,5.910000
49.663889,5.907222
49.657778,5.905000
49.656667,5.904444
49.653889,5.902778
49.645000,5.905556
49.641667,5.905833
49.638333,5.900000
49.636667,5.889444
49.636389,5.886944
49.631389,5.887222
49.629722,5.885556
49.620556,5.876111
49.608056,5.876111
49.600000,5.853611
49.597778,5.852500
49.588889,5.855278
49.589722,5.867500
49.588611,5.873611
49.582222,5.869167
49.576389,5.874444
49.571667,5.865278
49.561944,5.846389
49.559722,5.842222
49.556944,5.836944
49.551389,5.825833
49.546667,5.816667</Geometrie>Do you know how can I split this list to an acceptable format for MapPolyline path?..
thank a lot
-
@filipdns
So you have to split that text yourself into the pairs of coordinates, which you will then pass to your "polyline" function call(s).Whatever XML parser you use, you will come across an element whose name is
Geometrie
and whose value is the text. I forget whether you get that directly as the child, of whether the child is itself a text node with that value, but it's one or the other, can't be difficult for you to discover which.Then you need to split the text. The parser may have retained the newlines you show, but I wouldn't bet on it --- it may have joined them with a space separator. But either way you can split into original "lines" by splitting on whitespace in your case, fortunately. Then obviously you split each line on comma to get the two coordinates out.
-
@JonB Thank you very much.
To be sure I understand correctly, the pair of coordinates can be like 49.631389,5.887222 or the format has to be different?
what is the format for multiple pairs of coordinates?
I don't found any information in documentation about path format
-
@filipdns
Bear in mind: I don't use QML (or, for that matter, whatever your "Polyline" is)!I don't know now what you're expecting, but I'm expecting you to have to write some code to read in that XML as an external file, parse it, and make calls to whatever the polyline drawer function is, all in Qt/C++. I thought that was what your question title was asking.
In which case, you will have to convert those individual coordinate strings to
float
/double
/whatever Qt type is suitable, and then pass those to the "polyline draw" function. That will accept them as numbers, so "format" will not be an issue.However, if you are expecting more of an answer like "you can just do such-and-such [perhaps in a QML file] from QML and it will draw the polyline for you itself directly from the
<Geometrie>
content, you don't need to write any code yourself" then I am not your guy. Perhaps you should wait a bit in case someone else knows better than what I am suggesting. -
@JonB I had made the code to read the XML already and I got the long list in Geometrie. Usually, I receive for each segment 4 lines : 2 lines for lat et 2 other for long, but here they put lot of pairs, there is my problem. In QML with pairs of coordinates I do:
Map { MapPolygon { color: 'green' path: [ { latitude:49.559722,longitude:5.842222}, { latitude:49.556944,longitude:5.836944}, { latitude:49.551389,longitude:5.825833}, ... ] } }
but for the list of coordinates, I don't know how to format theme.
Example in GeoJson it's look like:
paths:[ [49.559722,5.842222], [49.556944,5.836944], [49.551389,5.825833], ... ]
that is why I talk about format
-
@JonB I just found the page http://doc.qt.io/qt-5/qml-coordinate.html:
and coordinates can be like:
import QtPositioning 5.2 Location { coordinate: QtPositioning.coordinate(-27.5, 153.1) }
I will try that tomorrow morning ;-)
-
Hello,
Here my first working attempt to use coordinates to build MapPolylines
import QtQuick 2.7 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.0 import QtQuick.XmlListModel 2.0 import QtLocation 5.10 import QtPositioning 5.10 ApplicationWindow { visible: true width: 1280 height: 1024 XmlListModel { id: assetsPolylineList source: "file:///E:/test.xml" query: "/SiaExport/Situation/BordureS/Bordure/Geometrie" property bool ready: false XmlRole { name: "country"; query: "string()" } onStatusChanged: { ready = (status == XmlListModel.Ready) //switch (status) { //case XmlListModel.Ready:console.log("[READY] '" + source + "' | " + count + " items"); //case XmlListModel.Error:console.log("[ERROR] '" + source + "' | Error: ''" + errorString() + "'"); //case XmlListModel.Loading:console.log("[LOADING] '" + source + "'") //} if(ready) { for (var i=0;i<count;i++) { var second=assetsPolylineList.get(i).country for(var j=0;(second.length)>1;j++) { var k = second.length var third=second.replace("\n",";") var forth= third.split(";") var forth1= forth[0] var forth2= forth[1] if(String(forth2)!=='undefined') {second=forth2} else{second="0"} var lat_long=forth1.split(",") var latitude =lat_long[0] var longitude =lat_long[1] var fith=QtPositioning.coordinate(latitude, longitude) if(i==0) {assetsPolyline0.addCoordinate(fith)} if(i==1) {assetsPolyline1.addCoordinate(fith)} if(i==2) {assetsPolyline2.addCoordinate(fith)} if(i==3) {assetsPolyline3.addCoordinate(fith)} if(i==4) {assetsPolyline4.addCoordinate(fith)} if(i==5) {assetsPolyline5.addCoordinate(fith)} if(i==6) {assetsPolyline6.addCoordinate(fith)} if(i==7) {assetsPolyline7.addCoordinate(fith)} if(i==8) {assetsPolyline8.addCoordinate(fith)} if(i==9) {assetsPolyline9.addCoordinate(fith)} if(i==10) {assetsPolyline10.addCoordinate(fith)} if(i==11) {assetsPolyline11.addCoordinate(fith)} if(i==12) {assetsPolyline12.addCoordinate(fith)} if(i==13) {assetsPolyline13.addCoordinate(fith)} if(i==14) {assetsPolyline14.addCoordinate(fith)} if(i==15) {assetsPolyline15.addCoordinate(fith)} if(i==16) {assetsPolyline16.addCoordinate(fith)} if(i==17) {assetsPolyline17.addCoordinate(fith)} if(i==18) {assetsPolyline18.addCoordinate(fith)} if(i==19) {assetsPolyline19.addCoordinate(fith)} if(i==20) {assetsPolyline20.addCoordinate(fith)} if(i==21) {assetsPolyline21.addCoordinate(fith)} if(i==22) {assetsPolyline22.addCoordinate(fith)} if(i==23) {assetsPolyline23.addCoordinate(fith)} if(i==24) {assetsPolyline24.addCoordinate(fith)} if(i==25) {assetsPolyline25.addCoordinate(fith)} if(i==26) {assetsPolyline26.addCoordinate(fith)} if(i==27) {assetsPolyline27.addCoordinate(fith)} if(i==28) {assetsPolyline28.addCoordinate(fith)} if(i==29) {assetsPolyline29.addCoordinate(fith)} if(i==30) {assetsPolyline30.addCoordinate(fith)} if(i==31) {assetsPolyline31.addCoordinate(fith)} if(i==32) {assetsPolyline32.addCoordinate(fith)} if(i==33) {assetsPolyline33.addCoordinate(fith)} if(i==34) {assetsPolyline34.addCoordinate(fith)} if(i==35) {assetsPolyline35.addCoordinate(fith)} if(i==36) {assetsPolyline36.addCoordinate(fith)} if(i==37) {assetsPolyline37.addCoordinate(fith)} if(i==38) {assetsPolyline38.addCoordinate(fith)} if(i==39) {assetsPolyline39.addCoordinate(fith)} if(i==40) {assetsPolyline40.addCoordinate(fith)} } } } } } Plugin { id: mapPlugin name: "esri" // "mapboxgl", "esri", "osm"... } Map { id:map anchors.fill: parent plugin: mapPlugin MapPolyline { id:assetsPolyline0 } MapPolyline { id:assetsPolyline1 } MapPolyline { id:assetsPolyline2 } MapPolyline { id:assetsPolyline3 } MapPolyline { id:assetsPolyline4 } MapPolyline { id:assetsPolyline5 } MapPolyline { id:assetsPolyline6 } MapPolyline { id:assetsPolyline7 } MapPolyline { id:assetsPolyline8 } MapPolyline { id:assetsPolyline9 } MapPolyline { id:assetsPolyline10 } MapPolyline { id:assetsPolyline11 } MapPolyline { id:assetsPolyline12 } MapPolyline { id:assetsPolyline13 } MapPolyline { id:assetsPolyline14 } MapPolyline { id:assetsPolyline15 } MapPolyline { id:assetsPolyline16 } MapPolyline { id:assetsPolyline17 } MapPolyline { id:assetsPolyline18 } MapPolyline { id:assetsPolyline19 } MapPolyline { id:assetsPolyline20 } MapPolyline { id:assetsPolyline21 } MapPolyline { id:assetsPolyline22 } MapPolyline { id:assetsPolyline23 } MapPolyline { id:assetsPolyline24 } MapPolyline { id:assetsPolyline25 } MapPolyline { id:assetsPolyline26 } MapPolyline { id:assetsPolyline27 } MapPolyline { id:assetsPolyline28 } MapPolyline { id:assetsPolyline29 } MapPolyline { id:assetsPolyline30 } MapPolyline { id:assetsPolyline31 } MapPolyline { id:assetsPolyline32 } MapPolyline { id:assetsPolyline33 } MapPolyline { id:assetsPolyline34 } MapPolyline { id:assetsPolyline35 } MapPolyline { id:assetsPolyline36 } MapPolyline { id:assetsPolyline37 } MapPolyline { id:assetsPolyline38 } MapPolyline { id:assetsPolyline39 } MapPolyline { id:assetsPolyline40 } } }
Now I have to found how to replace
if(i==0) {assetsPolyline0.addCoordinate(fith)} ... Map { id:map anchors.fill: parent plugin: mapPlugin MapPolyline { id:assetsPolyline0 } ... }
by something like :
// NON WORKING EXAMPLE/// if(ready) { for (var i=0;i<count;i++) { var second=assetsPolylineList.get(i).country for(var j=0;(second.length)>1;j++) { var k = second.length var third=second.replace("\n",";") var forth= third.split(";") var forth1= forth[0] var forth2= forth[1] if(String(forth2)!=='undefined') {second=forth2} else{second="0"} var lat_long=forth1.split(",") var latitude =lat_long[0] var longitude =lat_long[1] var fith= Qt.createQmlObject('Import QtQuick 1.1, MapPolyLine{path:QtPositioning.coordinate(latitude, longitude)',map,main.qml) } } } } }
Because on my first working attempt I know I have 40 polylines but for other items in my xml, I will have much more and I would like to have them automatically created, I don't know if I'm clear enough lol