Navigation Menu

Skip to content

Commit

Permalink
Always use the same method to convert QgsCoordinateReferenceSystem
Browse files Browse the repository at this point in the history
to OGR SRS
  • Loading branch information
nyalldawson committed Aug 8, 2021
1 parent fbee77c commit cae6c8d
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 24 deletions.
3 changes: 1 addition & 2 deletions src/app/dwg/qgsdwgimporter.cpp
Expand Up @@ -71,14 +71,13 @@ QgsDwgImporter::QgsDwgImporter( const QString &database, const QgsCoordinateRefe
, mSplineSegs( 8 )
, mBlockHandle( -1 )
, mCrs( crs.srsid() )
, mCrsH( nullptr )
, mUseCurves( true )
, mEntities( 0 )
{
QgsDebugCall;

QString crswkt( crs.toWkt( QgsCoordinateReferenceSystem::WKT_PREFERRED_GDAL ) );
mCrsH = OSRNewSpatialReference( crswkt.toLocal8Bit().constData() );
mCrsH = QgsOgrUtils::crsToOGRSpatialReference( crs );
QgsDebugMsg( QStringLiteral( "CRS %1[%2]: %3" ).arg( mCrs ).arg( ( qint64 ) mCrsH, 0, 16 ).arg( crswkt ) );
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/dwg/qgsdwgimporter.h
Expand Up @@ -211,7 +211,7 @@ class QgsDwgImporter : public DRW_Interface
int mSplineSegs;
int mBlockHandle;
int mCrs;
OGRSpatialReferenceH mCrsH;
OGRSpatialReferenceH mCrsH = nullptr;
bool mUseCurves;

QHash<QString, QString> mLayerColor;
Expand Down
8 changes: 1 addition & 7 deletions src/core/providers/ogr/qgsogrproviderutils.cpp
Expand Up @@ -794,7 +794,6 @@ bool QgsOgrProviderUtils::createEmptyDataSource( const QString &uri,
}

//consider spatial reference system
OGRSpatialReferenceH reference = nullptr;

QgsCoordinateReferenceSystem mySpatialRefSys;
if ( srs.isValid() )
Expand All @@ -806,12 +805,7 @@ bool QgsOgrProviderUtils::createEmptyDataSource( const QString &uri,
mySpatialRefSys.validate();
}

QString myWkt = mySpatialRefSys.toWkt( QgsCoordinateReferenceSystem::WKT_PREFERRED_GDAL );

if ( !myWkt.isNull() && myWkt.length() != 0 )
{
reference = OSRNewSpatialReference( myWkt.toLocal8Bit().data() );
}
OGRSpatialReferenceH reference = QgsOgrUtils::crsToOGRSpatialReference( mySpatialRefSys );

// Map the qgis geometry type to the OGR geometry type
OGRwkbGeometryType OGRvectortype = wkbUnknown;
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsofflineediting.cpp
Expand Up @@ -674,7 +674,7 @@ void QgsOfflineEditing::convertToOfflineLayer( QgsVectorLayer *layer, sqlite3 *d
}

OGRSFDriverH hDriver = nullptr;
OGRSpatialReferenceH hSRS = OSRNewSpatialReference( layer->crs().toWkt( QgsCoordinateReferenceSystem::WKT_PREFERRED_GDAL ).toLocal8Bit().data() );
OGRSpatialReferenceH hSRS = QgsOgrUtils::crsToOGRSpatialReference( layer->crs() );
gdal::ogr_datasource_unique_ptr hDS( OGROpen( offlineDbPath.toUtf8().constData(), true, &hDriver ) );
OGRLayerH hLayer = OGR_DS_CreateLayer( hDS.get(), tableName.toUtf8().constData(), hSRS, static_cast<OGRwkbGeometryType>( layer->wkbType() ), options );
CSLDestroy( options );
Expand Down
13 changes: 2 additions & 11 deletions src/core/qgsvectorfilewriter.cpp
Expand Up @@ -430,16 +430,7 @@ void QgsVectorFileWriter::init( QString vectorFileName,
}
}

if ( srs.isValid() )
{
QString srsWkt = srs.toWkt( QgsCoordinateReferenceSystem::WKT_PREFERRED_GDAL );
QgsDebugMsgLevel( "WKT to save as is " + srsWkt, 2 );
mOgrRef = OSRNewSpatialReference( srsWkt.toLocal8Bit().constData() );
if ( mOgrRef )
{
OSRSetAxisMappingStrategy( mOgrRef, OAMS_TRADITIONAL_GIS_ORDER );
}
}
mOgrRef = QgsOgrUtils::crsToOGRSpatialReference( srs );

// datasource created, now create the output layer
OGRwkbGeometryType wkbType = ogrTypeFromWkbType( geometryType );
Expand Down Expand Up @@ -2895,7 +2886,7 @@ QgsVectorFileWriter::~QgsVectorFileWriter()

if ( mOgrRef )
{
OSRDestroySpatialReference( mOgrRef );
OSRRelease( mOgrRef );
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/gui/qgsnewgeopackagelayerdialog.cpp
Expand Up @@ -412,8 +412,7 @@ bool QgsNewGeoPackageLayerDialog::apply()
QgsCoordinateReferenceSystem srs = mCrsSelector->crs();
if ( wkbType != wkbNone && srs.isValid() )
{
QString srsWkt = srs.toWkt( QgsCoordinateReferenceSystem::WKT_PREFERRED_GDAL );
hSRS = OSRNewSpatialReference( srsWkt.toLocal8Bit().data() );
hSRS = QgsOgrUtils::crsToOGRSpatialReference( srs );
}

// Set options
Expand Down

0 comments on commit cae6c8d

Please sign in to comment.