GeoJsonData QML Type
Ein Modell zum Darstellen, Laden und Speichern von GeoJSON-Dokumenten. Mehr...
| Import Statement: | import QtLocation 6.10 |
| Since: | QtLocation 6.7 |
- Liste aller Mitglieder, einschließlich geerbter Mitglieder
- GeoJsonData ist Teil des QML Maps Plugin.
Eigenschaften
Methoden
- bool addItem(Item item)
- void clear()
- bool open()
- bool openUrl(Url url)
- bool save()
- bool saveAs(Url url)
- void setModelToMapContents(MapView mapItemView)
Detaillierte Beschreibung
Der GeoJsonData-Typ liest und schreibt GeoJson formatierte Dokumente. GeoJsonData verfügt über Funktionen zum Öffnen und Speichern des Modells unter der in der Eigenschaft sourceUrl festgelegten URL. Das geladene Modell wird intern durch QVariant dargestellt und ist an die Eigenschaft model gebunden. Verwenden Sie Delegates, um die Elemente in einer Ansicht zu visualisieren.
Informationen über GeoJSON finden Sie auf der GeoJSON-Website.
GeoJSON-Objekt
Das GeoJSON-Objekt ist ein gültiges JSON-Objekt, das eine Geometrie, ein Feature oder eine Sammlung von Geometrien oder Features darstellt.
Ein GeoJSON-Objekt muss einem dieser Typen angehören:
PointMultiPointLineStringMultiLineStringPolygonMultiPolygonGeometryCollectionFeatureFeatureCollection
Um den Typ festzulegen, binden Sie das Mitglied type an einen GeoJSON-Typ. Der Member coordinates kann je nach GeoJSON-Typ ein Typ von QGeoShape oder eine Liste sein. Der Typ Feature hat ein zusätzliches geometry und properties Mitglied.
Eine Liste der geometrischen Typen und ihrer äquivalenten QVariant Repräsentationen:
- Für ein
PointObjekt,coordinatesPaare mit QGeoCircle. Zum Beispiel:{ "type": "Point", "coordinates": [11, 60] }Dieses GeoJSON-Objekt hat eine entsprechende QVariantMap Darstellung:
{ type: "Point" coordinates: QGeoCircle({11.000, 60.000}, -1) } - Für ein
LineStringObjekt,coordinatespaart sich mit QGeoPath. Zum Beispiel:{ "type" : "LineString", "coordinates" : [ [13.5, 43], [10.73, 59.92] ] }Dieses GeoJSON-Objekt hat eine entsprechende QVariantMap Darstellung:
{ type : "LineString" data : QGeoPath([{43.000, 13.500}, {59.920, 10.730}]) } - Für ein
PolygonObjekt,coordinatesMitgliedspaare mit QGeoPolygon (Löcher sind möglich). Das Polygon ist ein linearer Ring, dessen Endkoordinate mit der ersten Koordinate übereinstimmt, wodurch der Ring geöffnet und geschlossen wird. Das Elementbboxist ein optionales Element, mit dem der Bereich des Polygons festgelegt werden kann, was für konkave Begrenzungen nützlich ist. Weitere Informationen über die akzeptierten Polygonkoordinaten finden Sie in der GeoJson-Spezifikation zum Typ Polygon. Zum Beispiel:{ "type": "Polygon", "coordinates": [ [ [17.13, 51.11], [30.54, 50.42], [26.70, 58.36], [17.13, 51.11] ] ], "bbox": [50, -50, 10, -10] }Dieses GeoJSON-Objekt hat eine entsprechende QVariantMap Darstellung:
{ type : "Polygon" coordinates : QGeoPolygon([{51.110, 17.130}, {50.420,30.540}, {58.360, 26.700}, {51.110, 17.130}]) }
Bei den Typen MultiPoint, MultiLineString und MultiPolygon ist coordinates ein Paar mit QVariantList. Das Listenelement ist ein QVariantMap, das Geometrie enthält.
- Für ein
MultiPointObjekt,coordinatesPaare mit einer Liste von Punktkoordinaten. Zum Beispiel:{ "type": "MultiPoint", "coordinates": [ [11, 60], [5.5, 60.3], [5.7, 58.90] ] }Dieses GeoJSON-Objekt hat eine entsprechende QVariantMap Darstellung:
{ type : "MultiPoint" coordinates : [ { type : "Point" coordinates : QGeoCircle({60.000, 11.000}, -1) }, { type : "Point" coordinates : QGeoCircle({60.300, 5.500}, -1) }, { type : "Point" coordinates : QGeoCircle({58.900, 5.700}, -1) } ] } - Für ein
MultiLineStringObjekt,coordinatesPaare mit einer Liste von LineString Koordinaten. Das folgende GeoJSON-Objekt konstruiert zwei nicht-parallele Linien:{ "type" : "MultiLineString", "coordinates" : [ [[13.5, 43], [10.73, 59.92]], [[9.15, 45], [-3.15, 58.90]] ] }Dieses GeoJSON-Objekt hat eine entsprechende QVariantMap Darstellung:
{ type : "MultiLineString" coordinates : [ { type : "LineString" coordinates : QGeoPath([{45.000, 9.150}, {58.900, -3.150}]) }, { type : "LineString" coordinates : QGeoPath([{43.000, 13.500}, {59.920, 10.730}]) } ] } - Für den Typ
MultiPolygonpaart sichcoordinatesmit einer Liste von Polygonkoordinaten. Das Polygon ist ein linearer Ring und der TypPolygonenthält weitere Informationen über akzeptierte Formate. Das folgende GeoJSON-Objekt enthält eine Liste von zwei Dreiecken:{ "type" : "MultiPolygon", "coordinates" : [ [ [[17.13, 51.11], [30.54, 50.42], [26.74, 58.36], [17.13, 51.11] ]], [ [[19.84, 41.33], [30.45, 49.26], [17.07, 50.10], [19.84, 41.33] ]] ] }Dieses GeoJSON-Objekt hat eine entsprechende QVariantMap Darstellung:
{ type : "MultiPolygon" coordinates : [ { type : "Polygon" coordinates : QGeoPolygon([{51.110, 17.130}, {50.420,30.540}, {58.360, 26.740}]) }, { type : "Polygon" coordinates : QGeoPolygon([{41.330, 19.840}, {49.260,30.450}, {50.100, 17.070}]) } ] }
Der Typ GeometryCollection ist eine Komposition aus anderen Geometrietypen. Der Wert des Elements geometries ist eine QVariantList, die QVariantMaps verschiedener Typen enthält, einschließlich anderer GeometryCollection-Typen.
Zum Beispiel enthält der folgende GeometryCollection Typ mehrere andere Geometrien:
{
"type" : "GeometryCollection",
"geometries" : [
{
"type" : "MultiPoint",
"coordinates" : [
[11,60], [5.5,60.3], [5.7,58.90]
]
},
{
"type" : "MultiLineString",
"coordinates": [
[[13.5, 43], [10.73, 59.92]],
[[9.15, 45], [-3.15, 58.90]]
]
},
{
"type" : "MultiPolygon",
"coordinates" : [
[
[
[17.13, 51.11],
[30.54, 50.42],
[26.74, 58.36],
[17.13, 51.11]
]
],
[
[
[19.84, 41.33],
[30.45, 49.26],
[17.07, 50.10],
[19.84, 41.33]
]
]
]
}
]
}Dieses GeoJSON-Objekt hat eine entsprechende QVariantMap Darstellung:
{
type : "GeometryCollection"
coordinates : [
{
type : "MultiPolygon"
coordinates : [
{
type : "Polygon"
coordinates : QGeoPolygon([{41.330, 19.840}, {49.260, 30.450}, {50.100, 17.070}])
},
{
type : "Polygon"
coordinates : QGeoPolygon([{51.110, 17.130}, {50.420, 30.540}, {58.360, 26.740}])
}
]
}
{
type : "MultiLineString"
coordinates : [
{
type : "LineString"
coordinates : QGeoPath([{45.000, 9.150}, {58.900, -3.150}])
},
{
type : "LineString"
coordinates : QGeoPath([{43.000, 13.500}, {59.920, 10.730}])
}
]
}
{
type : "MultiPoint"
coordinates : [
{
type : Point
coordinates : QGeoCircle({58.900, 5.700}, -1)
},
{
type : Point
coordinates : QGeoCircle({60.300, 5.500}, -1)
},
{
type : Point
coordinates : QGeoCircle({60.000, 11.000}, -1)
}
]
}
]
}Der Typ Feature enthält ein zusätzliches geometry und properties Mitglied. Die einzige Möglichkeit, ein Feature-Objekt von anderen geometrischen Objekten zu unterscheiden, besteht darin, das Vorhandensein eines properties -Knotens im QVariantMap -Objekt zu überprüfen.
Zum Beispiel hat das folgende Feature eine Geometrie und Eigenschaften:
{
"type": "Feature",
"id": "Poly",
"properties": {
"name": "Poly",
"text": "This is a Feature with a Polygon",
"color": "limegreen"
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[17.13, 51.11],
[30.54, 50.42],
[26.70, 58.36],
[17.13, 51.11]
],
[
[23.46, 54.36],
[20.52, 51.91],
[28.25, 51.50],
[26.80, 54.36],
[23.46, 54.36]
]
]
}
}Dieses GeoJSON-Objekt hat eine entsprechende QVariantMap Darstellung:
{
type : "Polygon"
data : QGeoPolygon([{51.110, 17.130}, {50.420,30.540}, {58.360, 26.700}, {51.110, 17.130}])
properties : {text : "This is a Feature with a Polygon"}
}Das FeatureCollection ist eine Komposition von Feature-Objekten. Das Mitglied features bindet sich an ein QVariantList Objekt, das andere Feature-Objekte enthält.
Zum Beispiel hat das folgende FeatureCollection mehrere Features und Geometrien:
{
"type" : "FeatureCollection",
"properties" : {
"color" : "crimson"
},
"features" : [
{
"type" : "Feature",
"id" : "Poly",
"properties" : {
"text" : "This is a Feature with a Polygon"
},
"geometry" : {
"type" : "Polygon",
"coordinates" : [
[
[17.13, 51.11],
[30.54, 50.42],
[26.70, 58.36],
[17.13, 51.11]
],
[
[23.46, 54.36],
[20.52, 51.91],
[28.25, 51.50],
[26.80, 54.36],
[23.46, 54.36]
]
]
}
},
{
"type" : "Feature",
"id" : "MultiLine",
"properties" : {
"text" : "This is a Feature with a MultiLineString",
"color" : "deepskyblue"
},
"geometry" : {
"type" : "MultiLineString",
"coordinates" : [
[[13.5, 43], [10.73, 59.92]],
[[9.15, 45], [-3.15, 58.90]]
]
}
}
]
}Dieses GeoJSON-Objekt hat eine entsprechende QVariantMap Darstellung:
{
type: "FeatureCollection"
data: [{
type: "MultiLineString"
data: [{
type: "LineString"
data: QGeoPath( [{45.000, 9.150}, {58.900, -3.150}] )
} {
type: "LineString"
data: QGeoPath( [{43.000, 13.500}, {59.920, 10.730}] )
}]
properties: { text: "This is a Feature with a MultiLineString" }
},
{
type: "Polygon"
data: QGeoPolygon( {51.110, 17.130},
{50.420, 30.540},
{58.360, 26.700},
{51.110, 17.130}
)
properties: { text: "This is a Feature with a Polygon" }
}
]
}GeoJson Beispiel
Das GeoJson Viewer Beispiel demonstriert die Verwendung des GeoJsonData QML-Typs zum Laden und Visualisieren von Koordinaten auf einer Karte.
Dokumentation der Eigenschaften
model : QVariant |
Eine QVariant Darstellung des GeoJSON-Dokuments. QML-Delegierte können den Inhalt in Ansichten anzeigen.
Diese Eigenschaft wurde in Qt 6.7 eingeführt.
sourceUrl : url |
Die URL eines GeoJSON-Dokuments. Das Setzen dieser Eigenschaft lädt das Dokument und bindet das Objekt an das Mitglied model.
Diese Eigenschaft wurde in Qt 6.7 eingeführt.
Methode Dokumentation
Fügt das Objekt item zum Objekt model hinzu.
Gibt true zurück, wenn das Hinzufügen erfolgreich war, andernfalls false.
void clear() |
Löscht alle Elemente, die an das model gebunden sind.
bool open() |
Lädt den Inhalt der Datei unter sourceUrl.
Gibt true zurück, wenn das Öffnen erfolgreich war, andernfalls false.
bool save() |
Speichert das Modell unter sourceUrl.
Gibt true zurück, wenn das Speichern erfolgreich war, andernfalls false.
void setModelToMapContents(MapView mapItemView) |
Fügt alle Kartenelemente von mapItemView zu model des Objekts GeoJsonData hinzu. Löscht zuvor gespeicherte Map-Elemente aus dem model.
Gibt true zurück, wenn das Setzen erfolgreich war, andernfalls false.
Siehe auch addItem.
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.