Subgroup: Json
Class: QgsJsonExporter¶
-
class
qgis.core.
QgsJsonExporter
¶ Bases:
sip.wrapper
Handles exporting QgsFeature features to GeoJSON features.
Note that geometries will be automatically reprojected to WGS84 to match GeoJSON spec if either the source vector layer or source CRS is set.
New in version 2.16: Methods
attributes
Returns the list of attributes which will be included in the JSON exports, or an empty list if all attributes will be included. excludedAttributes
Returns a list of attributes which will be specifically excluded from the JSON exports. exportFeature
Returns a GeoJSON string representation of a feature. exportFeatures
Returns a GeoJSON string representation of a list of features (feature collection). includeAttributes
Returns whether attributes will be included in the JSON exports. includeGeometry
Returns whether geometry will be included in the JSON exports. includeRelated
Returns whether attributes of related (child) features will be included in the JSON exports. precision
Returns the maximum number of decimal places to use in geometry coordinates. setAttributes
Sets the list of attributes to include in the JSON exports. setExcludedAttributes
Sets a list of attributes to specifically exclude from the JSON exports. setIncludeAttributes
Sets whether to include attributes in the JSON exports. setIncludeGeometry
Sets whether to include geometry in the JSON exports. setIncludeRelated
Sets whether to include attributes of features linked via references in the JSON exports. setPrecision
Sets the maximum number of decimal places to use in geometry coordinates. setSourceCrs
Sets the source CRS for feature geometries. setVectorLayer
Sets the associated vector layer (required for related attribute export). sourceCrs
Returns the source CRS for feature geometries. vectorLayer
Returns the associated vector layer, if set. Attributes
-
attributes
(self) → List[int]¶ Returns the list of attributes which will be included in the JSON exports, or an empty list if all attributes will be included.
See also
See also
Note
Attributes excluded via excludedAttributes() take precedence over attributes returned by this method.
-
excludedAttributes
(self) → List[int]¶ Returns a list of attributes which will be specifically excluded from the JSON exports. Excluded attributes take precedence over attributes included via attributes().
See also
See also
-
exportFeature
(self, feature: QgsFeature, extraProperties: Dict[str, Any] = QVariantMap(), id: Any = None) → str¶ Returns a GeoJSON string representation of a feature.
Parameters: - feature – feature to convert
- extraProperties – map of extra attributes to include in feature’s properties
- id – optional ID to use as GeoJSON feature’s ID instead of input feature’s ID. If omitted, feature’s
ID is used.
Returns: GeoJSON string See also
-
exportFeatures
(self, features: object) → str¶ Returns a GeoJSON string representation of a list of features (feature collection).
Parameters: features – features to convert Returns: GeoJSON string See also
-
includeAttributes
(self) → bool¶ Returns whether attributes will be included in the JSON exports.
See also
-
includeGeometry
(self) → bool¶ Returns whether geometry will be included in the JSON exports.
See also
-
includeRelated
(self) → bool¶ Returns whether attributes of related (child) features will be included in the JSON exports.
See also
-
precision
(self) → int¶ Returns the maximum number of decimal places to use in geometry coordinates.
See also
-
setAttributes
(self, attributes: Iterable[int])¶ Sets the list of attributes to include in the JSON exports.
Parameters: attributes – list of attribute indexes, or an empty list to include all attributes
See also
See also
Note
Attributes excluded via setExcludedAttributes() take precedence over attributes specified by this method.
-
setExcludedAttributes
(self, attributes: Iterable[int])¶ Sets a list of attributes to specifically exclude from the JSON exports. Excluded attributes take precedence over attributes included via setAttributes().
Parameters: attributes – list of attribute indexes to exclude See also
See also
-
setIncludeAttributes
(self, includeAttributes: bool)¶ Sets whether to include attributes in the JSON exports.
Parameters: includeAttributes – set to false to prevent attribute inclusion See also
-
setIncludeGeometry
(self, includeGeometry: bool)¶ Sets whether to include geometry in the JSON exports.
Parameters: includeGeometry – set to false to prevent geometry inclusion See also
-
setIncludeRelated
(self, includeRelated: bool)¶ Sets whether to include attributes of features linked via references in the JSON exports.
Parameters: includeRelated – set to true to include attributes for any related child features within the exported properties element.
Note
associated vector layer must be set with setVectorLayer()
See also
-
setPrecision
(self, precision: int)¶ Sets the maximum number of decimal places to use in geometry coordinates. The RFC 7946 GeoJSON specification recommends limiting coordinate precision to 6
Parameters: precision – number of decimal places See also
-
setSourceCrs
(self, crs: QgsCoordinateReferenceSystem)¶ Sets the source CRS for feature geometries. The source CRS must be set if geometries are to be correctly automatically reprojected to WGS 84, to match GeoJSON specifications.
Parameters: crs – source CRS for input feature geometries Note
the source CRS will be overwritten when a vector layer is specified via setVectorLayer()
See also
-
setVectorLayer
(self, vectorLayer: QgsVectorLayer)¶ Sets the associated vector layer (required for related attribute export). This will automatically update the sourceCrs() to match.
Parameters: vectorLayer – vector layer See also
-
sourceCrs
(self) → QgsCoordinateReferenceSystem¶ Returns the source CRS for feature geometries. The source CRS must be set if geometries are to be correctly automatically reprojected to WGS 84, to match GeoJSON specifications.
See also
-
vectorLayer
(self) → QgsVectorLayer¶ Returns the associated vector layer, if set.
See also
-