Skip to content
Permalink
Browse files

fix set crs to OGR data items (broken in 04aab29)

  • Loading branch information
brushtyler committed May 28, 2012
1 parent 149c96a commit 9859709e924be5d0193fde5cc1fd82b6e332d879
Showing with 5 additions and 6 deletions.
  1. +5 −6 src/providers/ogr/qgsogrdataitems.cpp
@@ -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 );
@@ -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 );
@@ -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;
}

0 comments on commit 9859709

Please sign in to comment.
You can’t perform that action at this time.