how to use variable of QVariantList format
-
Good day to all!
I want to read the format file .geojson and manually apply graphical data from it to a map with an arbitrary cartographic projection.
I found the QGeoJson class in Qt, and following the example of geojson_viewer (Qt 5.15 -> location), I learned to read any geocoordinate file.
However, the example uses Qt Quick, which I do not understand, which did not allow me to understand exactly how the file data is decrypted in the example.geojson - I don't see polygon drawing operations in the graphics area (and, accordingly, I don't see the decrypted data that the drawing is based on).
Below I will give the code that I use to read the file.geojson. Using the debugger, I look at the variable modelList (see figure) and frankly do not understand how to get the coordinates of the corners of polygons from it. In addition to the fact that I have never encountered such complex data structures and do not understand how to get to the end of the chain to the final data, I also cannot see what lies there - Qt writes that the final field is "non-called" (what does it even mean?).
Could you tell me how to extract from a variable
modelList all coordinates of the polygon (and I have only polygons and multipolygons here)? The coordinates of any polygon will be enough - then I'll figure it out :)
I am grateful in advance for any help!int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QString file_path = QCoreApplication::applicationDirPath(); file_path += "/countries.geojson"; // Reading GeoJSON file QFile loadedFile(file_path); if (!loadedFile.open(QIODevice::ReadOnly)) { qWarning() << "Error while opening the file: " << file_path; qWarning() << loadedFile.error() << loadedFile.errorString(); return 1; } // Load the GeoJSON file using Qt's API QJsonParseError err; QJsonDocument loadDoc(QJsonDocument::fromJson(loadedFile.readAll(), &err)); if (err.error) { qWarning() << "Parsing while importing the JSON document:\n" << err.errorString(); return 2; } // Import geographic data to a QVariantList QVariantList modelList = QGeoJson::importGeoJson(loadDoc); return a.exec(); }
-
Good day to all!
I want to read the format file .geojson and manually apply graphical data from it to a map with an arbitrary cartographic projection.
I found the QGeoJson class in Qt, and following the example of geojson_viewer (Qt 5.15 -> location), I learned to read any geocoordinate file.
However, the example uses Qt Quick, which I do not understand, which did not allow me to understand exactly how the file data is decrypted in the example.geojson - I don't see polygon drawing operations in the graphics area (and, accordingly, I don't see the decrypted data that the drawing is based on).
Below I will give the code that I use to read the file.geojson. Using the debugger, I look at the variable modelList (see figure) and frankly do not understand how to get the coordinates of the corners of polygons from it. In addition to the fact that I have never encountered such complex data structures and do not understand how to get to the end of the chain to the final data, I also cannot see what lies there - Qt writes that the final field is "non-called" (what does it even mean?).
Could you tell me how to extract from a variable
modelList all coordinates of the polygon (and I have only polygons and multipolygons here)? The coordinates of any polygon will be enough - then I'll figure it out :)
I am grateful in advance for any help!int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QString file_path = QCoreApplication::applicationDirPath(); file_path += "/countries.geojson"; // Reading GeoJSON file QFile loadedFile(file_path); if (!loadedFile.open(QIODevice::ReadOnly)) { qWarning() << "Error while opening the file: " << file_path; qWarning() << loadedFile.error() << loadedFile.errorString(); return 1; } // Load the GeoJSON file using Qt's API QJsonParseError err; QJsonDocument loadDoc(QJsonDocument::fromJson(loadedFile.readAll(), &err)); if (err.error) { qWarning() << "Parsing while importing the JSON document:\n" << err.errorString(); return 2; } // Import geographic data to a QVariantList QVariantList modelList = QGeoJson::importGeoJson(loadDoc); return a.exec(); }
@RoApPr
If you are asking about the format/content of a GeoJson file itself you need to look at external specification documents.If you mean you want to see what is in the
QGeoJson::importGeoJson()
-returnedQVariantList
, you need to follow the description at https://doc.qt.io/qt-5/qgeojson.html#importing-geojson.The importer returns a
QVariantList
containing a singleQVariantMap
.Write some code to find that in the variant list and print its keys/values. If you are relying on the debugger window to be able to show you this I imagaine you will be disappointed.
-
@RoApPr
If you are asking about the format/content of a GeoJson file itself you need to look at external specification documents.If you mean you want to see what is in the
QGeoJson::importGeoJson()
-returnedQVariantList
, you need to follow the description at https://doc.qt.io/qt-5/qgeojson.html#importing-geojson.The importer returns a
QVariantList
containing a singleQVariantMap
.Write some code to find that in the variant list and print its keys/values. If you are relying on the debugger window to be able to show you this I imagaine you will be disappointed.
@JonB, thank you for your answer, but I mean more that I don't know how to access the required field - I tried a number of options, but I get either an error or an empty object.
I have given the image as an example of a real file that is being successfully read. I can't get a variable containing only information on "address" "modeList[0][0].value()[0][0].value()" (obviously, this is one of the incorrect access request forms, but, as I said earlier, I did not find the correct ones). -
@JonB, thank you for your answer, but I mean more that I don't know how to access the required field - I tried a number of options, but I get either an error or an empty object.
I have given the image as an example of a real file that is being successfully read. I can't get a variable containing only information on "address" "modeList[0][0].value()[0][0].value()" (obviously, this is one of the incorrect access request forms, but, as I said earlier, I did not find the correct ones).@RoApPr
I don't know what to say. You have to write code per the docs. Start by showing you found theQVariantMap
. Find how many elements it has, etc. Show code. And pretty obviously don't write code likemodeList[0][0].value()[0][0].value()
, pick out each item one at a time into intermediate variables so you can see how it goes.