@@ -78,15 +78,16 @@ bool QgsOgrLayerItem::setCrs( QgsCoordinateReferenceSystem crs )
78
78
// we are able to assign CRS only to shapefiles :-(
79
79
if ( driverName == " ESRI Shapefile" )
80
80
{
81
- QString layerName = mPath .left ( mPath .indexOf ( " .shp" , Qt::CaseInsensitive ) );
81
+ // QString layerName = mPath.left( mPath.indexOf( ".shp", Qt::CaseInsensitive ) );
82
+ QString lyrName = layerName ();
82
83
QString wkt = crs.toWkt ();
83
84
84
85
// save ordinary .prj file
85
86
OGRSpatialReferenceH hSRS = OSRNewSpatialReference ( wkt.toLocal8Bit ().data () );
86
87
OSRMorphToESRI ( hSRS ); // this is the important stuff for shapefile .prj
87
88
char * pszOutWkt = NULL ;
88
89
OSRExportToWkt ( hSRS, &pszOutWkt );
89
- QFile prjFile ( layerName + " .prj" );
90
+ QFile prjFile ( lyrName + " .prj" );
90
91
if ( prjFile.open ( QIODevice::WriteOnly ) )
91
92
{
92
93
QTextStream prjStream ( &prjFile );
@@ -95,14 +96,14 @@ bool QgsOgrLayerItem::setCrs( QgsCoordinateReferenceSystem crs )
95
96
}
96
97
else
97
98
{
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" ) );
99
100
return false ;
100
101
}
101
102
OSRDestroySpatialReference ( hSRS );
102
103
CPLFree ( pszOutWkt );
103
104
104
105
// save qgis-specific .qpj file (maybe because of better wkt compatibility?)
105
- QFile qpjFile ( layerName + " .qpj" );
106
+ QFile qpjFile ( lyrName + " .qpj" );
106
107
if ( qpjFile.open ( QIODevice::WriteOnly ) )
107
108
{
108
109
QTextStream qpjStream ( &qpjFile );
@@ -111,7 +112,7 @@ bool QgsOgrLayerItem::setCrs( QgsCoordinateReferenceSystem crs )
111
112
}
112
113
else
113
114
{
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" ) );
115
116
return false ;
116
117
}
117
118
@@ -123,6 +124,15 @@ bool QgsOgrLayerItem::setCrs( QgsCoordinateReferenceSystem crs )
123
124
return false ;
124
125
}
125
126
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
+
126
136
// -------
127
137
128
138
static QgsOgrLayerItem* dataItemForLayer ( QgsDataItem* parentItem, QString name, QString path, OGRDataSourceH hDataSource, int layerId )
0 commit comments