QGIS API Documentation
2.18.21-Las Palmas (9fba24a)
|
Handles exporting QgsFeature features to GeoJSON features. More...
#include <qgsjsonutils.h>
Public Member Functions | |
QgsJSONExporter (const QgsVectorLayer *vectorLayer=nullptr, int precision=6) | |
Constructor for QgsJSONExporter. 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()) const |
Returns a GeoJSON string representation of a feature. More... | |
QString | exportFeatures (const QgsFeatureList &features) const |
Returns a GeoJSON string representation of a list of features (feature collection). 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 | setAttributes (const QgsAttributeList &attributes) |
Sets the list of attributes to include in the JSON exports. 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 | setVectorLayer (const QgsVectorLayer *vectorLayer) |
Sets the associated vector layer (required for related attribute export). More... | |
const 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 35 of file qgsjsonutils.h.
QgsJSONExporter::QgsJSONExporter | ( | const 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 25 of file qgsjsonutils.cpp.
|
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 136 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 151 of file qgsjsonutils.h.
QString QgsJSONExporter::exportFeature | ( | const QgsFeature & | feature, |
const QVariantMap & | extraProperties = QVariantMap() , |
||
const QVariant & | id = QVariant() |
||
) | 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. |
Definition at line 66 of file qgsjsonutils.cpp.
QString QgsJSONExporter::exportFeatures | ( | const QgsFeatureList & | features | ) | const |
Returns a GeoJSON string representation of a list of features (feature collection).
features | features to convert |
Definition at line 209 of file qgsjsonutils.cpp.
|
inline |
Returns whether attributes will be included in the JSON exports.
Definition at line 78 of file qgsjsonutils.h.
|
inline |
Returns whether geometry will be included in the JSON exports.
Definition at line 67 of file qgsjsonutils.h.
|
inline |
Returns whether attributes of related (child) features will be included in the JSON exports.
Definition at line 91 of file qgsjsonutils.h.
|
inline |
Returns the maximum number of decimal places to use in geometry coordinates.
Definition at line 56 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 127 of file qgsjsonutils.h.
|
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 144 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 73 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 62 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 86 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 51 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 55 of file qgsjsonutils.cpp.
void QgsJSONExporter::setVectorLayer | ( | const 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 40 of file qgsjsonutils.cpp.
const 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 61 of file qgsjsonutils.cpp.
QgsVectorLayer * QgsJSONExporter::vectorLayer | ( | ) | const |
Returns the associated vector layer, if set.
Definition at line 50 of file qgsjsonutils.cpp.