QGIS API Documentation  2.18.3-Las Palmas (77b8c3d)
Public Member Functions | List of all members
QgsJSONExporter Class Reference

Handles exporting QgsFeature features to GeoJSON features. More...

#include <qgsjsonutils.h>

Public Member Functions

 QgsJSONExporter (const QgsVectorLayer *vectorLayer=nullptr, int precision=17)
 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 QgsCoordinateReferenceSystemsourceCrs () const
 Returns the source CRS for feature geometries. More...
 
QgsVectorLayervectorLayer () const
 Returns the associated vector layer, if set. More...
 

Detailed Description

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.

Note
Added in version 2.16

Definition at line 35 of file qgsjsonutils.h.

Constructor & Destructor Documentation

QgsJSONExporter::QgsJSONExporter ( const QgsVectorLayer vectorLayer = nullptr,
int  precision = 17 
)

Constructor for QgsJSONExporter.

Parameters
vectorLayerassociated vector layer (required for related attribute export)
precisionmaximum number of decimal places to use for geometry coordinates

Definition at line 25 of file qgsjsonutils.cpp.

Member Function Documentation

QgsAttributeList QgsJSONExporter::attributes ( ) const
inline

Returns the list of attributes which will be included in the JSON exports, or an empty list if all attributes will be included.

See also
setAttributes()
excludedAttributes()
Note
Attributes excluded via excludedAttributes() take precedence over attributes returned by this method.

Definition at line 134 of file qgsjsonutils.h.

QgsAttributeList QgsJSONExporter::excludedAttributes ( ) const
inline

Returns a list of attributes which will be specifically excluded from the JSON exports.

Excluded attributes take precedence over attributes included via attributes().

See also
setExcludedAttributes()
attributes()

Definition at line 149 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.

Parameters
featurefeature to convert
extraPropertiesmap of extra attributes to include in feature's properties
idoptional ID to use as GeoJSON feature's ID instead of input feature's ID. If omitted, feature's ID is used.
Returns
GeoJSON string
See also
exportFeatures()

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).

Parameters
featuresfeatures to convert
Returns
GeoJSON string
See also
exportFeature()

Definition at line 209 of file qgsjsonutils.cpp.

bool QgsJSONExporter::includeAttributes ( ) const
inline

Returns whether attributes will be included in the JSON exports.

See also
setIncludeAttributes()

Definition at line 76 of file qgsjsonutils.h.

bool QgsJSONExporter::includeGeometry ( ) const
inline

Returns whether geometry will be included in the JSON exports.

See also
setIncludeGeometry()

Definition at line 65 of file qgsjsonutils.h.

bool QgsJSONExporter::includeRelated ( ) const
inline

Returns whether attributes of related (child) features will be included in the JSON exports.

See also
setIncludeRelated()

Definition at line 89 of file qgsjsonutils.h.

int QgsJSONExporter::precision ( ) const
inline

Returns the maximum number of decimal places to use in geometry coordinates.

See also
setPrecision()

Definition at line 54 of file qgsjsonutils.h.

void QgsJSONExporter::setAttributes ( const QgsAttributeList attributes)
inline

Sets the list of attributes to include in the JSON exports.

Parameters
attributeslist of attribute indexes, or an empty list to include all attributes
See also
attributes()
setExcludedAttributes()
Note
Attributes excluded via setExcludedAttributes() take precedence over attributes specified by this method.

Definition at line 125 of file qgsjsonutils.h.

void QgsJSONExporter::setExcludedAttributes ( const QgsAttributeList attributes)
inline

Sets a list of attributes to specifically exclude from the JSON exports.

Excluded attributes take precedence over attributes included via setAttributes().

Parameters
attributeslist of attribute indexes to exclude
See also
excludedAttributes()
setAttributes()

Definition at line 142 of file qgsjsonutils.h.

void QgsJSONExporter::setIncludeAttributes ( bool  includeAttributes)
inline

Sets whether to include attributes in the JSON exports.

Parameters
includeAttributesset to false to prevent attribute inclusion
See also
includeAttributes()

Definition at line 71 of file qgsjsonutils.h.

void QgsJSONExporter::setIncludeGeometry ( bool  includeGeometry)
inline

Sets whether to include geometry in the JSON exports.

Parameters
includeGeometryset to false to prevent geometry inclusion
See also
includeGeometry()

Definition at line 60 of file qgsjsonutils.h.

void QgsJSONExporter::setIncludeRelated ( bool  includeRelated)
inline

Sets whether to include attributes of features linked via references in the JSON exports.

Parameters
includeRelatedset to true to include attributes for any related child features within the exported properties element.
Note
associated vector layer must be set with setVectorLayer()
See also
includeRelated()

Definition at line 84 of file qgsjsonutils.h.

void QgsJSONExporter::setPrecision ( int  precision)
inline

Sets the maximum number of decimal places to use in geometry coordinates.

Parameters
precisionnumber of decimal places
See also
precision()

Definition at line 49 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.

Parameters
crssource CRS for input feature geometries
Note
the source CRS will be overwritten when a vector layer is specified via setVectorLayer()
See also
sourceCrs()

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.

Parameters
vectorLayervector layer
See also
vectorLayer()

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.

See also
setSourceCrs()

Definition at line 61 of file qgsjsonutils.cpp.

QgsVectorLayer * QgsJSONExporter::vectorLayer ( ) const

Returns the associated vector layer, if set.

See also
setVectorLayer()

Definition at line 50 of file qgsjsonutils.cpp.


The documentation for this class was generated from the following files: