29 #include <QProgressDialog> 31 #define FEATURE_BUFFER_SIZE 200 54 , mAttributeCount( -1 )
55 , mProgress( progress )
106 if ( vectorProvider )
107 delete vectorProvider;
144 for (
int i = 0; i < attrs.
count(); ++i )
179 .arg( errors.
join(
"\n" ) );
212 bool skipAttributeCreation,
218 bool shallTransform =
false;
223 if ( destCRS && destCRS->
isValid() )
227 shallTransform =
true;
232 outputCRS = &layer->
crs();
236 bool overwrite =
false;
237 bool forceSinglePartGeom =
false;
240 overwrite = options->
take(
"overwrite" ).toBool();
241 forceSinglePartGeom = options->
take(
"forceSinglePartGeometryType" ).toBool();
251 for (
int fldIdx = 0; fldIdx < fields.
count(); ++fldIdx )
253 fields[fldIdx].setName( fields.
at( fldIdx ).
name().
toLower() );
256 if ( !forceSinglePartGeom )
286 new QgsVectorLayerImport( uri, providerKey, fields, wkbType, outputCRS, overwrite, options, progress );
300 errorMessage->
clear();
309 if ( skipAttributeCreation )
322 shallTransform =
false;
328 *errorMessage =
QObject::tr(
"Feature write errors:" );
336 bool cancelled =
false;
360 if ( onlySelected && !ids.
contains( fet.
id() ) )
363 if ( shallTransform )
377 QString msg =
QObject::tr(
"Failed to transform a point while drawing a feature with ID '%1'. Writing stopped. (Exception: %2)" )
381 *errorMessage +=
'\n' + msg;
386 if ( skipAttributeCreation )
425 if ( shallTransform )
434 *errorMessage +=
'\n' +
QObject::tr(
"Only %1 of %2 features written." ).
arg( n - errors ).
arg( n );
438 errorMessage->
clear();
444 else if ( errors > 0 )
QgsFeatureId id() const
Get the feature ID for this feature.
Wrapper for iterator of features from vector data provider or vector layer.
static QgsProviderRegistry * instance(const QString &pluginPath=QString::null)
Means of accessing canonical single instance.
QgsAttributeList attributeList() const
Returns list of attribute indexes.
QMap< int, int > mOldToNewAttrIdx
Map attribute indexes to new field indexes.
QgsFields fields() const
Returns the list of fields of this layer.
#define FEATURE_BUFFER_SIZE
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
QgsVectorLayerImport(const QString &uri, const QString &provider, const QgsFields &fields, QGis::WkbType geometryType, const QgsCoordinateReferenceSystem *crs, bool overwrite=false, const QMap< QString, QVariant > *options=nullptr, QProgressDialog *progress=nullptr)
Create a empty layer and add fields to it.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
bool flushBuffer()
Flush the buffer writing the features to the new layer.
QgsVectorDataProvider * mProvider
Container of fields for a vector layer.
bool setAttribute(int field, const QVariant &attr)
Set an attribute's value by field index.
QStringList errors()
Get recorded errors.
WkbType
Used for symbology operations.
QgsVectorLayerImport::ImportError createEmptyLayer_t(const QString &uri, const QgsFields &fields, QGis::WkbType geometryType, const QgsCoordinateReferenceSystem *destCRS, bool overwrite, QMap< int, int > *oldToNewAttrIdx, QString *errorMessage, const QMap< QString, QVariant > *options)
QString join(const QString &separator) const
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
virtual bool addFeatures(QgsFeatureList &flist)
Adds a list of features.
QString tr(const char *sourceText, const char *disambiguation, int n)
QGis::WkbType wkbType() const
Returns the WKBType or WKBUnknown in case of error.
long featureCount(QgsSymbolV2 *symbol)
Number of features rendered with specified symbol.
Allows creation of spatial index.
virtual bool createSpatialIndex()
Creates a spatial index on the datasource (if supported by the provider type).
void setGeometry(const QgsGeometry &geom)
Set this feature's geometry from another QgsGeometry object.
int count(const T &value) const
void append(const T &value)
A convenience class for writing vector files to disk.
QgsDataProvider * provider(const QString &providerKey, const QString &dataSource)
Create an instance of the provider.
const QgsFeatureIds & selectedFeaturesIds() const
Return reference to identifiers of selected features.
#define QgsDebugMsgLevel(str, level)
QgsAttributes attributes() const
Returns the feature's attributes.
virtual int capabilities() const
Returns a bitmask containing the supported capabilities Note, some capabilities may change depending ...
void initAttributes(int fieldCount)
Initialize this feature with the given number of fields.
QString name() const
Gets the name of the field.
QString errorMessage()
Retrieves error message.
static void logMessage(const QString &message, const QString &tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QList< int > QgsAttributeList
~QgsVectorLayerImport()
Close the new created layer.
void clearErrors()
Clear recorded errors.
int count() const
Return number of items.
QgsFeatureRequest & setFlags(const QgsFeatureRequest::Flags &flags)
Set flags that affect how features will be fetched.
void setRange(int minimum, int maximum)
const QgsField & at(int i) const
Get field at particular index (must be in range 0..N-1)
ImportError mError
Contains error value.
static ImportError importLayer(QgsVectorLayer *layer, const QString &uri, const QString &providerKey, const QgsCoordinateReferenceSystem *destCRS, bool onlySelected=false, QString *errorMessage=nullptr, bool skipAttributeCreation=false, QMap< QString, QVariant > *options=nullptr, QProgressDialog *progress=nullptr)
Write contents of vector layer to a different datasource.
bool createSpatialIndex()
Create index.
A registry / canonical manager of data providers.
QgsGeometry * geometry()
Get the geometry object associated with this feature.
bool contains(const T &value) const
bool addFeature(QgsFeature &feature)
Add feature to the new created layer.
QLibrary * providerLibrary(const QString &providerKey) const
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QString providerType() const
Return the provider type for this layer.
const T & at(int i) const
void * resolve(const char *symbol)
ImportError hasError()
Checks whether there were any errors.
virtual bool isValid()=0
Returns true if this is a valid layer.
Class for storing a coordinate reference system (CRS)
int count(const T &value) const
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
int transform(const QgsCoordinateTransform &ct)
Transform this geometry as described by CoordinateTransform ct.
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
void(*)() cast_to_fptr(void *p)
Custom exception class for Coordinate Reference System related exceptions.
bool nextFeature(QgsFeature &f)
This is the base class for vector data providers.
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
QgsFeatureList mFeatureBuffer
const T value(const Key &key) const
QString storageType() const
Returns the permanent storage type for this layer as a friendly name.