A model to represent, load and save GeoJSON documents. 更多...
| import 语句: |
import QtLocation 6.8
|
| Since: | QtLocation 6.7 |
The GeoJsonData type reads and writes GeoJson formatted documents. GeoJsonData has functions to open and save the model at the URL set to the sourceUrl property. The loaded model is internally represented by QVariant and binds to the model property. Use 委托 to visualize the items in a view.
For information about GeoJSON, visit the GeoJSON website.
The GeoJSON object is a valid JSON object that represents geometry, a feature, or a collection of geometries or features.
A GeoJSON object must be one of these types:
Point
MultiPoint
LineString
MultiLineString
Polygon
MultiPolygon
GeometryCollection
Feature
FeatureCollection
To set the type, bind the
type
member to a GeoJSON type. The
coordinates
member can be a type of
QGeoShape
or a list, depending on the GeoJSON type. The
Feature
type has an additional
geometry
and
properties
member.
A list of the geometric types and their equivalent QVariant representations:
Point
对象,
coordinates
pairs with
QGeoCircle
。例如:
{
"type"
:
"Point"
,
"coordinates"
:
[
11
,
60
]
}
This GeoJSON object has a corresponding QVariantMap representation:
{
type: "Point"
coordinates: QGeoCircle({11.000, 60.000}, -1)
}
LineString
对象,
coordinates
pairs with
QGeoPath
。例如:
{
"type"
:
"LineString"
,
"coordinates"
:
[
[
13.5
,
43
]
,
[
10.73
,
59.92
]
]
}
This GeoJSON object has a corresponding QVariantMap representation:
{
type : "LineString"
data : QGeoPath([{43.000, 13.500}, {59.920, 10.730}])
}
Polygon
对象,
coordinates
member pairs with
QGeoPolygon
(holes are possible). The polygon is a
linear ring
, whose final coordinate is the same as the first coordinate, thereby opening and closing the ring. The
bbox
member is an optional member and is for setting the area's range, useful for concave boundaries. For more information about the accepted polygon coordinates, read about the
Polygon
type in the GeoJson specification. For example:
{
"type"
:
"Polygon"
,
"coordinates"
:
[
[
[
17.13
,
51.11
]
,
[
30.54
,
50.42
]
,
[
26.70
,
58.36
]
,
[
17.13
,
51.11
]
]
]
,
"bbox"
:
[
50
,
-
50
,
10
,
-
10
]
}
This GeoJSON object has a corresponding QVariantMap representation:
{
type : "Polygon"
coordinates : QGeoPolygon([{51.110, 17.130}, {50.420,30.540}, {58.360, 26.700}, {51.110, 17.130}])
}
对于
MultiPoint
,
MultiLineString
,和
MultiPolygon
类型,
coordinates
pairs with a
QVariantList
. The list element is a
QVariantMap
containing geometry.
MultiPoint
对象,
coordinates
pairs with a list of Point coordinates. For example:
{
"type"
:
"MultiPoint"
,
"coordinates"
:
[
[
11
,
60
]
,
[
5.5
,
60.3
]
,
[
5.7
,
58.90
]
]
}
This GeoJSON object has a corresponding QVariantMap representation:
{
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
pairs with a list of LineString coordinates. The following GeoJSON object constructs two non-parallel lines:
{
"type"
:
"MultiLineString"
,
"coordinates"
:
[
[
[
13.5
,
43
]
,
[
10.73
,
59.92
]
]
,
[
[
9.15
,
45
]
,
[
-
3.15
,
58.90
]
]
]
}
This GeoJSON object has a corresponding QVariantMap representation:
{
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
type,
coordinates
pairs with a list of Polygon coordinates. The polygon is a
linear ring
和
Polygon
type has more information about accepted formats. The following GeoJSON object contains a list of two triangles:
{
"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
]
]
]
]
}
This GeoJSON object has a corresponding QVariantMap representation:
{
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}])
}
]
}
The
GeometryCollection
type is a composition of other geometry types. The value of the
geometries
member is a
QVariantList
containing QVariantMaps of various types, including other GeometryCollection types.
例如,以下
GeometryCollection
type contains several other geometries:
{
"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]
]
]
]
}
]
}
This GeoJSON object has a corresponding QVariantMap representation:
{
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)
}
]
}
]
}
The
Feature
type contains an additional
geometry
and
properties
member. The only way to distinguish a Feature object from other geometrical objects is to check for the existence of a
properties
node in the
QVariantMap
对象。
例如,以下
Feature
has a geometry and properties members:
{
"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]
]
]
}
}
This GeoJSON object has a corresponding QVariantMap representation:
{
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"}
}
The
FeatureCollection
is a composition of Feature objects. THe
features
member binds to a
QVariantList
object containing other Feature objects.
例如,以下
FeatureCollection
has several Features and geometries:
{
"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]]
]
}
}
]
}
This GeoJSON object has a corresponding QVariantMap representation:
{
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" }
}
]
}
The GeoJson Viewer example demonstrates the use of the GeoJsonData QML type to load and visualize coordinates on a map.
|
model
:
QVariant
|
A QVariant representation of the GeoJSON document. QML delegates can display the contents in views.
该特性在 Qt 6.7 引入。
|
sourceUrl
:
url
|
The URL of a GeoJSON document. Setting this property loads the document and binds the object to the model member.
该特性在 Qt 6.7 引入。
添加 item 到 model 对象。
返回
true
if adding is successful,
false
否则。
|
void clear () |
Deletes all items bound to the model .
|
bool open () |
Loads the content of the file at sourceUrl .
返回
true
if opening is successful,
false
否则。
Loads the GeoJson document at url and binds it to the model . The property sourceUrl 被设为 url if opening the file is successful.
返回
true
if opening is successful,
false
否则。
|
bool save () |
Saves the model at sourceUrl .
返回
true
if saving is successful,
false
否则。
Saves the model at url 。 sourceUrl property is set to url 若成功。
返回
true
if saving is successful,
false
否则。
|
void setModelToMapContents ( MapView mapItemView ) |
Adds all map items of mapItemView 到 model 的 GeoJsonData object. Deletes previously stored map items from the model .
返回
true
if setting is successful,
false
否则。
另请参阅 addItem .