Skip to content

Commit 69aa115

Browse files
committedMay 4, 2015
Merge pull request #2026 from kiselev-dv/pull/osm-not-null
Add not-null option for osm export
2 parents eb964f9 + 57d5d07 commit 69aa115

File tree

3 files changed

+46
-13
lines changed

3 files changed

+46
-13
lines changed
 

‎src/analysis/openstreetmap/qgsosmdatabase.cpp

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,9 @@ bool QgsOSMDatabase::prepareStatements()
297297
return true;
298298
}
299299

300-
301-
302-
bool QgsOSMDatabase::exportSpatiaLite( ExportType type, const QString& tableName, const QStringList& tagKeys )
300+
bool QgsOSMDatabase::exportSpatiaLite( ExportType type, const QString& tableName,
301+
const QStringList& tagKeys,
302+
const QStringList& notNullTagKeys )
303303
{
304304
mError.clear();
305305

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

323323
if ( type == Polyline || type == Polygon )
324-
exportSpatiaLiteWays( type == Polygon, tableName, tagKeys );
324+
exportSpatiaLiteWays( type == Polygon, tableName, tagKeys, notNullTagKeys );
325325
else if ( type == Point )
326-
exportSpatiaLiteNodes( tableName, tagKeys );
326+
exportSpatiaLiteNodes( tableName, tagKeys, notNullTagKeys );
327327
else
328328
Q_ASSERT( false && "Unknown export type" );
329329

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

387387

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

411+
//check not null tags
412+
bool skipNull = false;
413+
for ( int i = 0; i < notNullTagKeys.count() && !skipNull; ++i )
414+
if ( !t.contains( notNullTagKeys[i] ) )
415+
skipNull = true;
416+
417+
if ( skipNull )
418+
continue;
419+
411420
QgsGeometry* geom = QgsGeometry::fromPoint( n.point() );
412421
int col = 0;
413422
sqlite3_bind_int64( stmtInsert, ++col, n.id() );
@@ -440,7 +449,9 @@ void QgsOSMDatabase::exportSpatiaLiteNodes( const QString& tableName, const QStr
440449
}
441450

442451

443-
void QgsOSMDatabase::exportSpatiaLiteWays( bool closed, const QString& tableName, const QStringList& tagKeys )
452+
void QgsOSMDatabase::exportSpatiaLiteWays( bool closed, const QString& tableName,
453+
const QStringList& tagKeys,
454+
const QStringList& notNullTagKeys )
444455
{
445456
Q_UNUSED( tagKeys );
446457

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

491+
//check not null tags
492+
bool skipNull = false;
493+
for ( int i = 0; i < notNullTagKeys.count() && !skipNull; ++i )
494+
if ( !t.contains( notNullTagKeys[i] ) )
495+
skipNull = true;
496+
497+
if ( skipNull )
498+
continue;
499+
480500
QgsGeometry* geom = closed ? QgsGeometry::fromPolygon( QgsPolygon() << polyline ) : QgsGeometry::fromPolyline( polyline );
481501
int col = 0;
482502
sqlite3_bind_int64( stmtInsert, ++col, w.id() );

‎src/analysis/openstreetmap/qgsosmdatabase.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,17 @@ class ANALYSIS_EXPORT QgsOSMDatabase
7979
// export to spatialite
8080

8181
enum ExportType { Point, Polyline, Polygon };
82-
bool exportSpatiaLite( ExportType type, const QString& tableName, const QStringList& tagKeys = QStringList() );
82+
bool exportSpatiaLite( ExportType type, const QString& tableName,
83+
const QStringList& tagKeys = QStringList(),
84+
const QStringList& noNullTagKeys = QStringList() );
8385

8486
protected:
8587
bool prepareStatements();
8688
int runCountStatement( const char* sql ) const;
8789
void deleteStatement( sqlite3_stmt*& stmt );
8890

89-
void exportSpatiaLiteNodes( const QString& tableName, const QStringList& tagKeys );
90-
void exportSpatiaLiteWays( bool closed, const QString& tableName, const QStringList& tagKeys );
91+
void exportSpatiaLiteNodes( const QString& tableName, const QStringList& tagKeys, const QStringList& notNullTagKeys = QStringList() );
92+
void exportSpatiaLiteWays( bool closed, const QString& tableName, const QStringList& tagKeys, const QStringList& notNullTagKeys = QStringList() );
9193
bool createSpatialTable( const QString& tableName, const QString& geometryType, const QStringList& tagKeys );
9294
bool createSpatialIndex( const QString& tableName );
9395

‎src/app/openstreetmap/qgsosmexportdialog.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ QgsOSMExportDialog::QgsOSMExportDialog( QWidget *parent ) :
4444
connect( btnUnselectAll, SIGNAL( clicked() ), this, SLOT( onUnselectAll() ) );
4545

4646
mTagsModel = new QStandardItemModel( this );
47-
mTagsModel->setHorizontalHeaderLabels( QStringList() << tr( "Tag" ) << tr( "Count" ) );
47+
mTagsModel->setHorizontalHeaderLabels( QStringList() << tr( "Tag" ) << tr( "Count" ) << tr( "Not null" ) );
4848
viewTags->setModel( mTagsModel );
4949
}
5050

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

109-
mTagsModel->setColumnCount( 2 );
109+
mTagsModel->setColumnCount( 3 );
110110
mTagsModel->setRowCount( pairs.count() );
111111

112112
for ( int i = 0; i < pairs.count(); ++i )
@@ -115,9 +115,15 @@ void QgsOSMExportDialog::onLoadTags()
115115
QStandardItem* item = new QStandardItem( p.first );
116116
item->setCheckable( true );
117117
mTagsModel->setItem( i, 0, item );
118+
118119
QStandardItem* item2 = new QStandardItem();
119120
item2->setData( p.second, Qt::DisplayRole );
120121
mTagsModel->setItem( i, 1, item2 );
122+
123+
QStandardItem* item3 = new QStandardItem();
124+
item3->setData( "Not null", Qt::DisplayRole );
125+
item3->setCheckable( true );
126+
mTagsModel->setItem( i, 2, item3 );
121127
}
122128

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

146152
QStringList tagKeys;
153+
QStringList notNullTagKeys;
147154

148155
for ( int i = 0; i < mTagsModel->rowCount(); ++i )
149156
{
150157
QStandardItem* item = mTagsModel->item( i, 0 );
151158
if ( item->checkState() == Qt::Checked )
152159
tagKeys << item->text();
160+
161+
QStandardItem* item2 = mTagsModel->item( i, 2 );
162+
if ( item2->checkState() == Qt::Checked )
163+
notNullTagKeys << item->text();
153164
}
154165

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.