QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
|
Handles exporting QgsFeature features to GeoJSON features. More...
#include <qgsjsonutils.h>
Public Member Functions | |
QgsJsonExporter (QgsVectorLayer *vectorLayer=nullptr, int precision=6) | |
Constructor for QgsJsonExporter. More... | |
bool | attributeDisplayName () const |
Returns whether original names of attributes or aliases are printed. More... | |
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. More... | |
QgsAttributeList | excludedAttributes () const |
Returns a list of attributes which will be specifically excluded from the JSON exports. More... | |
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. More... | |
QString | exportFeatures (const QgsFeatureList &features, int indent=-1) const |
Returns a GeoJSON string representation of a list of features (feature collection). More... | |
json | exportFeaturesToJsonObject (const QgsFeatureList &features) const |
Returns a JSON object representation of a list of features (feature collection). More... | |
json | exportFeatureToJsonObject (const QgsFeature &feature, const QVariantMap &extraProperties=QVariantMap(), const QVariant &id=QVariant()) const |
Returns a QJsonObject representation of a feature. More... | |
bool | includeAttributes () const |
Returns whether attributes will be included in the JSON exports. More... | |
bool | includeGeometry () const |
Returns whether geometry will be included in the JSON exports. More... | |
bool | includeRelated () const |
Returns whether attributes of related (child) features will be included in the JSON exports. More... | |
int | precision () const |
Returns the maximum number of decimal places to use in geometry coordinates. More... | |
void | setAttributeDisplayName (bool displayName) |
Sets whether to print original names of attributes or aliases if defined. More... | |
void | setAttributes (const QgsAttributeList &attributes) |
Sets the list of attributes to include in the JSON exports. More... | |
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). More... | |
void | setExcludedAttributes (const QgsAttributeList &attributes) |
Sets a list of attributes to specifically exclude from the JSON exports. More... | |
void | setIncludeAttributes (bool includeAttributes) |
Sets whether to include attributes in the JSON exports. More... | |
void | setIncludeGeometry (bool includeGeometry) |
Sets whether to include geometry in the JSON exports. More... | |
void | setIncludeRelated (bool includeRelated) |
Sets whether to include attributes of features linked via references in the JSON exports. More... | |
void | setPrecision (int precision) |
Sets the maximum number of decimal places to use in geometry coordinates. More... | |
void | setSourceCrs (const QgsCoordinateReferenceSystem &crs) |
Sets the source CRS for feature geometries. More... | |
void | setTransformGeometries (bool activate) |
Sets whether geometries should be transformed in EPSG 4326 (default behavior) or just keep as it is. More... | |
void | setVectorLayer (QgsVectorLayer *vectorLayer) |
Sets the associated vector layer (required for related attribute export). More... | |
QgsCoordinateReferenceSystem | sourceCrs () const |
Returns the source CRS for feature geometries. More... | |
QgsVectorLayer * | vectorLayer () const |
Returns the associated vector layer, if set. More... | |
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 40 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 36 of file qgsjsonutils.cpp.
|
inline |
Returns whether original names of attributes or aliases are printed.
Definition at line 119 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 177 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 194 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 77 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 231 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 236 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 83 of file qgsjsonutils.cpp.
|
inline |
Returns whether attributes will be included in the JSON exports.
Definition at line 90 of file qgsjsonutils.h.
|
inline |
Returns whether geometry will be included in the JSON exports.
Definition at line 77 of file qgsjsonutils.h.
|
inline |
Returns whether attributes of related (child) features will be included in the JSON exports.
Definition at line 105 of file qgsjsonutils.h.
|
inline |
Returns the maximum number of decimal places to use in geometry coordinates.
Definition at line 64 of file qgsjsonutils.h.
|
inline |
Sets whether to print original names of attributes or aliases if defined.
Definition at line 112 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 167 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 250 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 186 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 84 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 71 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 99 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 58 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 66 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 156 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 51 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 72 of file qgsjsonutils.cpp.
QgsVectorLayer * QgsJsonExporter::vectorLayer | ( | ) | const |
Returns the associated vector layer, if set.
Definition at line 61 of file qgsjsonutils.cpp.