@@ -78,15 +78,16 @@ bool QgsOgrLayerItem::setCrs( QgsCoordinateReferenceSystem crs )
7878 // we are able to assign CRS only to shapefiles :-(
7979 if ( driverName == " ESRI Shapefile" )
8080 {
81- QString layerName = mPath .left ( mPath .indexOf ( " .shp" , Qt::CaseInsensitive ) );
81+ // QString layerName = mPath.left( mPath.indexOf( ".shp", Qt::CaseInsensitive ) );
82+ QString lyrName = layerName ();
8283 QString wkt = crs.toWkt ();
8384
8485 // save ordinary .prj file
8586 OGRSpatialReferenceH hSRS = OSRNewSpatialReference ( wkt.toLocal8Bit ().data () );
8687 OSRMorphToESRI ( hSRS ); // this is the important stuff for shapefile .prj
8788 char * pszOutWkt = NULL ;
8889 OSRExportToWkt ( hSRS, &pszOutWkt );
89- QFile prjFile ( layerName + " .prj" );
90+ QFile prjFile ( lyrName + " .prj" );
9091 if ( prjFile.open ( QIODevice::WriteOnly ) )
9192 {
9293 QTextStream prjStream ( &prjFile );
@@ -95,14 +96,14 @@ bool QgsOgrLayerItem::setCrs( QgsCoordinateReferenceSystem crs )
9596 }
9697 else
9798 {
98- QgsMessageLog::logMessage ( tr ( " Couldn't open file %1.prj" ).arg ( layerName ), tr ( " OGR" ) );
99+ QgsMessageLog::logMessage ( tr ( " Couldn't open file %1.prj" ).arg ( lyrName ), tr ( " OGR" ) );
99100 return false ;
100101 }
101102 OSRDestroySpatialReference ( hSRS );
102103 CPLFree ( pszOutWkt );
103104
104105 // save qgis-specific .qpj file (maybe because of better wkt compatibility?)
105- QFile qpjFile ( layerName + " .qpj" );
106+ QFile qpjFile ( lyrName + " .qpj" );
106107 if ( qpjFile.open ( QIODevice::WriteOnly ) )
107108 {
108109 QTextStream qpjStream ( &qpjFile );
@@ -111,7 +112,7 @@ bool QgsOgrLayerItem::setCrs( QgsCoordinateReferenceSystem crs )
111112 }
112113 else
113114 {
114- QgsMessageLog::logMessage ( tr ( " Couldn't open file %1.qpj" ).arg ( layerName ), tr ( " OGR" ) );
115+ QgsMessageLog::logMessage ( tr ( " Couldn't open file %1.qpj" ).arg ( lyrName ), tr ( " OGR" ) );
115116 return false ;
116117 }
117118
@@ -123,6 +124,15 @@ bool QgsOgrLayerItem::setCrs( QgsCoordinateReferenceSystem crs )
123124 return false ;
124125}
125126
127+ QString QgsOgrLayerItem::layerName () const
128+ {
129+ QFileInfo info ( name () );
130+ if ( info.suffix () == " gz" )
131+ return info.baseName ();
132+ else
133+ return info.completeBaseName ();
134+ }
135+
126136// -------
127137
128138static QgsOgrLayerItem* dataItemForLayer ( QgsDataItem* parentItem, QString name, QString path, OGRDataSourceH hDataSource, int layerId )
0 commit comments