Skip to content

Commit

Permalink
Implement import layer feature for OGR provider using QgsVectorFileWr…
Browse files Browse the repository at this point in the history
…iter
  • Loading branch information
brushtyler committed Aug 23, 2011
1 parent 9a2972a commit 593ea7e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
49 changes: 48 additions & 1 deletion src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -42,7 +42,6 @@ email : sherman at mrcc.com
#include "qgsfield.h"
#include "qgsgeometry.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsvectorfilewriter.h"
#include "qgsvectorlayer.h"

static const QString TEXT_PROVIDER_KEY = "ogr";
Expand Down Expand Up @@ -83,6 +82,43 @@ class QgsCPLErrorHandler
}
};



QgsVectorFileWriter::WriterError
QgsOgrProvider::importVector(
QgsVectorLayer *layer,
const QString& fileName,
const QgsCoordinateReferenceSystem *destCRS,
bool onlySelected,
QString *errorMessage,
bool skipAttributeCreation,
const QMap<QString,QVariant> *options )
{
QString encoding;
QString driverName = "ESRI Shapefile";
QStringList dsOptions, layerOptions;

if ( options )
{
if ( options->contains( "fileEncoding" ) )
encoding = options->value( "fileEncoding" ).toString();

if ( options->contains( "driverName" ) )
driverName = options->value( "driverName" ).toString();

if ( options->contains( "datasourceOptions" ) )
dsOptions << options->value( "datasourceOptions" ).toStringList();

if ( options->contains( "layerOptions" ) )
layerOptions << options->value( "layerOptions" ).toStringList();
}

return QgsVectorFileWriter::writeAsVectorFormat(
layer, fileName, encoding, destCRS, driverName, onlySelected,
errorMessage, dsOptions, layerOptions, skipAttributeCreation );
}


QgsOgrProvider::QgsOgrProvider( QString const & uri )
: QgsVectorDataProvider( uri ),
ogrDataSource( 0 ),
Expand Down Expand Up @@ -2369,3 +2405,14 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
return 0;
}

QGISEXTERN int importVector(
QgsVectorLayer *layer,
const QString& uri,
const QgsCoordinateReferenceSystem *destCRS,
bool onlySelected,
QString *errorMessage,
bool skipAttributeCreation,
const QMap<QString,QVariant> *options )
{
return QgsOgrProvider::importVector( layer, uri, destCRS, onlySelected, errorMessage, skipAttributeCreation, options );
}
12 changes: 12 additions & 0 deletions src/providers/ogr/qgsogrprovider.h
Expand Up @@ -18,6 +18,7 @@ email : sherman at mrcc.com
#include "qgsdataitem.h"
#include "qgsrectangle.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorfilewriter.h"

class QgsFeature;
class QgsField;
Expand All @@ -34,6 +35,17 @@ class QgsOgrProvider : public QgsVectorDataProvider

public:

/** convert a vector layer to a vector file */
static QgsVectorFileWriter::WriterError importVector(
QgsVectorLayer *layer,
const QString& fileName,
const QgsCoordinateReferenceSystem *destCRS,
bool onlySelected,
QString *errorMessage,
bool skipAttributeCreation,
const QMap<QString,QVariant> *options
);

/**
* Constructor of the vector provider
* @param uri uniform resource locator (URI) for a dataset
Expand Down

0 comments on commit 593ea7e

Please sign in to comment.