Skip to content

Commit

Permalink
workaround to create unique memory layer data sources (fixes #12206)
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Feb 17, 2015
1 parent 255cbd2 commit f64730e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -6343,6 +6343,9 @@ QgsVectorLayer *QgisApp::pasteToNewMemoryVector()

QString typeName = QString( QGis::featureType( wkbType ) ).replace( "WKB", "" );

static int pastedFeatureLayers = 0;
typeName += QString( "?memoryid=pasted_features%1" ).arg( ++pastedFeatureLayers );

QgsDebugMsg( QString( "output wkbType = %1 typeName = %2" ).arg( wkbType ).arg( typeName ) );

QString message;
Expand Down
3 changes: 2 additions & 1 deletion src/gui/qgsnewmemorylayerdialog.cpp
Expand Up @@ -64,7 +64,8 @@ QgsVectorLayer *QgsNewMemoryLayerDialog::runAndCreateLayer( QWidget *parent )
geomType = "point";
}

QString layerProperties = geomType + QString( "?crs=%1" ).arg( crsId );
static int createScratchLayers = 0;
QString layerProperties = QString( "%1?crs=%2&memoryid=scratchlayer%3" ).arg( geomType ).arg( crsId ).arg( ++createScratchLayers );
QString name = dialog.layerName().isEmpty() ? tr( "New scratch layer" ) : dialog.layerName();
QgsVectorLayer* newLayer = new QgsVectorLayer( layerProperties, name, QString( "memory" ) );
return newLayer;
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/roadgraph/exportdlg.cpp
Expand Up @@ -76,7 +76,8 @@ QgsVectorLayer* RgExportDlg::mapLayer() const
if ( layerId == QString( "-1" ) )
{
// create a temporary layer
myLayer = new QgsVectorLayer( "LineString?crs=epsg:4326", "shortest path", "memory" );
static int createdLayers = 0;
myLayer = new QgsVectorLayer( QString( "LineString?crs=epsg:4326&memoryid=rglayer%1" ).arg( ++createdLayers ), "shortest path", "memory" );

QgsVectorDataProvider *prov = myLayer->dataProvider();
if ( prov == NULL )
Expand Down

2 comments on commit f64730e

@nirvn
Copy link
Contributor

@nirvn nirvn commented on f64730e Feb 17, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jef-n , that's a great workaround, it'll do just fine. There might be issues with projects that keep - through the memory layer saver plugin - memory layers across sessions, but the chances of affecting people out there would be quite slim.

There is one memory layer creation scenario that wasn't fixed by your commit, that is the processing's save to memory layer output. Might be worth fixing that too.

@jef-n
Copy link
Member Author

@jef-n jef-n commented on f64730e Feb 17, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be implemented in e748281

Please sign in to comment.