Skip to content

Commit bce0f5a

Browse files
committedApr 20, 2023
Use GDAL API to get field subtype
1 parent f1b1007 commit bce0f5a

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed
 

‎src/core/qgsvectorfilewriter.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -704,16 +704,19 @@ void QgsVectorFileWriter::init( QString vectorFileName,
704704
}
705705

706706
case QVariant::Map:
707+
{
707708
// handle GPKG conversion to JSON
708-
if ( mOgrDriverName == QLatin1String( "GPKG" ) )
709+
const char *pszDataSubTypes = GDALGetMetadataItem( poDriver, GDAL_DMD_CREATIONFIELDDATASUBTYPES, nullptr );
710+
if ( pszDataSubTypes && strstr( pszDataSubTypes, "JSON" ) )
709711
{
710712
ogrType = OFTString;
711713
ogrSubType = OFSTJSON;
712714
break;
713715
}
716+
}
714717

715718
//intentional fall-through
716-
FALLTHROUGH
719+
FALLTHROUGH
717720

718721
case QVariant::List:
719722
// handle GPKG conversion to JSON
@@ -2936,8 +2939,10 @@ gdal::ogr_feature_unique_ptr QgsVectorFileWriter::createFeature( const QgsFeatur
29362939
FALLTHROUGH
29372940

29382941
case QVariant::Map:
2942+
{
29392943
// handle GPKG conversion to JSON
2940-
if ( mOgrDriverName == QLatin1String( "GPKG" ) )
2944+
const char *pszDataSubTypes = GDALGetMetadataItem( OGRGetDriverByName( mOgrDriverName.toLocal8Bit().constData() ), GDAL_DMD_CREATIONFIELDDATASUBTYPES, nullptr );
2945+
if ( pszDataSubTypes && strstr( pszDataSubTypes, "JSON" ) )
29412946
{
29422947
const QJsonDocument doc = QJsonDocument::fromVariant( attrValue );
29432948
QString jsonString;
@@ -2949,9 +2954,10 @@ gdal::ogr_feature_unique_ptr QgsVectorFileWriter::createFeature( const QgsFeatur
29492954
OGR_F_SetFieldString( poFeature.get(), ogrField, mCodec->fromUnicode( jsonString.constData() ) );
29502955
break;
29512956
}
2957+
}
29522958

29532959
//intentional fall-through
2954-
FALLTHROUGH
2960+
FALLTHROUGH
29552961

29562962

29572963
default:

0 commit comments

Comments
 (0)
Please sign in to comment.