QGIS API Documentation 3.41.0-Master (3440c17df1d)
|
Handles exporting QgsFeature features to GeoJSON features. More...
#include <qgsjsonutils.h>
Public Member Functions | |
QgsJsonExporter (QgsVectorLayer *vectorLayer=nullptr, int precision=6) | |
Constructor for QgsJsonExporter. | |
bool | attributeDisplayName () const |
Returns whether original names of attributes or aliases are printed. | |
QgsAttributeList | attributes () const |
Returns the list of attributes which will be included in the JSON exports, or an empty list if all attributes will be included. | |
QgsAttributeList | excludedAttributes () const |
Returns a list of attributes which will be specifically excluded from the JSON exports. | |
QString | exportFeature (const QgsFeature &feature, const QVariantMap &extraProperties=QVariantMap(), const QVariant &id=QVariant(), int indent=-1) const |
Returns a GeoJSON string representation of a feature. | |
QString | exportFeatures (const QgsFeatureList &features, int indent=-1) const |
Returns a GeoJSON string representation of a list of features (feature collection). | |
json | exportFeaturesToJsonObject (const QgsFeatureList &features) const |
Returns a JSON object representation of a list of features (feature collection). | |
json | exportFeatureToJsonObject (const QgsFeature &feature, const QVariantMap &extraProperties=QVariantMap(), const QVariant &id=QVariant()) const |
Returns a QJsonObject representation of a feature. | |
bool | includeAttributes () const |
Returns whether attributes will be included in the JSON exports. | |
bool | includeGeometry () const |
Returns whether geometry will be included in the JSON exports. | |
bool | includeRelated () const |
Returns whether attributes of related (child) features will be included in the JSON exports. | |
int | precision () const |
Returns the maximum number of decimal places to use in geometry coordinates. | |
void | setAttributeDisplayName (bool displayName) |
Sets whether to print original names of attributes or aliases if defined. | |
void | setAttributes (const QgsAttributeList &attributes) |
Sets the list of attributes to include in the JSON exports. | |
void | setDestinationCrs (const QgsCoordinateReferenceSystem &destinationCrs) |
Set the destination CRS for feature geometry transformation to destinationCrs, this defaults to EPSG:4326 and it is only effective when the automatic geometry transformation is active (it is by default). | |
void | setExcludedAttributes (const QgsAttributeList &attributes) |
Sets a list of attributes to specifically exclude from the JSON exports. | |
void | setIncludeAttributes (bool includeAttributes) |
Sets whether to include attributes in the JSON exports. | |
void | setIncludeGeometry (bool includeGeometry) |
Sets whether to include geometry in the JSON exports. | |
void | setIncludeRelated (bool includeRelated) |
Sets whether to include attributes of features linked via references in the JSON exports. | |
void | setPrecision (int precision) |
Sets the maximum number of decimal places to use in geometry coordinates. | |
void | setSourceCrs (const QgsCoordinateReferenceSystem &crs) |
Sets the source CRS for feature geometries. | |
void | setTransformGeometries (bool activate) |
Sets whether geometries should be transformed in EPSG 4326 (default behavior) or just keep as it is. | |
void | setUseFieldFormatters (bool useFieldFormatters) |
Sets whether field formatters (of type KeyValue, List, ValueRelation, ValueMap) are used to export raw values as displayed values. | |
void | setVectorLayer (QgsVectorLayer *vectorLayer) |
Sets the associated vector layer (required for related attribute export). | |
QgsCoordinateReferenceSystem | sourceCrs () const |
Returns the source CRS for feature geometries. | |
bool | useFieldFormatters () const |
Returned whether field formatters (of type KeyValue, List, ValueRelation, ValueMap) are used to export raw values as displayed values. | |
QgsVectorLayer * | vectorLayer () const |
Returns the associated vector layer, if set. | |
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.
Definition at line 44 of file qgsjsonutils.h.
QgsJsonExporter::QgsJsonExporter | ( | QgsVectorLayer * | vectorLayer = nullptr , |
int | precision = 6 |
||
) |
Constructor for QgsJsonExporter.
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 |
Definition at line 42 of file qgsjsonutils.cpp.
|
inline |
Returns whether original names of attributes or aliases are printed.
Definition at line 123 of file qgsjsonutils.h.
|
inline |
Returns the list of attributes which will be included in the JSON exports, or an empty list if all attributes will be included.
Definition at line 181 of file qgsjsonutils.h.
|
inline |
Returns a list of attributes which will be specifically excluded from the JSON exports.
Excluded attributes take precedence over attributes included via attributes().
Definition at line 198 of file qgsjsonutils.h.
QString QgsJsonExporter::exportFeature | ( | const QgsFeature & | feature, |
const QVariantMap & | extraProperties = QVariantMap() , |
||
const QVariant & | id = QVariant() , |
||
int | indent = -1 |
||
) | const |
Returns a GeoJSON string representation of a feature.
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. |
indent | number of indentation spaces for generated JSON (defaults to none) |
Definition at line 83 of file qgsjsonutils.cpp.
QString QgsJsonExporter::exportFeatures | ( | const QgsFeatureList & | features, |
int | indent = -1 |
||
) | const |
Returns a GeoJSON string representation of a list of features (feature collection).
features | features to convert |
indent | number of indentation spaces for generated JSON (defaults to none) |
Definition at line 237 of file qgsjsonutils.cpp.
json QgsJsonExporter::exportFeaturesToJsonObject | ( | const QgsFeatureList & | features | ) | const |
Returns a JSON object representation of a list of features (feature collection).
features | features to convert |
Definition at line 242 of file qgsjsonutils.cpp.
json QgsJsonExporter::exportFeatureToJsonObject | ( | const QgsFeature & | feature, |
const QVariantMap & | extraProperties = QVariantMap() , |
||
const QVariant & | id = QVariant() |
||
) | const |
Returns a QJsonObject representation of a feature.
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. |
Definition at line 89 of file qgsjsonutils.cpp.
|
inline |
Returns whether attributes will be included in the JSON exports.
Definition at line 94 of file qgsjsonutils.h.
|
inline |
Returns whether geometry will be included in the JSON exports.
Definition at line 81 of file qgsjsonutils.h.
|
inline |
Returns whether attributes of related (child) features will be included in the JSON exports.
Definition at line 109 of file qgsjsonutils.h.
|
inline |
Returns the maximum number of decimal places to use in geometry coordinates.
Definition at line 68 of file qgsjsonutils.h.
|
inline |
Sets whether to print original names of attributes or aliases if defined.
Definition at line 116 of file qgsjsonutils.h.
|
inline |
Sets the list of attributes to include in the JSON exports.
attributes | list of attribute indexes, or an empty list to include all attributes |
Definition at line 171 of file qgsjsonutils.h.
void QgsJsonExporter::setDestinationCrs | ( | const QgsCoordinateReferenceSystem & | destinationCrs | ) |
Set the destination CRS for feature geometry transformation to destinationCrs, this defaults to EPSG:4326 and it is only effective when the automatic geometry transformation is active (it is by default).
Definition at line 259 of file qgsjsonutils.cpp.
|
inline |
Sets a list of attributes to specifically exclude from the JSON exports.
Excluded attributes take precedence over attributes included via setAttributes().
attributes | list of attribute indexes to exclude |
Definition at line 190 of file qgsjsonutils.h.
|
inline |
Sets whether to include attributes in the JSON exports.
includeAttributes | set to false to prevent attribute inclusion |
Definition at line 88 of file qgsjsonutils.h.
|
inline |
Sets whether to include geometry in the JSON exports.
includeGeometry | set to false to prevent geometry inclusion |
Definition at line 75 of file qgsjsonutils.h.
|
inline |
Sets whether to include attributes of features linked via references in the JSON exports.
includeRelated | set to true to include attributes for any related child features within the exported properties element. |
Definition at line 103 of file qgsjsonutils.h.
|
inline |
Sets the maximum number of decimal places to use in geometry coordinates.
The RFC 7946 GeoJSON specification recommends limiting coordinate precision to 6
precision | number of decimal places |
Definition at line 62 of file qgsjsonutils.h.
void QgsJsonExporter::setSourceCrs | ( | const QgsCoordinateReferenceSystem & | crs | ) |
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.
crs | source CRS for input feature geometries |
Definition at line 72 of file qgsjsonutils.cpp.
|
inline |
Sets whether geometries should be transformed in EPSG 4326 (default behavior) or just keep as it is.
Definition at line 160 of file qgsjsonutils.h.
|
inline |
Sets whether field formatters (of type KeyValue, List, ValueRelation, ValueMap) are used to export raw values as displayed values.
The default is true.
Definition at line 206 of file qgsjsonutils.h.
void QgsJsonExporter::setVectorLayer | ( | QgsVectorLayer * | vectorLayer | ) |
Sets the associated vector layer (required for related attribute export).
This will automatically update the sourceCrs() to match.
vectorLayer | vector layer |
Definition at line 57 of file qgsjsonutils.cpp.
QgsCoordinateReferenceSystem QgsJsonExporter::sourceCrs | ( | ) | const |
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.
Definition at line 78 of file qgsjsonutils.cpp.
|
inline |
Returned whether field formatters (of type KeyValue, List, ValueRelation, ValueMap) are used to export raw values as displayed values.
Definition at line 214 of file qgsjsonutils.h.
QgsVectorLayer * QgsJsonExporter::vectorLayer | ( | ) | const |
Returns the associated vector layer, if set.
Definition at line 67 of file qgsjsonutils.cpp.