29 #include <QProgressDialog> 31 #define FEATURE_BUFFER_SIZE 200 54 , mAttributeCount( -1 )
55 , mProgress( progress )
102 if ( providerKey ==
"ogr" )
105 if ( options->
contains(
"layerName" ) )
106 layerName = options->
value(
"layerName" ).toString();
109 uriUpdated +=
"|layername=";
110 uriUpdated += layerName;
119 if ( vectorProvider )
120 delete vectorProvider;
157 for (
int i = 0; i < attrs.
count(); ++i )
192 .arg( errors.
join(
"\n" ) );
225 bool skipAttributeCreation,
231 bool shallTransform =
false;
236 if ( destCRS && destCRS->
isValid() )
240 shallTransform =
true;
245 outputCRS = &layer->
crs();
249 bool overwrite =
false;
250 bool forceSinglePartGeom =
false;
253 overwrite = options->
take(
"overwrite" ).toBool();
254 forceSinglePartGeom = options->
take(
"forceSinglePartGeometryType" ).toBool();
264 for (
int fldIdx = 0; fldIdx < fields.
count(); ++fldIdx )
266 fields[fldIdx].setName( fields.
at( fldIdx ).
name().
toLower() );
269 if ( !forceSinglePartGeom )
299 new QgsVectorLayerImport( uri, providerKey, fields, wkbType, outputCRS, overwrite, options, progress );
313 errorMessage->
clear();
322 if ( skipAttributeCreation )
335 shallTransform =
false;
341 *errorMessage =
QObject::tr(
"Feature write errors:" );
349 bool cancelled =
false;
373 if ( onlySelected && !ids.
contains( fet.
id() ) )
376 if ( shallTransform )
390 QString msg =
QObject::tr(
"Failed to transform a point while drawing a feature with ID '%1'. Writing stopped. (Exception: %2)" )
394 *errorMessage +=
'\n' + msg;
399 if ( skipAttributeCreation )
438 if ( shallTransform )
447 *errorMessage +=
'\n' +
QObject::tr(
"Only %1 of %2 features written." ).
arg( n - errors ).
arg( n );
451 errorMessage->
clear();
457 else if ( errors > 0 )
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.
QGis::WkbType wkbType() const
Returns the WKBType or WKBUnknown in case of error.
QgsAttributes attributes() const
Returns the feature's attributes.
bool contains(const Key &key) const
QMap< int, int > mOldToNewAttrIdx
Map attribute indexes to new field indexes.
QString storageType() const
Returns the permanent storage type for this layer as a friendly name.
#define FEATURE_BUFFER_SIZE
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
QLibrary * providerLibrary(const QString &providerKey) 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=nullptr, QProgressDialog *progress=nullptr)
Create a empty layer and add fields to it.
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
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)
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...
virtual bool addFeatures(QgsFeatureList &flist)
Adds a list of features.
int count() const
Return number of items.
QString tr(const char *sourceText, const char *disambiguation, int n)
const QgsField & at(int i) const
Get field at particular index (must be in range 0..N-1)
QgsFields fields() const
Returns the list of fields of this layer.
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.
#define QgsDebugMsgLevel(str, level)
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.
QgsAttributeList attributeList() const
Returns list of attribute indexes.
QgsFeatureRequest & setFlags(const QgsFeatureRequest::Flags &flags)
Set flags that affect how features will be fetched.
virtual int capabilities() const
Returns a bitmask containing the supported capabilities Note, some capabilities may change depending ...
void setRange(int minimum, int maximum)
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.
QgsFeatureId id() const
Get the feature ID for this feature.
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.
const QgsFeatureIds & selectedFeaturesIds() const
Return reference to identifiers of selected features.
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
int transform(const QgsCoordinateTransform &ct)
Transform this geometry as described by CoordinateTransform ct.
void(*)() cast_to_fptr(void *p)
Custom exception class for Coordinate Reference System related exceptions.
QString providerType() const
Return the provider type for this layer.
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
bool isValid() const
Returns whether this CRS is correctly initialized and usable.