Skip to content

Commit

Permalink
fix set crs to OGR data items (broken in 04aab29)
Browse files Browse the repository at this point in the history
  • Loading branch information
brushtyler committed May 28, 2012
1 parent 149c96a commit 9859709
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/providers/ogr/qgsogrdataitems.cpp
Expand Up @@ -78,16 +78,15 @@ bool QgsOgrLayerItem::setCrs( QgsCoordinateReferenceSystem crs )
// we are able to assign CRS only to shapefiles :-(
if ( driverName == "ESRI Shapefile" )
{
// QString layerName = mPath.left( mPath.indexOf( ".shp", Qt::CaseInsensitive ) );
QString lyrName = layerName();
QString layerName = mPath.left( mPath.indexOf( ".shp", Qt::CaseInsensitive ) );
QString wkt = crs.toWkt();

// save ordinary .prj file
OGRSpatialReferenceH hSRS = OSRNewSpatialReference( wkt.toLocal8Bit().data() );
OSRMorphToESRI( hSRS ); // this is the important stuff for shapefile .prj
char* pszOutWkt = NULL;
OSRExportToWkt( hSRS, &pszOutWkt );
QFile prjFile( lyrName + ".prj" );
QFile prjFile( layerName + ".prj" );
if ( prjFile.open( QIODevice::WriteOnly ) )
{
QTextStream prjStream( &prjFile );
Expand All @@ -96,14 +95,14 @@ bool QgsOgrLayerItem::setCrs( QgsCoordinateReferenceSystem crs )
}
else
{
QgsMessageLog::logMessage( tr( "Couldn't open file %1.prj" ).arg( lyrName ), tr( "OGR" ) );
QgsMessageLog::logMessage( tr( "Couldn't open file %1.prj" ).arg( layerName ), tr( "OGR" ) );
return false;
}
OSRDestroySpatialReference( hSRS );
CPLFree( pszOutWkt );

// save qgis-specific .qpj file (maybe because of better wkt compatibility?)
QFile qpjFile( lyrName + ".qpj" );
QFile qpjFile( layerName + ".qpj" );
if ( qpjFile.open( QIODevice::WriteOnly ) )
{
QTextStream qpjStream( &qpjFile );
Expand All @@ -112,7 +111,7 @@ bool QgsOgrLayerItem::setCrs( QgsCoordinateReferenceSystem crs )
}
else
{
QgsMessageLog::logMessage( tr( "Couldn't open file %1.qpj" ).arg( lyrName ), tr( "OGR" ) );
QgsMessageLog::logMessage( tr( "Couldn't open file %1.qpj" ).arg( layerName ), tr( "OGR" ) );
return false;
}

Expand Down

0 comments on commit 9859709

Please sign in to comment.