26     : mPrecision( precision )
    27     , mIncludeGeometry( true )
    28     , mIncludeAttributes( true )
    29     , mIncludeRelatedAttributes( false )
    30     , mLayerId( vectorLayer ? vectorLayer->id() : 
QString() )
    34     mCrs = vectorLayer->
crs();
    42   mLayerId = vectorLayer ? vectorLayer->
id() : 
QString();
    45     mCrs = vectorLayer->
crs();
    69   QString s = 
"{\n   \"type\":\"Feature\",\n";
    75   if ( geom && !geom->
isEmpty() && mIncludeGeometry )
    83         if ( clone->
transform( mTransform ) == 0 )
   103     s += 
"   \"geometry\":\n   ";
   107     if ( exportGeom != geom )
   112     s += 
"   \"geometry\":null,\n";
   117   int attributeCounter = 0;
   118   if ( mIncludeAttributes || !extraProperties.isEmpty() )
   122     if ( mIncludeAttributes )
   126       for ( 
int i = 0; i < fields->
count(); ++i )
   128         if (( !mAttributeIndexes.
isEmpty() && !mAttributeIndexes.
contains( i ) ) || mExcludedAttributeIndexes.
contains( i ) )
   131         if ( attributeCounter > 0 )
   141     if ( !extraProperties.isEmpty() )
   143       QVariantMap::const_iterator it = extraProperties.
constBegin();
   144       for ( ; it != extraProperties.constEnd(); ++it )
   146         if ( attributeCounter > 0 )
   157     if ( vl && mIncludeRelatedAttributes )
   160       Q_FOREACH ( 
const QgsRelation& relation, relations )
   162         if ( attributeCounter > 0 )
   168         QString relatedFeatureAttributes;
   173           int relationFeatures = 0;
   176             if ( relationFeatures > 0 )
   177               relatedFeatureAttributes += 
",\n";
   185         properties += 
QString( 
"      \"%1\":%2" ).
arg( relation.
name(), relatedFeatureAttributes );
   191   bool hasProperties = attributeCounter > 0;
   193   s += 
"   \"properties\":";
   197     s += 
"{\n" + properties + 
"\n   }\n";
   212   Q_FOREACH ( 
const QgsFeature& feature, features )
   217   return QString( 
"{ \"type\": \"FeatureCollection\",\n    \"features\":[\n%1\n]}" ).
arg( featureJSON.
join( 
",\n" ) );
   241   switch ( value.
type() )
   245     case QVariant::LongLong:
   246     case QVariant::ULongLong:
   247     case QVariant::Double:
   251       return value.
toBool() ? 
"true" : 
"false";
   253     case QVariant::StringList:
   257       Q_FOREACH ( 
const QString& 
string, input )
   259         output << encodeValue( 
string );
   266       QVariantList input = value.
toList();
   268       Q_FOREACH ( 
const QVariant& v, input )
   270         output << encodeValue( v );
   280       for ( ; it != input.
constEnd(); ++it )
   282         output << encodeValue( it.
key() ) + 
':' + encodeValue( it.
value() );
   288     case QVariant::String:
   306   for ( 
int i = 0; i < fields->
count(); ++i )
   312     attrs += encodeValue( fields->
at( i ).
name() ) + 
':' + encodeValue( val );
 const_iterator constBegin() const
 
Wrapper for iterator of features from vector data provider or vector layer. 
 
A rectangle specified with double values. 
 
QString & append(QChar ch)
 
QgsAttributes attributes() const
Returns the feature's attributes. 
 
static QString exportAttributes(const QgsFeature &feature)
Exports all attributes from a QgsFeature as a JSON map type. 
 
QgsVectorLayer * vectorLayer() const
Returns the associated vector layer, if set. 
 
QList< QVariant > toList() const
 
QgsMapLayer * mapLayer(const QString &theLayerId) const
Retrieve a pointer to a registered layer by layer ID. 
 
QString & prepend(QChar ch)
 
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request. 
 
QString exportFeatures(const QgsFeatureList &features) const
Returns a GeoJSON string representation of a list of features (feature collection). 
 
const_iterator constBegin() const
 
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system. 
 
static QgsFields stringToFields(const QString &string, QTextCodec *encoding)
Attempts to retrieve the fields from a GeoJSON string representing a collection of features...
 
Container of fields for a vector layer. 
 
