Skip to content
Permalink
Browse files

Fix #21160: fix geojson in protocol and file twice

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 Feb 8, 2019
1 parent fa843f8 commit 7757ffc5dd232b1be240984734e44282f390588a
Showing with 39 additions and 3 deletions.
  1. +30 −1 src/core/qgsvectorfilewriter.cpp
  2. +2 −1 src/gui/ogr/qgsogrhelperfunctions.cpp
  3. +7 −1 src/providers/ogr/qgsogrprovider.cpp
@@ -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
) );

@@ -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();
@@ -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;
}
@@ -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" );
}

0 comments on commit 7757ffc

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