GeoJsonData QML Type
一个用于表示、加载和保存 GeoJSON 文档的模型。更多...
| Import Statement: | import QtLocation 6.12 |
| Since: | QtLocation 6.7 |
- 所有成员列表,包括继承的成员
- GeoJsonData 是QML 地图插件的一部分。
属性
方法
- bool addItem(Item item)
- void clear()
- bool open()
- bool openUrl(Url url)
- bool save()
- bool saveAs(Url url)
- void setModelToMapContents(MapView mapItemView)
详细说明
GeoJsonData 类型用于读取和写入 GeoJSON 格式的文档。GeoJsonData 提供了用于打开和保存设置在sourceUrl 属性中的 URL 所对应模型的功能。加载的模型在内部由QVariant 表示,并绑定到model 属性。使用委托在视图中可视化这些项。
有关 GeoJSON 的信息,请访问GeoJSON网站。
GeoJSON 对象
GeoJSON 对象是一个有效的 JSON 对象,用于表示几何图形、要素,或几何图形或要素的集合。
GeoJSON 对象必须属于以下类型之一:
PointMultiPointLineStringMultiLineStringPolygonMultiPolygonGeometryCollectionFeatureFeatureCollection
要设置类型,请将type 成员绑定到GeoJSON类型。coordinates 成员可以是QGeoShape 类型或列表,具体取决于GeoJSON类型。Feature 类型还具有额外的geometry 和properties 成员。
几何类型及其等效的QVariant 表示形式的列表:
- 对于
Point对象,coordinates与QGeoCircle 配对。例如:{ "type": "Point", "coordinates": [11, 60] }该GeoJSON对象对应的QVariantMap 表示形式为:
{ type: "Point" coordinates: QGeoCircle({11.000, 60.000}, -1) } - 对于一个
LineString对象,coordinates与QGeoPath 相对应。例如:{ "type" : "LineString", "coordinates" : [ [13.5, 43], [10.73, 59.92] ] }该 GeoJSON 对象有一个对应的QVariantMap 表示形式:
{ type : "LineString" data : QGeoPath([{43.000, 13.500}, {59.920, 10.730}]) } - 对于
Polygon对象,coordinates成员与QGeoPolygon 配对(允许存在孔洞)。该多边形是一个线性环,其末端坐标与起始坐标相同,从而使环形成闭合。bbox成员为可选成员,用于设置面积范围,这对处理凹形边界非常有用。 有关可接受的多边形坐标的更多信息,请参阅 GeoJSON 规范中的“Polygon”类型。例如:{ "type": "Polygon", "coordinates": [ [ [17.13, 51.11], [30.54, 50.42], [26.70, 58.36], [17.13, 51.11] ] ], "bbox": [50, -50, 10, -10] }此 GeoJSON 对象对应的QVariantMap 表示形式为:
{ type : "Polygon" coordinates : QGeoPolygon([{51.110, 17.130}, {50.420,30.540}, {58.360, 26.700}, {51.110, 17.130}]) }
对于MultiPoint 、MultiLineString 和MultiPolygon 这三种类型,coordinates 需与QVariantList 配对。该列表元素是一个包含几何信息的QVariantMap 。
- 对于
MultiPoint对象,coordinates会与一个包含Point坐标的列表配对。例如:{ "type": "MultiPoint", "coordinates": [ [11, 60], [5.5, 60.3], [5.7, 58.90] ] }该 GeoJSON 对象具有相应的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) } ] } - 对于
MultiLineString对象,coordinates与 LineString 坐标列表配对。以下 GeoJSON 对象构建了两条非平行线:{ "type" : "MultiLineString", "coordinates" : [ [[13.5, 43], [10.73, 59.92]], [[9.15, 45], [-3.15, 58.90]] ] }该 GeoJSON 对象有一个对应的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}]) } ] } - 对于
MultiPolygon类型,coordinates与一个Polygon坐标列表配对。该多边形是一个线性环,有关支持格式的更多信息,请参阅Polygon类型。以下GeoJSON对象包含两个三角形的列表:{ "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] ]] ] }该 GeoJSON 对象对应的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}]) } ] }
GeometryCollection 类型是由其他几何类型组合而成的。geometries 成员的值是一个QVariantList ,其中包含各种类型的QVariantMaps,包括其他GeometryCollection类型。
例如,以下 `GeometryCollection ` 类型包含其他几个几何对象:
{
"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]
]
]
]
}
]
}该 GeoJSON 对象具有相应的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)
}
]
}
]
}Feature 类型还包含一个额外的geometry 和properties 成员。区分Feature对象与其他几何对象的唯一方法是检查QVariantMap 对象中是否存在properties 节点。
例如,以下Feature 包含 geometry 和 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]
]
]
}
}该 GeoJSON 对象对应的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"}
}该FeatureCollection 是由 Feature 对象组合而成的。其features 成员绑定到一个包含其他 Feature 对象的QVariantList 对象上。
例如,以下FeatureCollection 包含多个Feature及其几何信息:
{
"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]]
]
}
}
]
}该 GeoJSON 对象有一个对应的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 示例
GeoJson 查看器示例演示了如何使用 GeoJsonData QML 类型在地图上加载并可视化坐标。
属性文档
model : QVariant [since 6.7]
GeoJSON 文档的QVariant 表示形式。QML 代理可在视图中显示其内容。
该属性于 Qt 6.7 中引入。
sourceUrl : url [since 6.7]
GeoJSON 文档的 URL。设置此属性将加载该文档,并将对象绑定到 `model ` 成员。
该属性自 Qt 6.7 起引入。
方法文档
bool addItem(Item item)
将item 添加到model 对象中。
若添加成功,则返回 `true `;否则返回 `false `。
void clear()
删除所有绑定到model 的项。
bool open()
加载位于sourceUrl 的文件内容。
若打开成功,则返回true ;否则返回false 。
bool openUrl(Url url)
加载位于url 的 GeoJson 文档,并将其绑定到model 上。如果文件打开成功,则将属性sourceUrl 设置为url 。
若打开操作成功,则返回true ;否则返回false 。
bool save()
将模型保存至sourceUrl 。
若保存成功,则返回true ;否则返回false 。
bool saveAs(Url url)
将model 保存至url 。如果操作成功,sourceUrl 属性将设置为url 。
若保存成功,则返回true ;否则返回false 。
void setModelToMapContents(MapView mapItemView)
将mapItemView 中的所有映射项添加到GeoJsonData 对象的model 中。从model 中删除先前存储的映射项。
若设置成功,则返回true ;否则返回false 。
另请参阅 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.