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;
225 if ( destCRS && destCRS->
isValid() )
229 shallTransform =
true;
234 outputCRS = &layer->
crs();
238 bool overwrite =
false;
239 bool forceSinglePartGeom =
false;
242 overwrite = options->
take(
"overwrite" ).toBool();
243 forceSinglePartGeom = options->
take(
"forceSinglePartGeometryType" ).toBool();
253 for (
int fldIdx = 0; fldIdx < fields.
count(); ++fldIdx )
255 fields[fldIdx].setName( fields.
at( fldIdx ).
name().
toLower() );
258 if ( !forceSinglePartGeom )
288 new QgsVectorLayerImport( uri, providerKey, fields, wkbType, outputCRS, overwrite, options, progress );
302 errorMessage->
clear();
311 if ( skipAttributeCreation )
327 shallTransform =
false;
334 *errorMessage =
QObject::tr(
"Feature write errors:" );
363 if ( onlySelected && !ids.
contains( fet.
id() ) )
366 if ( shallTransform )
380 QString msg =
QObject::tr(
"Failed to transform a point while drawing a feature with ID '%1'. Writing stopped. (Exception: %2)" )
384 *errorMessage +=
"\n" + msg;
389 if ( skipAttributeCreation )
428 if ( shallTransform )
437 *errorMessage +=
"\n" +
QObject::tr(
"Only %1 of %2 features written." ).
arg( n - errors ).
arg( n );
441 errorMessage->
clear();
QgsFeatureId id() const
Get the feature ID for this feature.
const QString & name() const
Gets the name of the field.
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.
QList< T > values() const
QgsVectorLayerImport(const QString &uri, const QString &provider, const QgsFields &fields, QGis::WkbType geometryType, const QgsCoordinateReferenceSystem *crs, bool overwrite=false, const QMap< QString, QVariant > *options=0, QProgressDialog *progress=0)
Create a empty layer and add fields to it.
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.
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
Allows creation of spatial index.
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.
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
WkbType
Used for symbology operations.
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)
static ImportError importLayer(QgsVectorLayer *layer, const QString &uri, const QString &providerKey, const QgsCoordinateReferenceSystem *destCRS, bool onlySelected=false, QString *errorMessage=0, bool skipAttributeCreation=false, QMap< QString, QVariant > *options=0, QProgressDialog *progress=0)
Write contents of vector layer to a different datasource.
QGis::WkbType wkbType() const
Returns the WKBType or WKBUnknown in case of error.
long featureCount(QgsSymbolV2 *symbol)
Number of features rendered with specified symbol.
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 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.
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
Find out whether this CRS is correctly initialised 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.