Skip to content

Commit

Permalink
Add option in json exporter to not transform geometries
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Oct 31, 2019
1 parent e3371fd commit 2f79dcc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
7 changes: 1 addition & 6 deletions src/core/qgsjsonutils.cpp
Expand Up @@ -43,11 +43,6 @@ QgsJsonExporter::QgsJsonExporter( QgsVectorLayer *vectorLayer, int precision )
mTransform.setDestinationCrs( QgsCoordinateReferenceSystem( 4326, QgsCoordinateReferenceSystem::EpsgCrsId ) );
}

void QgsJsonExporter::setDestinationCrs( const QgsCoordinateReferenceSystem &crs )
{
mTransform.setDestinationCrs( crs );
}

void QgsJsonExporter::setVectorLayer( QgsVectorLayer *vectorLayer )
{
mLayer = vectorLayer;
Expand Down Expand Up @@ -112,7 +107,7 @@ json QgsJsonExporter::exportFeatureToJsonObject( const QgsFeature &feature, cons
try
{
QgsGeometry transformed = geom;
if ( transformed.transform( mTransform ) == 0 )
if ( mTransformGeometries && transformed.transform( mTransform ) == 0 )
geom = transformed;
}
catch ( QgsCsException &cse )
Expand Down
16 changes: 9 additions & 7 deletions src/core/qgsjsonutils.h
Expand Up @@ -146,20 +146,20 @@ class CORE_EXPORT QgsJsonExporter
*/
void setSourceCrs( const QgsCoordinateReferenceSystem &crs );

/**
* Sets the destination CRS for writing feature geometries.
* \param crs destination CRS for output feature geometries
* \since QGIS 3.10
*/
void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );

/**
* Returns the source CRS for feature geometries. The source CRS must be set if geometries are to be
* correctly automatically reprojected to WGS 84, to match GeoJSON specifications.
* \see setSourceCrs()
*/
QgsCoordinateReferenceSystem sourceCrs() const;

/**
* Sets whether geometries should be transformed in EPSG 4326 (default
* behavior) or just keep as it is.
* \since QGIS 3.12
*/
void setTransformGeometries( bool activate ) { mTransformGeometries = activate; }

/**
* Sets the list of attributes to include in the JSON exports.
* \param attributes list of attribute indexes, or an empty list to include all
Expand Down Expand Up @@ -277,6 +277,8 @@ class CORE_EXPORT QgsJsonExporter
QgsCoordinateTransform mTransform;

bool mAttributeDisplayName = false;

bool mTransformGeometries = true;
};

/**
Expand Down

0 comments on commit 2f79dcc

Please sign in to comment.