QGIS API Documentation
3.0.2-Girona (307d082)
|
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... | |
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 (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 38 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 32 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 154 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 171 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 70 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 223 of file qgsjsonutils.cpp.
|
inline |
Returns whether attributes will be included in the JSON exports.
Definition at line 88 of file qgsjsonutils.h.
|
inline |
Returns whether geometry will be included in the JSON exports.
Definition at line 75 of file qgsjsonutils.h.
|
inline |
Returns whether attributes of related (child) features will be included in the JSON exports.
Definition at line 103 of file qgsjsonutils.h.
|
inline |
Returns the maximum number of decimal places to use in geometry coordinates.
Definition at line 62 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 144 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 163 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 82 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 69 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 97 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 56 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 59 of file qgsjsonutils.cpp.
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 44 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 65 of file qgsjsonutils.cpp.
QgsVectorLayer * QgsJsonExporter::vectorLayer | ( | ) | const |
Returns the associated vector layer, if set.
Definition at line 54 of file qgsjsonutils.cpp.