A geometry is the spatial representation of a feature. 
 
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature. 
 
QString join(const QString &separator) const
 
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
 
QgsRelationManager * relationManager() const
 
int count() const
Return number of items. 
 
const QgsField & at(int i) const
Get field at particular index (must be in range 0..N-1) 
 
QString number(int n, int base)
 
static QgsFeatureList stringToFeatureList(const QString &string, const QgsFields &fields, QTextCodec *encoding)
Attempts to parse a string representing a collection of features using OGR. 
 
const QgsFields * fields() const
Returns the field map associated with the feature. 
 
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry. 
 
QgsJSONExporter(const QgsVectorLayer *vectorLayer=nullptr, int precision=6)
Constructor for QgsJSONExporter. 
 
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double. 
 
static QString encodeValue(const QVariant &value)
Encodes a value to a JSON string representation, adding appropriate quotations and escaping where req...
 
const_iterator constEnd() const
 
This class wraps a request for features to a vector layer (or directly its vector data provider)...
 
bool isEmpty() const
Returns true if the geometry is empty (ie, contains no underlying geometry accessible via geometry)...
 
QgsFeatureRequest & setFlags(const QgsFeatureRequest::Flags &flags)
Set flags that affect how features will be fetched. 
 
QList< QgsRelation > referencedRelations(QgsVectorLayer *layer=nullptr) const
Get all relations where this layer is the referenced part (i.e. 
 
static QgsFields stringToFields(const QString &string, QTextCodec *encoding)
Attempts to retrieve the fields from a string representing a collection of features using OGR...
 
QgsFeatureRequest getRelatedFeaturesRequest(const QgsFeature &feature) const
Creates a request to return all the features on the referencing (child) layer which have a foreign ke...
 
const QgsCoordinateReferenceSystem & sourceCrs() const
Returns the source CRS for feature geometries. 
 
QgsFeatureId id() const
Get the feature ID for this feature. 
 
double yMinimum() const
Get the y minimum value (bottom side of rectangle) 
 
bool contains(const T &value) const
 
double xMaximum() const
Get the x maximum value (right side of rectangle) 
 
const Key key(const T &value) const
 
QString & replace(int position, int n, QChar after)
 
const T & at(int i) const
 
QgsVectorLayer * referencingLayer() const
Access the referencing (child) layer This is the layer which has the field(s) which point to another ...
 
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call. 
 
QgsAbstractGeometryV2 * geometry() const
Returns the underlying geometry store. 
 
QMap< QString, QVariant > toMap() const
 
QStringList toStringList() const
 
QString exportToGeoJSON(int precision=17) const
Exports the geometry to GeoJSON. 
 
QgsWKBTypes::Type wkbType() const
Returns the WKB type of the geometry. 
 
static QgsProject * instance()
Returns the QgsProject singleton instance. 
 
void setSourceCrs(const QgsCoordinateReferenceSystem &crs)
Sets the source CRS for feature geometries. 
 
QgsRectangle boundingBox() const
Returns the bounding box of this feature. 
 
Class for storing a coordinate reference system (CRS) 
 
double xMinimum() const
Get the x minimum value (left side of rectangle) 
 
int transform(const QgsCoordinateTransform &ct)
Transform this geometry as described by CoordinateTransform ct. 
 
static Type flatType(Type type)
Returns the flat type for a WKB type. 
 
double yMaximum() const
Get the y maximum value (top side of rectangle) 
 
void setVectorLayer(const QgsVectorLayer *vectorLayer)
Sets the associated vector layer (required for related attribute export). 
 
Custom exception class for Coordinate Reference System related exceptions. 
 
bool nextFeature(QgsFeature &f)
 
Geometry is not required. It may still be returned if e.g. required for a filter condition. 
 
Represents a vector layer which manages a vector based data sets. 
 
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
 
QString exportFeature(const QgsFeature &feature, const QVariantMap &extraProperties=QVariantMap(), const QVariant &id=QVariant()) const
Returns a GeoJSON string representation of a feature. 
 
static QgsFeatureList stringToFeatureList(const QString &string, const QgsFields &fields, QTextCodec *encoding)
Attempts to parse a GeoJSON string to a collection of features. 
 
QString name() const
Returns a human readable name for this relation. 
 
const T value(const Key &key) const
 
bool isValid() const
Returns whether this CRS is correctly initialized and usable.