QGIS API Documentation
3.6.0-Noosa (5873452)
|
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()) 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 | 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 | 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 39 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 33 of file qgsjsonutils.cpp.
|
inline |
Returns whether original names of attributes or aliases are printed.
Definition at line 118 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 169 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 186 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 71 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 238 of file qgsjsonutils.cpp.
|
inline |
Returns whether attributes will be included in the JSON exports.
Definition at line 89 of file qgsjsonutils.h.
|
inline |
Returns whether geometry will be included in the JSON exports.
Definition at line 76 of file qgsjsonutils.h.
|
inline |
Returns whether attributes of related (child) features will be included in the JSON exports.
Definition at line 104 of file qgsjsonutils.h.
|
inline |
Returns the maximum number of decimal places to use in geometry coordinates.
Definition at line 63 of file qgsjsonutils.h.
|
inline |
Sets whether to print original names of attributes or aliases if defined.
Definition at line 111 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 159 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 178 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 83 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 70 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 98 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 57 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 60 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 45 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 66 of file qgsjsonutils.cpp.
QgsVectorLayer * QgsJsonExporter::vectorLayer | ( | ) | const |
Returns the associated vector layer, if set.
Definition at line 55 of file qgsjsonutils.cpp.