Skip to content

Commit

Permalink
Fix #21160: fix geojson in protocol and file twice
Browse files Browse the repository at this point in the history
GDAL/OGR has two geojson related drivers now: GeoJSON and
GeoJSONSeq, see https://www.gdal.org/drv_geojsonseq.html

This commit makes it possible to open GeoJSONSeq (geojsonl and
geojsons and json) files as protocols/streams. And write them
as *.json.
  • Loading branch information
rduivenvoorde authored and nyalldawson committed Mar 10, 2019
1 parent fa843f8 commit 7757ffc
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
31 changes: 30 additions & 1 deletion src/core/qgsvectorfilewriter.cpp
Expand Up @@ -1007,7 +1007,7 @@ class QgsVectorFileWriterMetadataContainer

layerOptions.insert( QStringLiteral( "COORDINATE_PRECISION" ), new QgsVectorFileWriter::IntOption(
QObject::tr( "Maximum number of figures after decimal separator to write in coordinates. "
"Default to 15. Truncation will occur to remove trailing zeros." ),
"Defaults to 15. Truncation will occur to remove trailing zeros." ),
15 // Default value
) );

Expand All @@ -1023,6 +1023,35 @@ class QgsVectorFileWriterMetadataContainer
)
);

// GeoJSONSeq
datasetOptions.clear();
layerOptions.clear();

layerOptions.insert( QStringLiteral( "COORDINATE_PRECISION" ), new QgsVectorFileWriter::IntOption(
QObject::tr( "Maximum number of figures after decimal separator to write in coordinates. "
"Defaults to 15. Truncation will occur to remove trailing zeros." ),
15 // Default value
) );

layerOptions.insert( QStringLiteral( "RS" ), new QgsVectorFileWriter::BoolOption(
QObject::tr( "Whether to start records with the RS=0x1E character (RFC 8142 standard). "
"Defaults to NO: Newline Delimited JSON (geojsonl). \n"
"If set to YES: RFC 8142 standard: GeoJSON Text Sequences (geojsons)." ),
false // Default value = NO
) );

driverMetadata.insert( QStringLiteral( "GeoJSONSeq" ),
QgsVectorFileWriter::MetaData(
QStringLiteral( "GeoJSON - Newline Delimited" ),
QObject::tr( "GeoJSON - Newline Delimited" ),
QStringLiteral( "*.geojsonl *.geojsons *.json" ),
QStringLiteral( "json" ), // add json for now
datasetOptions,
layerOptions,
QStringLiteral( "UTF-8" )
)
);

// GeoRSS
datasetOptions.clear();
layerOptions.clear();
Expand Down
3 changes: 2 additions & 1 deletion src/gui/ogr/qgsogrhelperfunctions.cpp
Expand Up @@ -256,7 +256,8 @@ QString createProtocolURI( const QString &type, const QString &url, const QStri
uri = url;
uri.prepend( QStringLiteral( "/vsiswift/" ) );
}
else if ( type == QLatin1String( "GeoJSON" ) )
// catching both GeoJSON and GeoJSONSeq
else if ( type.startsWith( QLatin1String( "GeoJSON" ) ) )
{
uri = url;
}
Expand Down
8 changes: 7 additions & 1 deletion src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -2794,9 +2794,15 @@ QString createFilters( const QString &type )
sFileFilters += createFileFilter_( QObject::tr( "FMEObjects Gateway" ), QStringLiteral( "*.fdd" ) );
sExtensions << QStringLiteral( "fdd" );
}
else if ( driverName.startsWith( QLatin1String( "GeoJSONSeq" ) ) )
{
sProtocolDrivers += QLatin1String( "GeoJSON - Newline Delimited;" );
sFileFilters += createFileFilter_( QObject::tr( "GeoJSON Newline Delimited JSON" ), QStringLiteral( "*.geojsonl *.geojsons *.nlgeojson *.json" ) );
sExtensions << QStringLiteral( "geojsonl" ) << QStringLiteral( "geojsons" ) << QStringLiteral( "nlgeojson" ) << QStringLiteral( "json" );
}
else if ( driverName.startsWith( QLatin1String( "GeoJSON" ) ) )
{
sProtocolDrivers += QLatin1String( "GeoJSON,GeoJSON;" );
sProtocolDrivers += QLatin1String( "GeoJSON;" );
sFileFilters += createFileFilter_( QObject::tr( "GeoJSON" ), QStringLiteral( "*.geojson" ) );
sExtensions << QStringLiteral( "geojson" );
}
Expand Down

0 comments on commit 7757ffc

Please sign in to comment.