Skip to content
Permalink
Browse files

Merge pull request #2026 from kiselev-dv/pull/osm-not-null

Add not-null option for osm export
  • Loading branch information
wonder-sk committed May 4, 2015
2 parents eb964f9 + 57d5d07 commit 69aa1152945d0d89644fe7aa6d16c7bd2c1069d3
@@ -297,9 +297,9 @@ bool QgsOSMDatabase::prepareStatements()
return true;
}



bool QgsOSMDatabase::exportSpatiaLite( ExportType type, const QString& tableName, const QStringList& tagKeys )
bool QgsOSMDatabase::exportSpatiaLite( ExportType type, const QString& tableName,
const QStringList& tagKeys,
const QStringList& notNullTagKeys )
{
mError.clear();

@@ -321,9 +321,9 @@ bool QgsOSMDatabase::exportSpatiaLite( ExportType type, const QString& tableName
Q_UNUSED( retX );

if ( type == Polyline || type == Polygon )
exportSpatiaLiteWays( type == Polygon, tableName, tagKeys );
exportSpatiaLiteWays( type == Polygon, tableName, tagKeys, notNullTagKeys );
else if ( type == Point )
exportSpatiaLiteNodes( tableName, tagKeys );
exportSpatiaLiteNodes( tableName, tagKeys, notNullTagKeys );
else
Q_ASSERT( false && "Unknown export type" );

@@ -385,7 +385,7 @@ bool QgsOSMDatabase::createSpatialIndex( const QString& tableName )
}


void QgsOSMDatabase::exportSpatiaLiteNodes( const QString& tableName, const QStringList& tagKeys )
void QgsOSMDatabase::exportSpatiaLiteNodes( const QString& tableName, const QStringList& tagKeys, const QStringList& notNullTagKeys )
{
QString sqlInsertPoint = QString( "INSERT INTO %1 VALUES (?" ).arg( quotedIdentifier( tableName ) );
for ( int i = 0; i < tagKeys.count(); ++i )
@@ -408,6 +408,15 @@ void QgsOSMDatabase::exportSpatiaLiteNodes( const QString& tableName, const QStr
if ( t.count() == 0 )
continue;

//check not null tags
bool skipNull = false;
for ( int i = 0; i < notNullTagKeys.count() && !skipNull; ++i )
if ( !t.contains( notNullTagKeys[i] ) )
skipNull = true;

if ( skipNull )
continue;

QgsGeometry* geom = QgsGeometry::fromPoint( n.point() );
int col = 0;
sqlite3_bind_int64( stmtInsert, ++col, n.id() );
@@ -440,7 +449,9 @@ void QgsOSMDatabase::exportSpatiaLiteNodes( const QString& tableName, const QStr
}


void QgsOSMDatabase::exportSpatiaLiteWays( bool closed, const QString& tableName, const QStringList& tagKeys )
void QgsOSMDatabase::exportSpatiaLiteWays( bool closed, const QString& tableName,
const QStringList& tagKeys,
const QStringList& notNullTagKeys )
{
Q_UNUSED( tagKeys );

@@ -477,6 +488,15 @@ void QgsOSMDatabase::exportSpatiaLiteWays( bool closed, const QString& tableName
if ( closed != isArea )
continue; // skip if it's not what we're looking for

//check not null tags
bool skipNull = false;
for ( int i = 0; i < notNullTagKeys.count() && !skipNull; ++i )
if ( !t.contains( notNullTagKeys[i] ) )
skipNull = true;

if ( skipNull )
continue;

QgsGeometry* geom = closed ? QgsGeometry::fromPolygon( QgsPolygon() << polyline ) : QgsGeometry::fromPolyline( polyline );
int col = 0;
sqlite3_bind_int64( stmtInsert, ++col, w.id() );
@@ -79,15 +79,17 @@ class ANALYSIS_EXPORT QgsOSMDatabase
// export to spatialite

enum ExportType { Point, Polyline, Polygon };
bool exportSpatiaLite( ExportType type, const QString& tableName, const QStringList& tagKeys = QStringList() );
bool exportSpatiaLite( ExportType type, const QString& tableName,
const QStringList& tagKeys = QStringList(),
const QStringList& noNullTagKeys = QStringList() );

protected:
bool prepareStatements();
int runCountStatement( const char* sql ) const;
void deleteStatement( sqlite3_stmt*& stmt );

void exportSpatiaLiteNodes( const QString& tableName, const QStringList& tagKeys );
void exportSpatiaLiteWays( bool closed, const QString& tableName, const QStringList& tagKeys );
void exportSpatiaLiteNodes( const QString& tableName, const QStringList& tagKeys, const QStringList& notNullTagKeys = QStringList() );
void exportSpatiaLiteWays( bool closed, const QString& tableName, const QStringList& tagKeys, const QStringList& notNullTagKeys = QStringList() );
bool createSpatialTable( const QString& tableName, const QString& geometryType, const QStringList& tagKeys );
bool createSpatialIndex( const QString& tableName );

@@ -44,7 +44,7 @@ QgsOSMExportDialog::QgsOSMExportDialog( QWidget *parent ) :
connect( btnUnselectAll, SIGNAL( clicked() ), this, SLOT( onUnselectAll() ) );

mTagsModel = new QStandardItemModel( this );
mTagsModel->setHorizontalHeaderLabels( QStringList() << tr( "Tag" ) << tr( "Count" ) );
mTagsModel->setHorizontalHeaderLabels( QStringList() << tr( "Tag" ) << tr( "Count" ) << tr( "Not null" ) );
viewTags->setModel( mTagsModel );
}

@@ -106,7 +106,7 @@ void QgsOSMExportDialog::onLoadTags()
QList<QgsOSMTagCountPair> pairs = mDatabase->usedTags( !radPoints->isChecked() );
mDatabase->close();

mTagsModel->setColumnCount( 2 );
mTagsModel->setColumnCount( 3 );
mTagsModel->setRowCount( pairs.count() );

for ( int i = 0; i < pairs.count(); ++i )
@@ -115,9 +115,15 @@ void QgsOSMExportDialog::onLoadTags()
QStandardItem* item = new QStandardItem( p.first );
item->setCheckable( true );
mTagsModel->setItem( i, 0, item );

QStandardItem* item2 = new QStandardItem();
item2->setData( p.second, Qt::DisplayRole );
mTagsModel->setItem( i, 1, item2 );

QStandardItem* item3 = new QStandardItem();
item3->setData( "Not null", Qt::DisplayRole );
item3->setCheckable( true );
mTagsModel->setItem( i, 2, item3 );
}

viewTags->resizeColumnToContents( 0 );
@@ -144,15 +150,20 @@ void QgsOSMExportDialog::onOK()
QApplication::setOverrideCursor( Qt::WaitCursor );

QStringList tagKeys;
QStringList notNullTagKeys;

for ( int i = 0; i < mTagsModel->rowCount(); ++i )
{
QStandardItem* item = mTagsModel->item( i, 0 );
if ( item->checkState() == Qt::Checked )
tagKeys << item->text();

QStandardItem* item2 = mTagsModel->item( i, 2 );
if ( item2->checkState() == Qt::Checked )
notNullTagKeys << item->text();
}

bool res = mDatabase->exportSpatiaLite( type, editLayerName->text(), tagKeys );
bool res = mDatabase->exportSpatiaLite( type, editLayerName->text(), tagKeys, notNullTagKeys );

// load the layer into canvas if that was requested
if ( chkLoadWhenFinished->isChecked() )

0 comments on commit 69aa115

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