Skip to content

Commit

Permalink
merge import_layer branch
Browse files Browse the repository at this point in the history
  • Loading branch information
brushtyler committed Sep 13, 2011
2 parents f2b6876 + 6eb406b commit 262ec3f
Show file tree
Hide file tree
Showing 15 changed files with 1,519 additions and 44 deletions.
1 change: 1 addition & 0 deletions python/core/core.sip
Expand Up @@ -84,6 +84,7 @@
%Include qgsvectordataprovider.sip %Include qgsvectordataprovider.sip
%Include qgsvectorfilewriter.sip %Include qgsvectorfilewriter.sip
%Include qgsvectorlayer.sip %Include qgsvectorlayer.sip
%Include qgsvectorlayerimport.sip
%Include qgsvectoroverlay.sip %Include qgsvectoroverlay.sip


%Include qgsnetworkaccessmanager.sip %Include qgsnetworkaccessmanager.sip
Expand Down
2 changes: 0 additions & 2 deletions python/core/qgsproviderregistry.sip
Expand Up @@ -60,8 +60,6 @@ class QgsProviderRegistry
* @note this method was added in QGIS 1.1 * @note this method was added in QGIS 1.1
*/ */
virtual QString protocolDrivers() const; virtual QString protocolDrivers() const;




private: private:


Expand Down
65 changes: 65 additions & 0 deletions python/core/qgsvectorlayerimport.sip
@@ -0,0 +1,65 @@

/**
There are two possibilities how to use this class:
1. static call to QgsVectorLayerImport::importLayer(...) which saves the whole vector layer
2. create an instance of the class and issue calls to addFeature(...)
*/
class QgsVectorLayerImport
{
%TypeHeaderCode
#include <qgsvectorlayerimport.h>
#include <qgsfield.h>
%End

public:

enum ImportError
{
NoError = 0,
ErrDriverNotFound,
ErrCreateDataSource,
ErrCreateLayer,
ErrAttributeTypeUnsupported,
ErrAttributeCreationFailed,
ErrProjection,
ErrFeatureWriteFailed,
ErrInvalidLayer,
ErrInvalidProvider,
ErrProviderUnsupportedFeature,
ErrConnectionFailed
};

/** Write contents of vector layer to a different datasource */
static ImportError importLayer( QgsVectorLayer* layer,
const QString& uri,
const QString& providerKey,
const QgsCoordinateReferenceSystem *destCRS,
bool onlySelected = FALSE,
QString *errorMessage /Out/ = 0,
bool skipAttributeCreation = FALSE,
QMap<QString, QVariant> *options = 0
);

/** create a empty layer and add fields to it */
QgsVectorLayerImport( const QString &uri,
const QString &provider,
const QgsFieldMap& fields,
QGis::WkbType geometryType,
const QgsCoordinateReferenceSystem* crs,
bool overwrite = false,
const QMap<QString, QVariant> *options = 0
);

/** checks whether there were any errors */
ImportError hasError();

/** retrieves error message */
QString errorMessage();

/** add feature to the new created layer */
bool addFeature( QgsFeature& feature );

/** close the new created layer */
~QgsVectorLayerImport();
};

2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -101,6 +101,7 @@ SET(QGIS_CORE_SRCS
qgsvectordataprovider.cpp qgsvectordataprovider.cpp
qgsvectorfilewriter.cpp qgsvectorfilewriter.cpp
qgsvectorlayer.cpp qgsvectorlayer.cpp
qgsvectorlayerimport.cpp
qgsvectorlayerjoinbuffer.cpp qgsvectorlayerjoinbuffer.cpp
qgsvectorlayerundocommand.cpp qgsvectorlayerundocommand.cpp
qgsvectoroverlay.cpp qgsvectoroverlay.cpp
Expand Down Expand Up @@ -333,6 +334,7 @@ SET(QGIS_CORE_HDRS
qgsvectordataprovider.h qgsvectordataprovider.h
qgsvectorfilewriter.h qgsvectorfilewriter.h
qgsvectorlayer.h qgsvectorlayer.h
qgsvectorlayerimport.h
qgsvectoroverlay.h qgsvectoroverlay.h
qgstolerance.h qgstolerance.h


Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsproviderregistry.cpp
Expand Up @@ -30,6 +30,7 @@
#include "qgslogger.h" #include "qgslogger.h"
#include "qgsmessageoutput.h" #include "qgsmessageoutput.h"
#include "qgsprovidermetadata.h" #include "qgsprovidermetadata.h"
#include "qgsvectorlayer.h"




// typedefs for provider plugin functions of interest // typedefs for provider plugin functions of interest
Expand Down Expand Up @@ -468,7 +469,7 @@ void * QgsProviderRegistry::function( QString const & providerKey,
return 0; return 0;
} }


QLibrary *QgsProviderRegistry::providerLibrary( QString const & providerKey ) QLibrary *QgsProviderRegistry::providerLibrary( QString const & providerKey ) const
{ {
QString lib = library( providerKey ); QString lib = library( providerKey );


Expand Down
5 changes: 3 additions & 2 deletions src/core/qgsproviderregistry.h
Expand Up @@ -28,7 +28,8 @@


class QgsDataProvider; class QgsDataProvider;
class QgsProviderMetadata; class QgsProviderMetadata;

class QgsVectorLayer;
class QgsCoordinateReferenceSystem;




/** \ingroup core /** \ingroup core
Expand Down Expand Up @@ -78,7 +79,7 @@ class CORE_EXPORT QgsProviderRegistry
void *function( const QString & providerKey, void *function( const QString & providerKey,
const QString & functionName ); const QString & functionName );


QLibrary *providerLibrary( const QString & providerKey ); QLibrary *providerLibrary( const QString & providerKey ) const;


/** Return list of available providers by their keys */ /** Return list of available providers by their keys */
QStringList providerList() const; QStringList providerList() const;
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsvectorfilewriter.h
Expand Up @@ -116,6 +116,8 @@ class CORE_EXPORT QgsVectorFileWriter
/** add feature to the currently opened shapefile */ /** add feature to the currently opened shapefile */
bool addFeature( QgsFeature& feature ); bool addFeature( QgsFeature& feature );


QMap<int, int> attrIdxToOgrIdx() { return mAttrIdxToOgrIdx; }

/** close opened shapefile for writing */ /** close opened shapefile for writing */
~QgsVectorFileWriter(); ~QgsVectorFileWriter();


Expand Down

0 comments on commit 262ec3f

Please sign in to comment.