Skip to content
Permalink
Browse files

Implement import layer feature for OGR provider using QgsVectorFileWr…

…iter
  • Loading branch information
brushtyler committed Aug 18, 2011
1 parent 097eefc commit f0f1b5e3b21ce797fc528282805c37a37f4cf423
Showing with 60 additions and 1 deletion.
  1. +48 −1 src/providers/ogr/qgsogrprovider.cpp
  2. +12 −0 src/providers/ogr/qgsogrprovider.h
@@ -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";
@@ -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 ),
@@ -2362,3 +2398,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 );
}
@@ -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;
@@ -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

0 comments on commit f0f1b5e

Please sign in to comment.
You can’t perform that action at this time.