QgsDelimitedTextProvider::QgsDelimitedTextProvider( QString uri ) : QgsVectorDataProvider( uri ) , mLayerValid( false ) , mValid( false ) , mFile( 0 ) , mGeomRep( GeomNone ) , mFieldCount( 0 ) , mXFieldIndex( -1 ) , mYFieldIndex( -1 ) , mWktFieldIndex( -1 ) , mWktHasZM( false ) , mWktHasPrefix( false ) , mXyDms( false ) , mSubsetString( "" ) , mSubsetExpression( 0 ) , mBuildSubsetIndex( true ) , mUseSubsetIndex( false ) , mMaxInvalidLines( 50 ) , mShowInvalidLines( true ) , mRescanRequired( false ) , mCrs() , mWkbType( QGis::WKBNoGeometry ) , mGeometryType( QGis::UnknownGeometry ) , mBuildSpatialIndex( false ) , mSpatialIndex( 0 ) { // Add supported types to enable creating expression fields in field calculator mNativeTypes << QgsVectorDataProvider::NativeType( tr( "Whole number (integer)" ), "integer", QVariant::Int, 0, 10 ) << QgsVectorDataProvider::NativeType( tr( "Whole number (integer - 64 bit)" ), "int8", QVariant::LongLong ) << QgsVectorDataProvider::NativeType( tr( "Decimal number (double)" ), "double precision", QVariant::Double, -1, -1, -1, -1 ) << QgsVectorDataProvider::NativeType( tr( "Text, unlimited length (text)" ), "text", QVariant::String, -1, -1, -1, -1 ) ; QgsDebugMsg( "Delimited text file uri is " + uri ); QUrl url = QUrl::fromEncoded( uri.toAscii() ); mFile = new QgsDelimitedTextFile(); mFile->setFromUrl( url ); QString subset; if ( url.hasQueryItem( "geomType" ) ) { QString gtype = url.queryItemValue( "geomType" ).toLower(); if ( gtype == "point" ) mGeometryType = QGis::Point; else if ( gtype == "line" ) mGeometryType = QGis::Line; else if ( gtype == "polygon" ) mGeometryType = QGis::Polygon; else if ( gtype == "none " ) mGeometryType = QGis::NoGeometry; } if ( mGeometryType != QGis::NoGeometry ) { if ( url.hasQueryItem( "wktField" ) ) { mWktFieldName = url.queryItemValue( "wktField" ); mGeomRep = GeomAsWkt; QgsDebugMsg( "wktField is: " + mWktFieldName ); } else if ( url.hasQueryItem( "xField" ) && url.hasQueryItem( "yField" ) ) { mGeomRep = GeomAsXy; mGeometryType = QGis::Point; mXFieldName = url.queryItemValue( "xField" ); mYFieldName = url.queryItemValue( "yField" ); QgsDebugMsg( "xField is: " + mXFieldName ); QgsDebugMsg( "yField is: " + mYFieldName ); if ( url.hasQueryItem( "xyDms" ) ) { mXyDms = ! url.queryItemValue( "xyDms" ).toLower().startsWith( "n" ); } } else { mGeometryType = QGis::NoGeometry; } } if ( url.hasQueryItem( "decimalPoint" ) ) mDecimalPoint = url.queryItemValue( "decimalPoint" ); if ( url.hasQueryItem( "crs" ) ) mCrs.createFromString( url.queryItemValue( "crs" ) ); if ( url.hasQueryItem( "subsetIndex" ) ) { mBuildSubsetIndex = ! url.queryItemValue( "subsetIndex" ).toLower().startsWith( "n" ); } if ( url.hasQueryItem( "spatialIndex" ) ) { mBuildSpatialIndex = ! url.queryItemValue( "spatialIndex" ).toLower().startsWith( "n" ); } if ( url.hasQueryItem( "subset" ) ) { subset = url.queryItemValue( "subset" ); QgsDebugMsg( "subset is: " + subset ); } if ( url.hasQueryItem( "quiet" ) ) mShowInvalidLines = false; // Do an initial scan of the file to determine field names, types, // geometry type (for Wkt), extents, etc. Parameter value subset.isEmpty() // avoid redundant building indexes if we will be building a subset string, // in which case indexes will be rebuilt. scanFile( subset.isEmpty() ); if ( ! subset.isEmpty() ) { setSubsetString( subset ); } }
QgsDelimitedTextProvider::QgsDelimitedTextProvider( const QString &uri, const ProviderOptions &options ) : QgsVectorDataProvider( uri, options ) { // Add supported types to enable creating expression fields in field calculator setNativeTypes( QList< NativeType >() << QgsVectorDataProvider::NativeType( tr( "Whole number (integer)" ), QStringLiteral( "integer" ), QVariant::Int, 0, 10 ) << QgsVectorDataProvider::NativeType( tr( "Whole number (integer - 64 bit)" ), QStringLiteral( "int8" ), QVariant::LongLong ) << QgsVectorDataProvider::NativeType( tr( "Decimal number (double)" ), QStringLiteral( "double precision" ), QVariant::Double, -1, -1, -1, -1 ) << QgsVectorDataProvider::NativeType( tr( "Text, unlimited length (text)" ), QStringLiteral( "text" ), QVariant::String, -1, -1, -1, -1 ) ); QgsDebugMsg( "Delimited text file uri is " + uri ); QUrl url = QUrl::fromEncoded( uri.toLatin1() ); mFile = qgis::make_unique< QgsDelimitedTextFile >(); mFile->setFromUrl( url ); QString subset; if ( url.hasQueryItem( QStringLiteral( "geomType" ) ) ) { QString gtype = url.queryItemValue( QStringLiteral( "geomType" ) ).toLower(); if ( gtype == QLatin1String( "point" ) ) mGeometryType = QgsWkbTypes::PointGeometry; else if ( gtype == QLatin1String( "line" ) ) mGeometryType = QgsWkbTypes::LineGeometry; else if ( gtype == QLatin1String( "polygon" ) ) mGeometryType = QgsWkbTypes::PolygonGeometry; else if ( gtype == QLatin1String( "none " ) ) mGeometryType = QgsWkbTypes::NullGeometry; } if ( mGeometryType != QgsWkbTypes::NullGeometry ) { if ( url.hasQueryItem( QStringLiteral( "wktField" ) ) ) { mWktFieldName = url.queryItemValue( QStringLiteral( "wktField" ) ); mGeomRep = GeomAsWkt; QgsDebugMsg( "wktField is: " + mWktFieldName ); } else if ( url.hasQueryItem( QStringLiteral( "xField" ) ) && url.hasQueryItem( QStringLiteral( "yField" ) ) ) { mGeomRep = GeomAsXy; mGeometryType = QgsWkbTypes::PointGeometry; mXFieldName = url.queryItemValue( QStringLiteral( "xField" ) ); mYFieldName = url.queryItemValue( QStringLiteral( "yField" ) ); QgsDebugMsg( "xField is: " + mXFieldName ); QgsDebugMsg( "yField is: " + mYFieldName ); if ( url.hasQueryItem( QStringLiteral( "xyDms" ) ) ) { mXyDms = ! url.queryItemValue( QStringLiteral( "xyDms" ) ).toLower().startsWith( 'n' ); } } else { mGeometryType = QgsWkbTypes::NullGeometry; } } mDetectTypes = true; if ( url.hasQueryItem( QStringLiteral( "detectTypes" ) ) ) mDetectTypes = ! url.queryItemValue( QStringLiteral( "detectTypes" ) ).toLower().startsWith( 'n' ); if ( url.hasQueryItem( QStringLiteral( "decimalPoint" ) ) ) mDecimalPoint = url.queryItemValue( QStringLiteral( "decimalPoint" ) ); if ( url.hasQueryItem( QStringLiteral( "crs" ) ) ) mCrs.createFromString( url.queryItemValue( QStringLiteral( "crs" ) ) ); if ( url.hasQueryItem( QStringLiteral( "subsetIndex" ) ) ) { mBuildSubsetIndex = ! url.queryItemValue( QStringLiteral( "subsetIndex" ) ).toLower().startsWith( 'n' ); } if ( url.hasQueryItem( QStringLiteral( "spatialIndex" ) ) ) { mBuildSpatialIndex = ! url.queryItemValue( QStringLiteral( "spatialIndex" ) ).toLower().startsWith( 'n' ); } if ( url.hasQueryItem( QStringLiteral( "subset" ) ) ) { // We need to specify FullyDecoded so that %25 is decoded as % subset = QUrlQuery( url ).queryItemValue( QStringLiteral( "subset" ), QUrl::FullyDecoded ); QgsDebugMsg( "subset is: " + subset ); } if ( url.hasQueryItem( QStringLiteral( "quiet" ) ) ) mShowInvalidLines = false; // Do an initial scan of the file to determine field names, types, // geometry type (for Wkt), extents, etc. Parameter value subset.isEmpty() // avoid redundant building indexes if we will be building a subset string, // in which case indexes will be rebuilt. scanFile( subset.isEmpty() ); if ( ! subset.isEmpty() ) { setSubsetString( subset ); } }