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.
QgsJsonExporter(vectorLayer:
QgsVectorLayer
= None, precision: int = 6) Constructor for QgsJsonExporter.- Parameters
vectorLayer – associated vector layer (required for related attribute export)
precision – maximum number of decimal places to use for geometry coordinates, the RFC 7946 GeoJSON specification recommends limiting coordinate precision to 6
QgsJsonExporter(
QgsJsonExporter
)Methods
Returns whether original names of attributes or aliases are printed.
Returns the list of attributes which will be included in the JSON exports, or an empty list if all attributes will be included.
Returns a list of attributes which will be specifically excluded from the JSON exports.
Returns a GeoJSON string representation of a feature.
Returns a GeoJSON string representation of a list of features (feature collection).
Returns whether attributes will be included in the JSON exports.
Returns whether geometry will be included in the JSON exports.
Returns whether attributes of related (child) features will be included in the JSON exports.
Returns the maximum number of decimal places to use in geometry coordinates.
Sets whether to print original names of attributes or aliases if defined.
Sets the list of attributes to include in the JSON exports.
Sets a list of attributes to specifically exclude from the JSON exports.
Sets whether to include attributes in the JSON exports.
Sets whether to include geometry in the JSON exports.
Sets whether to include attributes of features linked via references in the JSON exports.
Sets the maximum number of decimal places to use in geometry coordinates.
Sets the source CRS for feature geometries.
Sets whether geometries should be transformed in EPSG 4326 (default behavior) or just keep as it is.
Sets the associated vector layer (required for related attribute export).
Returns the source CRS for feature geometries.
Returns the associated vector layer, if set.
- attributeDisplayName(self) bool ¶
Returns whether original names of attributes or aliases are printed.
New in version 3.6.
- Return type
bool
- 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.- Return type
List[int]
- 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
- Return type
List[int]
- exportFeature(self, feature: QgsFeature, extraProperties: Dict[str, Any] = {}, id: Any = None, indent: int = -1) str ¶
Returns a GeoJSON string representation of a feature.
- Parameters
feature (QgsFeature) – feature to convert
extraProperties (Dict[str) – map of extra attributes to include in feature’s properties
id (Any = None) – optional ID to use as GeoJSON feature’s ID instead of input feature’s ID. If omitted, feature’s ID is used.
indent (int = -1) – number of indentation spaces for generated JSON (defaults to none)
- Return type
str
- Returns
GeoJSON string
See also
See also
exportFeatureToJsonObject()
- exportFeatures(self, features: Iterable[QgsFeature], indent: int = -1) str ¶
Returns a GeoJSON string representation of a list of features (feature collection).
- Parameters
features (Iterable[QgsFeature]) – features to convert
indent (int = -1) – number of indentation spaces for generated JSON (defaults to none)
- Return type
str
- Returns
GeoJSON string
See also
- includeAttributes(self) bool ¶
Returns whether attributes will be included in the JSON exports.
See also
- Return type
bool
- includeGeometry(self) bool ¶
Returns whether geometry will be included in the JSON exports.
See also
- Return type
bool
- includeRelated(self) bool ¶
Returns whether attributes of related (child) features will be included in the JSON exports.
See also
- Return type
bool
- precision(self) int ¶
Returns the maximum number of decimal places to use in geometry coordinates.
See also
- Return type
int
- setAttributeDisplayName(self, displayName: bool)¶
Sets whether to print original names of attributes or aliases if defined.
New in version 3.6.
- Parameters
displayName (bool) –
- setAttributes(self, attributes: Iterable[int])¶
Sets the list of attributes to include in the JSON exports.
- Parameters
attributes (Iterable[int]) – 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 (Iterable[int]) – 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 (bool) – set to
False
to prevent attribute inclusion
See also
- setIncludeGeometry(self, includeGeometry: bool)¶
Sets whether to include geometry in the JSON exports.
- Parameters
includeGeometry (bool) – 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 (bool) – 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 (int) – 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 (QgsCoordinateReferenceSystem) – source CRS for input feature geometries
Note
the source CRS will be overwritten when a vector layer is specified via
setVectorLayer()
See also
- setTransformGeometries(self, activate: bool)¶
Sets whether geometries should be transformed in EPSG 4326 (default behavior) or just keep as it is.
New in version 3.12.
- Parameters
activate (bool) –
- setVectorLayer(self, vectorLayer: QgsVectorLayer)¶
Sets the associated vector layer (required for related attribute export). This will automatically update the
sourceCrs()
to match.- Parameters
vectorLayer (QgsVectorLayer) – 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
- Return type
- vectorLayer(self) QgsVectorLayer ¶
Returns the associated vector layer, if set.
See also
- Return type