GeoJsonData QML Type
Un modello per rappresentare, caricare e salvare documenti GeoJSON. Maggiori informazioni...
| Import Statement: | import QtLocation 6.12 |
| Since: | QtLocation 6.7 |
- Elenco di tutti i membri, compresi quelli ereditati
- GeoJsonData fa parte del plugin QML Maps.
Proprietà
Metodi
- bool addItem(Item item)
- void clear()
- bool open()
- bool openUrl(Url url)
- bool save()
- bool saveAs(Url url)
- void setModelToMapContents(MapView mapItemView)
Descrizione dettagliata
Il tipo GeoJsonData legge e scrive documenti in formato GeoJSON. GeoJsonData dispone di funzioni per aprire e salvare il modello all'URL specificato nella proprietà sourceUrl. Il modello caricato è rappresentato internamente da QVariant ed è associato alla proprietà model. Utilizzare i delegati per visualizzare gli elementi in una vista.
Per informazioni su GeoJSON, visitare il sito web di GeoJSON.
Oggetto GeoJSON
L'oggetto GeoJSON è un oggetto JSON valido che rappresenta una geometria, un elemento o una raccolta di geometrie o elementi.
Un oggetto GeoJSON deve essere di uno dei seguenti tipi:
PointMultiPointLineStringMultiLineStringPolygonMultiPolygonGeometryCollectionFeatureFeatureCollection
Per impostare il tipo, associare il membro ` type ` a un tipo GeoJSON. Il membro ` coordinates ` può essere un tipo di ` QGeoShape ` o un elenco, a seconda del tipo GeoJSON. Il tipo ` Feature ` dispone di un membro aggiuntivo ` geometry ` e ` properties `.
Elenco dei tipi geometrici e delle loro rappresentazioni equivalenti in QVariant:
- Per un oggetto
Point,coordinatesè associato a QGeoCircle. Ad esempio:{ "type": "Point", "coordinates": [11, 60] }Questo oggetto GeoJSON ha una rappresentazione QVariantMap corrispondente:
{ type: "Point" coordinates: QGeoCircle({11.000, 60.000}, -1) } - Per un oggetto
LineString,coordinatesè associato a QGeoPath. Ad esempio:{ "type" : "LineString", "coordinates" : [ [13.5, 43], [10.73, 59.92] ] }Questo oggetto GeoJSON ha una rappresentazione QVariantMap corrispondente:
{ type : "LineString" data : QGeoPath([{43.000, 13.500}, {59.920, 10.730}]) } - Per un oggetto
Polygon, il membrocoordinatesè associato a QGeoPolygon (sono possibili dei fori). Il poligono è un anello lineare, la cui coordinata finale è uguale alla prima coordinata, aprendo e chiudendo così l’anello. Il membrobboxè un membro opzionale e serve a impostare l’estensione dell’area, utile per i confini concavi. Per ulteriori informazioni sulle coordinate dei poligoni accettate, consultare la sezione relativa al tipo Polygon nelle specifiche GeoJSON. Ad esempio:{ "type": "Polygon", "coordinates": [ [ [17.13, 51.11], [30.54, 50.42], [26.70, 58.36], [17.13, 51.11] ] ], "bbox": [50, -50, 10, -10] }Questo oggetto GeoJSON ha una rappresentazione corrispondente in formato QVariantMap:
{ type : "Polygon" coordinates : QGeoPolygon([{51.110, 17.130}, {50.420,30.540}, {58.360, 26.700}, {51.110, 17.130}]) }
Per i tipi " MultiPoint", " MultiLineString" e " MultiPolygon ", una coppia " coordinates " è associata a un " QVariantList". L'elemento "list" è un " QVariantMap " contenente una geometria.
- Per un oggetto `
MultiPoint`, `coordinates` è associato a un elenco di coordinate `Point`. Ad esempio:{ "type": "MultiPoint", "coordinates": [ [11, 60], [5.5, 60.3], [5.7, 58.90] ] }Questo oggetto GeoJSON ha una rappresentazione corrispondente in QVariantMap:
{ 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) } ] } - Per un oggetto
MultiLineString,coordinatesè associato a un elenco di coordinate LineString. Il seguente oggetto GeoJSON definisce due linee non parallele:{ "type" : "MultiLineString", "coordinates" : [ [[13.5, 43], [10.73, 59.92]], [[9.15, 45], [-3.15, 58.90]] ] }Questo oggetto GeoJSON ha una rappresentazione QVariantMap corrispondente:
{ 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}]) } ] } - Per un tipo `
MultiPolygon`, `coordinates` è associato a un elenco di coordinate `Polygon`. Il poligono è un anello lineare e il tipo `Polygon` fornisce ulteriori informazioni sui formati accettati. Il seguente oggetto GeoJSON contiene un elenco di due triangoli:{ "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] ]] ] }Questo oggetto GeoJSON ha una corrispondente rappresentazione QVariantMap:
{ 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}]) } ] }
Il tipo ` GeometryCollection ` è una composizione di altri tipi geometrici. Il valore del membro ` geometries ` è una ` QVariantList ` contenente `QVariantMaps` di vari tipi, inclusi altri tipi di `GeometryCollection`.
Ad esempio, il seguente tipo GeometryCollection contiene diverse altre geometrie:
{
"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]
]
]
]
}
]
}Questo oggetto GeoJSON ha una corrispondente rappresentazione QVariantMap:
{
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)
}
]
}
]
}Il tipo Feature contiene un membro aggiuntivo geometry e properties. L’unico modo per distinguere un oggetto Feature da altri oggetti geometrici è verificare l’esistenza di un nodo properties nell’oggetto QVariantMap.
Ad esempio, il seguente Feature presenta i membri «geometry» e «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]
]
]
}
}Questo oggetto GeoJSON ha una corrispondente rappresentazione 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"}
}L’ FeatureCollection è una composizione di oggetti Feature. Il membro features si associa a un oggetto QVariantList contenente altri oggetti Feature.
Ad esempio, il seguente FeatureCollection presenta diverse Feature e geometrie:
{
"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]]
]
}
}
]
}Questo oggetto GeoJSON ha una corrispondente rappresentazione in formato 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" }
}
]
}Esempio GeoJSON
L'esempio GeoJson Viewer illustra l'uso del tipo QML GeoJsonData per caricare e visualizzare le coordinate su una mappa.
Documentazione delle proprietà
model : QVariant [since 6.7]
Una rappresentazione in formato " QVariant " del documento GeoJSON. I delegati QML possono visualizzarne il contenuto nelle viste.
Questa proprietà è stata introdotta in Qt 6.7.
sourceUrl : url [since 6.7]
L'URL di un documento GeoJSON. Impostando questa proprietà, il documento viene caricato e l'oggetto viene associato al membro model.
Questa proprietà è stata introdotta in Qt 6.7.
Documentazione sui metodi
bool addItem(Item item)
Aggiunge l'item all'oggetto model.
Restituisce ` true ` se l'aggiunta va a buon fine, altrimenti ` false `.
void clear()
Elimina tutti gli elementi associati all'model.
bool open()
Carica il contenuto del file all'indirizzo sourceUrl.
Restituisce true se l’apertura va a buon fine, altrimenti false.
bool openUrl(Url url)
Carica il documento GeoJSON all'indirizzo url e lo associa a model. La proprietà sourceUrl viene impostata su url se l'apertura del file va a buon fine.
Restituisce true se l’apertura va a buon fine, false in caso contrario.
bool save()
Salva il modello su sourceUrl.
Restituisce true se il salvataggio va a buon fine, false in caso contrario.
bool saveAs(Url url)
Salva il file ` model ` all'indirizzo url. Se l'operazione va a buon fine, la proprietà ` sourceUrl ` viene impostata su ` url `.
Restituisce true se il salvataggio va a buon fine, false in caso contrario.
void setModelToMapContents(MapView mapItemView)
Aggiunge tutti gli elementi della mappa di mapItemView all'model dell'oggetto GeoJsonData. Elimina gli elementi della mappa precedentemente memorizzati da model.
Restituisce true se l'impostazione va a buon fine, false in caso contrario.
Vedi anche 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.