Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use GDAL API to get field subtype
  • Loading branch information
elpaso committed Apr 20, 2023
1 parent f1b1007 commit bce0f5a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/core/qgsvectorfilewriter.cpp
Expand Up @@ -704,16 +704,19 @@ void QgsVectorFileWriter::init( QString vectorFileName,
}

case QVariant::Map:
{
// handle GPKG conversion to JSON
if ( mOgrDriverName == QLatin1String( "GPKG" ) )
const char *pszDataSubTypes = GDALGetMetadataItem( poDriver, GDAL_DMD_CREATIONFIELDDATASUBTYPES, nullptr );
if ( pszDataSubTypes && strstr( pszDataSubTypes, "JSON" ) )
{
ogrType = OFTString;
ogrSubType = OFSTJSON;
break;
}
}

//intentional fall-through
FALLTHROUGH
FALLTHROUGH

case QVariant::List:
// handle GPKG conversion to JSON
Expand Down Expand Up @@ -2936,8 +2939,10 @@ gdal::ogr_feature_unique_ptr QgsVectorFileWriter::createFeature( const QgsFeatur
FALLTHROUGH

case QVariant::Map:
{
// handle GPKG conversion to JSON
if ( mOgrDriverName == QLatin1String( "GPKG" ) )
const char *pszDataSubTypes = GDALGetMetadataItem( OGRGetDriverByName( mOgrDriverName.toLocal8Bit().constData() ), GDAL_DMD_CREATIONFIELDDATASUBTYPES, nullptr );
if ( pszDataSubTypes && strstr( pszDataSubTypes, "JSON" ) )
{
const QJsonDocument doc = QJsonDocument::fromVariant( attrValue );
QString jsonString;
Expand All @@ -2949,9 +2954,10 @@ gdal::ogr_feature_unique_ptr QgsVectorFileWriter::createFeature( const QgsFeatur
OGR_F_SetFieldString( poFeature.get(), ogrField, mCodec->fromUnicode( jsonString.constData() ) );
break;
}
}

//intentional fall-through
FALLTHROUGH
FALLTHROUGH


default:
Expand Down

0 comments on commit bce0f5a

Please sign in to comment.