Auf dieser Seite

GeoJsonData QML Type

Ein Modell zum Darstellen, Laden und Speichern von GeoJSON-Dokumenten. Mehr...

Import Statement: import QtLocation 6.12
Since: QtLocation 6.7

Eigenschaften

Methoden

Ausführliche Beschreibung

Der Typ „GeoJsonData“ liest und schreibt Dokumente im GeoJSON-Format. „GeoJsonData“ verfügt über Funktionen zum Öffnen und Speichern des Modells unter der URL, die in der Eigenschaft „ sourceUrl “ festgelegt ist. Das geladene Modell wird intern durch „ QVariant “ dargestellt und ist an die Eigenschaft „ model “ gebunden. Verwenden Sie Delegaten, um die Elemente in einer Ansicht darzustellen.

Informationen zu 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 der folgenden Typen entsprechen:

  • Point
  • MultiPoint
  • LineString
  • MultiLineString
  • Polygon
  • MultiPolygon
  • GeometryCollection
  • Feature
  • FeatureCollection

Um den Typ festzulegen, binden Sie das Element „ type “ an einen GeoJSON-Typ. Das Element „ coordinates “ kann je nach GeoJSON-Typ ein Typ vom Typ „ QGeoShape “ oder eine Liste sein. Der Typ „ Feature “ verfügt über die zusätzlichen Elemente „ geometry “ und „ properties “.

Eine Liste der geometrischen Typen und ihrer entsprechenden „ QVariant “-Darstellungen:

  • Bei einem „ Point “-Objekt entspricht „ coordinates “ dem „ QGeoCircle “. 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 „ LineString “-Objekt entspricht „ coordinates “ dem Objekt „ QGeoPath “. Beispiel:
    {
        "type" : "LineString",
        "coordinates" : [
        [13.5, 43],
        [10.73, 59.92]
        ]
    }

    Dieses GeoJSON-Objekt hat eine entsprechende Darstellung im QVariantMap -Format:

    {
        type : "LineString"
        data : QGeoPath([{43.000, 13.500}, {59.920, 10.730}])
    }
  • Bei einem „ Polygon “-Objekt ist das Element „ coordinates “ mit „ QGeoPolygon “ verknüpft (Lücken sind möglich). Das Polygon ist ein linearer Ring, dessen letzte Koordinate mit der ersten Koordinate übereinstimmt, wodurch der Ring geöffnet und geschlossen wird. Das Element „ bbox “ ist optional und dient zur Festlegung des Bereichs der Fläche, was bei konkaven Grenzen nützlich ist. Weitere Informationen zu den zulässigen Polygonkoordinaten finden Sie im Abschnitt zum Typ „Polygon“ in der GeoJSON-Spezifikation. 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 Darstellung im Format „ QVariantMap “:

    {
        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 “ wird „ coordinates “ mit einem „ QVariantList “ gepaart. Das Listenelement ist ein „ QVariantMap “, das Geometrie enthält.

  • Bei einem „ MultiPoint “-Objekt wird „ coordinates “ mit einer Liste von „Point“-Koordinaten gepaart. 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)
            }
            ]
    }
  • Bei einem „ MultiLineString “-Objekt wird „ coordinates “ mit einer Liste von „LineString“-Koordinaten gepaart. Das folgende GeoJSON-Objekt bildet 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 Darstellung im Format „ QVariantMap “:

    {
        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}])
            }
        ]
    }
  • Bei einem „ MultiPolygon “-Typ wird „ coordinates “ mit einer Liste von „Polygon“-Koordinaten gepaart. Das Polygon ist ein linearer Ring; weitere Informationen zu den zulässigen Formaten finden Sie unter dem Typ „ Polygon “. Das folgende GeoJSON-Objekt enthält eine Liste mit 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 Zusammensetzung aus anderen Geometrietypen. Der Wert des Elements „ geometries “ ist eine „ QVariantList “, die „QVariantMaps“ verschiedener Typen enthält, darunter auch andere „GeometryCollection“-Typen.

Beispielsweise enthält der folgende Typ „ GeometryCollection “ 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 zusätzlich die Elemente „ geometry “ und „ properties “. Die einzige Möglichkeit, ein „Feature“-Objekt von anderen geometrischen Objekten zu unterscheiden, besteht darin, zu prüfen, ob im „ QVariantMap “-Objekt ein Knoten vom Typ „ properties “ vorhanden ist.

Beispielsweise verfügt das folgende „ Feature “-Objekt über die Elemente „geometry“ und „properties“:

{
    "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 Darstellung als „ QVariantMap “:

{
  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 Zusammensetzung aus „Feature“-Objekten. Das Element „ features “ ist mit einem „ QVariantList “-Objekt verknüpft, das weitere „Feature“-Objekte enthält.

Beispielsweise enthält 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 verfügt über eine entsprechende Darstellung im Format „ QVariantMap “:

{
    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 Beispiel „GeoJSON-Viewer“ veranschaulicht die Verwendung des QML-Typs „GeoJsonData“ zum Laden und Visualisieren von Koordinaten auf einer Karte.

Dokumentation zu den Eigenschaften

model : QVariant [since 6.7]

Eine „ QVariant “-Darstellung des GeoJSON-Dokuments. QML-Delegaten können den Inhalt in Ansichten anzeigen.

Diese Eigenschaft wurde in Qt 6.7 eingeführt.

sourceUrl : url [since 6.7]

Die URL eines GeoJSON-Dokuments. Durch das Festlegen dieser Eigenschaft wird das Dokument geladen und das Objekt an das Mitglied „ model “ gebunden.

Diese Eigenschaft wurde in Qt 6.7 eingeführt.

Methodendokumentation

bool addItem(Item item)

Fügt das Objekt „ item “ zum Objekt „ model “ hinzu.

Gibt bei erfolgreichem Hinzufügen „ true “ zurück, andernfalls „ false “.

void clear()

Löscht alle Elemente, die mit dem „ model “ verknüpft sind.

bool open()

Lädt den Inhalt der Datei unter sourceUrl.

Gibt „ true “ zurück, wenn das Öffnen erfolgreich war, andernfalls „ false “.

bool openUrl(Url url)

Lädt das GeoJSON-Dokument unter url und bindet es an die model. Die Eigenschaft sourceUrl wird auf url gesetzt, wenn das Öffnen der Datei erfolgreich war.

Gibt „ true “ zurück, wenn das Öffnen erfolgreich war, andernfalls „ false “.

bool save()

Speichert das Modell unter sourceUrl.

Gibt bei erfolgreichem Speichern „ true “ zurück, andernfalls „ false “.

bool saveAs(Url url)

Speichert die Datei „ model “ unter „ url “. Die Eigenschaft „ sourceUrl “ wird bei Erfolg auf „ url “ gesetzt.

Gibt „ true “ zurück, wenn das Speichern erfolgreich war, andernfalls „ false “.

void setModelToMapContents(MapView mapItemView)

Fügt alle Map-Elemente von mapItemView zur model des GeoJsonData -Objekts hinzu. Löscht zuvor gespeicherte Map-Elemente aus der model.

Gibt „ true “ zurück, wenn die Einstellung erfolgreich war, andernfalls „ false “.

Siehe auch „ addItem “.

© 2026 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.