24 #include "qgsogrprovider.h"
27 #include <cpl_error.h>
28 #include <QJsonDocument>
31 #include <QTextStream>
32 #include <QDataStream>
34 #include "ogr_srs_api.h"
40 #define OGR_F_IsFieldSetAndNotNull OGR_F_IsFieldSet
47 OGR_DS_Destroy( source );
53 OGR_G_DestroyGeometry( geometry );
58 OGR_Fld_Destroy( definition );
63 OGR_F_Destroy( feature );
80 CPLPushErrorHandler( CPLQuietErrorHandler );
81 GDALDeleteDataset( driver, path.toUtf8().constData() );
93 GDALDestroyWarpOptions( options );
105 feature.
setId( OGR_F_GetFID( ogrFet ) );
108 if ( !readOgrFeatureGeometry( ogrFet, feature ) )
113 if ( !readOgrFeatureAttributes( ogrFet, fields, feature, encoding ) )
128 int fieldCount = OGR_F_GetFieldCount( ogrFet );
129 for (
int i = 0; i < fieldCount; ++i )
131 OGRFieldDefnH fldDef = OGR_F_GetFieldDefnRef( ogrFet, i );
138 QString name = encoding ? encoding->toUnicode( OGR_Fld_GetNameRef( fldDef ) ) : QString::fromUtf8( OGR_Fld_GetNameRef( fldDef ) );
139 QVariant::Type varType;
140 switch ( OGR_Fld_GetType( fldDef ) )
143 if ( OGR_Fld_GetSubType( fldDef ) == OFSTBoolean )
144 varType = QVariant::Bool;
146 varType = QVariant::Int;
149 varType = QVariant::LongLong;
152 varType = QVariant::Double;
155 varType = QVariant::Date;
158 varType = QVariant::Time;
161 varType = QVariant::DateTime;
164 #if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,4,0)
165 if ( OGR_Fld_GetSubType( fldDef ) == OFSTJSON )
166 varType = QVariant::Map;
168 varType = QVariant::String;
172 varType = QVariant::String;
182 if ( attIndex < 0 || attIndex >= fields.
count() )
190 return getOgrFeatureAttribute( ogrFet,
field, attIndex, encoding, ok );
195 if ( !ogrFet || attIndex < 0 )
202 OGRFieldDefnH fldDef = OGR_F_GetFieldDefnRef( ogrFet, attIndex );
209 QgsDebugMsg( QStringLiteral(
"ogrFet->GetFieldDefnRef(attindex) returns NULL" ) );
222 case QVariant::String:
225 value = QVariant( encoding->toUnicode( OGR_F_GetFieldAsString( ogrFet, attIndex ) ) );
227 value = QVariant( QString::fromUtf8( OGR_F_GetFieldAsString( ogrFet, attIndex ) ) );
232 if ( value.isNull() )
233 value = QVariant( QStringLiteral(
"" ) );
239 value = QVariant( OGR_F_GetFieldAsInteger( ogrFet, attIndex ) );
242 value = QVariant(
bool( OGR_F_GetFieldAsInteger( ogrFet, attIndex ) ) );
244 case QVariant::LongLong:
245 value = QVariant( OGR_F_GetFieldAsInteger64( ogrFet, attIndex ) );
247 case QVariant::Double:
248 value = QVariant( OGR_F_GetFieldAsDouble( ogrFet, attIndex ) );
251 case QVariant::DateTime:
254 int year, month, day, hour, minute, second, tzf;
256 OGR_F_GetFieldAsDateTime( ogrFet, attIndex, &year, &month, &day, &hour, &minute, &second, &tzf );
258 value = QDate( year, month, day );
259 else if (
field.
type() == QVariant::Time )
260 value = QTime( hour, minute, second );
262 value = QDateTime( QDate( year, month, day ), QTime( hour, minute, second ) );
266 case QVariant::ByteArray:
269 const GByte *b = OGR_F_GetFieldAsBinary( ogrFet, attIndex, &size );
273 QByteArray ba = QByteArray::fromRawData(
reinterpret_cast<const char *
>( b ), size );
285 char **lst = OGR_F_GetFieldAsStringList( ogrFet, attIndex );
286 const int count = CSLCount( lst );
289 for (
int i = 0; i < count; i++ )
292 list << encoding->toUnicode( lst[i] );
294 list << QString::fromUtf8( lst[i] );
301 Q_ASSERT_X(
false,
"QgsOgrUtils::getOgrFeatureAttribute",
"unsupported field type" );
313 value = QJsonDocument::fromJson( encoding->toUnicode( OGR_F_GetFieldAsString( ogrFet, attIndex ) ).toUtf8() ).toVariant();
315 value = QJsonDocument::fromJson( QString::fromUtf8( OGR_F_GetFieldAsString( ogrFet, attIndex ) ).toUtf8() ).toVariant();
319 Q_ASSERT_X(
false,
"QgsOgrUtils::getOgrFeatureAttribute",
"unsupported field type" );
342 for (
int idx = 0; idx < fields.
count(); ++idx )
344 QVariant value = getOgrFeatureAttribute( ogrFet, fields, idx, encoding, &ok );
358 OGRGeometryH geom = OGR_F_GetGeometryRef( ogrFet );
362 feature.
setGeometry( ogrGeometryToQgsGeometry( geom ) );
372 OGR_G_GetPointZM( geom, 0, &x, &y, &z, &m );
373 return qgis::make_unique< QgsPoint >( wkbType, x, y, z, m );
378 std::unique_ptr< QgsMultiPoint > mp = qgis::make_unique< QgsMultiPoint >();
380 const int count = OGR_G_GetGeometryCount( geom );
381 mp->reserve( count );
382 for (
int i = 0; i < count; ++i )
394 int count = OGR_G_GetPointCount( geom );
395 QVector< double > x( count );
396 QVector< double > y( count );
398 double *pz =
nullptr;
404 double *pm =
nullptr;
411 OGR_G_GetPointsZM( geom, x.data(),
sizeof(
double ), y.data(),
sizeof(
double ), pz,
sizeof(
double ), pm,
sizeof(
double ) );
418 std::unique_ptr< QgsMultiLineString > mp = qgis::make_unique< QgsMultiLineString >();
420 const int count = OGR_G_GetGeometryCount( geom );
421 mp->reserve( count );
422 for (
int i = 0; i < count; ++i )
432 switch ( ogrGeomType )
434 case wkbUnknown:
return QgsWkbTypes::Type::Unknown;
435 case wkbPoint:
return QgsWkbTypes::Type::Point;
436 case wkbLineString:
return QgsWkbTypes::Type::LineString;
437 case wkbPolygon:
return QgsWkbTypes::Type::Polygon;
438 case wkbMultiPoint:
return QgsWkbTypes::Type::MultiPoint;
439 case wkbMultiLineString:
return QgsWkbTypes::Type::MultiLineString;
440 case wkbMultiPolygon:
return QgsWkbTypes::Type::MultiPolygon;
441 case wkbGeometryCollection:
return QgsWkbTypes::Type::GeometryCollection;
442 case wkbCircularString:
return QgsWkbTypes::Type::CircularString;
443 case wkbCompoundCurve:
return QgsWkbTypes::Type::CompoundCurve;
444 case wkbCurvePolygon:
return QgsWkbTypes::Type::CurvePolygon;
445 case wkbMultiCurve:
return QgsWkbTypes::Type::MultiCurve;
446 case wkbMultiSurface:
return QgsWkbTypes::Type::MultiSurface;
447 case wkbCurve:
return QgsWkbTypes::Type::Unknown;
448 case wkbSurface:
return QgsWkbTypes::Type::Unknown;
449 case wkbPolyhedralSurface:
return QgsWkbTypes::Type::Unknown;
450 case wkbTIN:
return QgsWkbTypes::Type::Unknown;
451 case wkbTriangle:
return QgsWkbTypes::Type::Triangle;
453 case wkbNone:
return QgsWkbTypes::Type::NoGeometry;
454 case wkbLinearRing:
return QgsWkbTypes::Type::LineString;
456 case wkbCircularStringZ:
return QgsWkbTypes::Type::CircularStringZ;
457 case wkbCompoundCurveZ:
return QgsWkbTypes::Type::CompoundCurveZ;
458 case wkbCurvePolygonZ:
return QgsWkbTypes::Type::CurvePolygonZ;
459 case wkbMultiCurveZ:
return QgsWkbTypes::Type::MultiCurveZ;
460 case wkbMultiSurfaceZ:
return QgsWkbTypes::Type::MultiSurfaceZ;
461 case wkbCurveZ:
return QgsWkbTypes::Type::Unknown;
462 case wkbSurfaceZ:
return QgsWkbTypes::Type::Unknown;
463 case wkbPolyhedralSurfaceZ:
return QgsWkbTypes::Type::Unknown;
464 case wkbTINZ:
return QgsWkbTypes::Type::Unknown;
465 case wkbTriangleZ:
return QgsWkbTypes::Type::TriangleZ;
467 case wkbPointM:
return QgsWkbTypes::Type::PointM;
468 case wkbLineStringM:
return QgsWkbTypes::Type::LineStringM;
469 case wkbPolygonM:
return QgsWkbTypes::Type::PolygonM;
470 case wkbMultiPointM:
return QgsWkbTypes::Type::MultiPointM;
471 case wkbMultiLineStringM:
return QgsWkbTypes::Type::MultiLineStringM;
472 case wkbMultiPolygonM:
return QgsWkbTypes::Type::MultiPolygonM;
473 case wkbGeometryCollectionM:
return QgsWkbTypes::Type::GeometryCollectionM;
474 case wkbCircularStringM:
return QgsWkbTypes::Type::CircularStringM;
475 case wkbCompoundCurveM:
return QgsWkbTypes::Type::CompoundCurveM;
476 case wkbCurvePolygonM:
return QgsWkbTypes::Type::CurvePolygonM;
477 case wkbMultiCurveM:
return QgsWkbTypes::Type::MultiCurveM;
478 case wkbMultiSurfaceM:
return QgsWkbTypes::Type::MultiSurfaceM;
479 case wkbCurveM:
return QgsWkbTypes::Type::Unknown;
480 case wkbSurfaceM:
return QgsWkbTypes::Type::Unknown;
481 case wkbPolyhedralSurfaceM:
return QgsWkbTypes::Type::Unknown;
482 case wkbTINM:
return QgsWkbTypes::Type::Unknown;
483 case wkbTriangleM:
return QgsWkbTypes::Type::TriangleM;
485 case wkbPointZM:
return QgsWkbTypes::Type::PointZM;
486 case wkbLineStringZM:
return QgsWkbTypes::Type::LineStringZM;
487 case wkbPolygonZM:
return QgsWkbTypes::Type::PolygonZM;
488 case wkbMultiPointZM:
return QgsWkbTypes::Type::MultiPointZM;
489 case wkbMultiLineStringZM:
return QgsWkbTypes::Type::MultiLineStringZM;
490 case wkbMultiPolygonZM:
return QgsWkbTypes::Type::MultiPolygonZM;
491 case wkbGeometryCollectionZM:
return QgsWkbTypes::Type::GeometryCollectionZM;
492 case wkbCircularStringZM:
return QgsWkbTypes::Type::CircularStringZM;
493 case wkbCompoundCurveZM:
return QgsWkbTypes::Type::CompoundCurveZM;
494 case wkbCurvePolygonZM:
return QgsWkbTypes::Type::CurvePolygonZM;
495 case wkbMultiCurveZM:
return QgsWkbTypes::Type::MultiCurveZM;
496 case wkbMultiSurfaceZM:
return QgsWkbTypes::Type::MultiSurfaceZM;
497 case wkbCurveZM:
return QgsWkbTypes::Type::Unknown;
498 case wkbSurfaceZM:
return QgsWkbTypes::Type::Unknown;
499 case wkbPolyhedralSurfaceZM:
return QgsWkbTypes::Type::Unknown;
500 case wkbTINZM:
return QgsWkbTypes::Type::Unknown;
501 case wkbTriangleZM:
return QgsWkbTypes::Type::TriangleZM;
503 case wkbPoint25D:
return QgsWkbTypes::Type::PointZ;
504 case wkbLineString25D:
return QgsWkbTypes::Type::LineStringZ;
505 case wkbPolygon25D:
return QgsWkbTypes::Type::PolygonZ;
506 case wkbMultiPoint25D:
return QgsWkbTypes::Type::MultiPointZ;
507 case wkbMultiLineString25D:
return QgsWkbTypes::Type::MultiLineStringZ;
508 case wkbMultiPolygon25D:
return QgsWkbTypes::Type::MultiPolygonZ;
509 case wkbGeometryCollection25D:
return QgsWkbTypes::Type::GeometryCollectionZ;
513 return QgsWkbTypes::Type::Unknown;
521 const auto ogrGeomType = OGR_G_GetGeometryType( geom );
556 if ( wkbFlatten( wkbType ) == wkbGeometryCollection )
559 if ( OGR_G_GetGeometryCount( geom ) >= 1 &&
560 wkbFlatten( OGR_G_GetGeometryType( OGR_G_GetGeometryRef( geom, 0 ) ) ) == wkbTIN )
562 auto newGeom = OGR_G_ForceToMultiPolygon( OGR_G_Clone( geom ) );
563 auto ret = ogrGeometryToQgsGeometry( newGeom );
564 OGR_G_DestroyGeometry( newGeom );
570 int memorySize = OGR_G_WkbSize( geom );
571 unsigned char *wkb =
new unsigned char[memorySize];
575 uint32_t origGeomType;
576 memcpy( &origGeomType, wkb + 1,
sizeof( uint32_t ) );
577 bool hasZ = ( origGeomType >= 1000 && origGeomType < 2000 ) || ( origGeomType >= 3000 && origGeomType < 4000 );
578 bool hasM = ( origGeomType >= 2000 && origGeomType < 3000 ) || ( origGeomType >= 3000 && origGeomType < 4000 );
581 if ( origGeomType % 1000 == 16 )
584 int nDims = 2 + hasZ + hasM;
587 unsigned char *wkbptr = wkb;
593 memcpy( wkbptr, &newMultiType,
sizeof( uint32_t ) );
598 memcpy( &numGeoms, wkb + 5,
sizeof( uint32_t ) );
602 for ( uint32_t i = 0; i < numGeoms; ++i )
608 memcpy( wkbptr, &newSingleType,
sizeof( uint32_t ) );
609 wkbptr +=
sizeof( uint32_t );
613 memcpy( &nRings, wkbptr,
sizeof( uint32_t ) );
614 wkbptr +=
sizeof( uint32_t );
616 for ( uint32_t j = 0; j < nRings; ++j )
619 memcpy( &nPoints, wkbptr,
sizeof( uint32_t ) );
620 wkbptr +=
sizeof( uint32_t ) +
sizeof(
double ) * nDims * nPoints;
624 else if ( origGeomType % 1000 == 15 )
629 memcpy( wkb + 1, &newType,
sizeof( uint32_t ) );
640 if (
string.isEmpty() )
643 QString randomFileName = QStringLiteral(
"/vsimem/%1" ).arg( QUuid::createUuid().toString() );
646 QByteArray ba =
string.toUtf8();
647 VSIFCloseL( VSIFileFromMemBuffer( randomFileName.toUtf8().constData(),
reinterpret_cast< GByte *
>( ba.data() ),
648 static_cast< vsi_l_offset
>( ba.size() ), FALSE ) );
653 VSIUnlink( randomFileName.toUtf8().constData() );
657 OGRLayerH ogrLayer = OGR_DS_GetLayer( hDS.get(), 0 );
661 VSIUnlink( randomFileName.toUtf8().constData() );
666 while ( oFeat.reset( OGR_L_GetNextFeature( ogrLayer ) ), oFeat )
668 QgsFeature feat = readOgrFeature( oFeat.get(), fields, encoding );
674 VSIUnlink( randomFileName.toUtf8().constData() );
682 if (
string.isEmpty() )
685 QString randomFileName = QStringLiteral(
"/vsimem/%1" ).arg( QUuid::createUuid().toString() );
688 QByteArray ba =
string.toUtf8();
689 VSIFCloseL( VSIFileFromMemBuffer( randomFileName.toUtf8().constData(),
reinterpret_cast< GByte *
>( ba.data() ),
690 static_cast< vsi_l_offset
>( ba.size() ), FALSE ) );
695 VSIUnlink( randomFileName.toUtf8().constData() );
699 OGRLayerH ogrLayer = OGR_DS_GetLayer( hDS.get(), 0 );
703 VSIUnlink( randomFileName.toUtf8().constData() );
709 if ( oFeat.reset( OGR_L_GetNextFeature( ogrLayer ) ), oFeat )
711 fields = readOgrFields( oFeat.get(), encoding );
715 VSIUnlink( randomFileName.toUtf8().constData() );
724 for (
qgssize i = 0; stringList[i]; ++i )
726 strings.append( QString::fromUtf8( stringList[i] ) );
737 char *pszWkt =
nullptr;
738 #if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,0,0)
739 const QByteArray multiLineOption = QStringLiteral(
"MULTILINE=NO" ).toLocal8Bit();
740 const QByteArray formatOption = QStringLiteral(
"FORMAT=WKT2" ).toLocal8Bit();
741 const char *
const options[] = {multiLineOption.constData(), formatOption.constData(),
nullptr};
742 OSRExportToWktEx( srs, &pszWkt, options );
744 OSRExportToWkt( srs, &pszWkt );
747 const QString res( pszWkt );
754 const QString wkt = OGRSpatialReferenceToWkt( srs );
763 const QString cpgEncoding = readShapefileEncodingFromCpg( path );
764 if ( !cpgEncoding.isEmpty() )
767 return readShapefileEncodingFromLdid( path );
772 #if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,1,0)
774 QgsOgrLayerUniquePtr layer = QgsOgrProviderUtils::getLayer( path,
false, QStringList(), 0, errCause,
false );
775 return layer ? layer->GetMetadataItem( QStringLiteral(
"ENCODING_FROM_CPG" ), QStringLiteral(
"SHAPEFILE" ) ) : QString();
777 if ( !QFileInfo::exists( path ) )
781 const QFileInfo fi( path );
782 const QString baseName = fi.completeBaseName();
783 const QString cpgPath = fi.dir().filePath( QStringLiteral(
"%1.%2" ).arg( baseName, fi.suffix() == QLatin1String(
"SHP" ) ? QStringLiteral(
"CPG" ) : QStringLiteral(
"cpg" ) ) );
784 if ( QFile::exists( cpgPath ) )
786 QFile cpgFile( cpgPath );
787 if ( cpgFile.open( QIODevice::ReadOnly ) )
789 QTextStream cpgStream( &cpgFile );
790 const QString cpgString = cpgStream.readLine();
793 if ( !cpgString.isEmpty() )
798 int cpgCodePage = cpgString.toInt( &ok );
799 if ( ok && ( ( cpgCodePage >= 437 && cpgCodePage <= 950 )
800 || ( cpgCodePage >= 1250 && cpgCodePage <= 1258 ) ) )
802 return QStringLiteral(
"CP%1" ).arg( cpgCodePage );
804 else if ( cpgString.startsWith( QLatin1String(
"8859" ) ) )
806 if ( cpgString.length() > 4 && cpgString.at( 4 ) ==
'-' )
807 return QStringLiteral(
"ISO-8859-%1" ).arg( cpgString.mid( 5 ) );
809 return QStringLiteral(
"ISO-8859-%1" ).arg( cpgString.mid( 4 ) );
811 else if ( cpgString.startsWith( QLatin1String(
"UTF-8" ), Qt::CaseInsensitive ) ||
812 cpgString.startsWith( QLatin1String(
"UTF8" ), Qt::CaseInsensitive ) )
813 return QStringLiteral(
"UTF-8" );
814 else if ( cpgString.startsWith( QLatin1String(
"ANSI 1251" ), Qt::CaseInsensitive ) )
815 return QStringLiteral(
"CP1251" );
828 #if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,1,0)
830 QgsOgrLayerUniquePtr layer = QgsOgrProviderUtils::getLayer( path,
false, QStringList(), 0, errCause,
false );
831 return layer ? layer->GetMetadataItem( QStringLiteral(
"ENCODING_FROM_LDID" ), QStringLiteral(
"SHAPEFILE" ) ) : QString();
836 if ( !QFileInfo::exists( path ) )
840 const QFileInfo fi( path );
841 const QString baseName = fi.completeBaseName();
844 const QString dbfPath = fi.dir().filePath( QStringLiteral(
"%1.%2" ).arg( baseName, fi.suffix() == QLatin1String(
"SHP" ) ? QStringLiteral(
"DBF" ) : QStringLiteral(
"dbf" ) ) );
845 if ( QFile::exists( dbfPath ) )
847 QFile dbfFile( dbfPath );
848 if ( dbfFile.open( QIODevice::ReadOnly ) )
851 QDataStream dbfIn( &dbfFile );
852 dbfIn.setByteOrder( QDataStream::LittleEndian );
862 case 1: nCP = 437;
break;
863 case 2: nCP = 850;
break;
864 case 3: nCP = 1252;
break;
865 case 4: nCP = 10000;
break;
866 case 8: nCP = 865;
break;
867 case 10: nCP = 850;
break;
868 case 11: nCP = 437;
break;
869 case 13: nCP = 437;
break;
870 case 14: nCP = 850;
break;
871 case 15: nCP = 437;
break;
872 case 16: nCP = 850;
break;
873 case 17: nCP = 437;
break;
874 case 18: nCP = 850;
break;
875 case 19: nCP = 932;
break;
876 case 20: nCP = 850;
break;
877 case 21: nCP = 437;
break;
878 case 22: nCP = 850;
break;
879 case 23: nCP = 865;
break;
880 case 24: nCP = 437;
break;
881 case 25: nCP = 437;
break;
882 case 26: nCP = 850;
break;
883 case 27: nCP = 437;
break;
884 case 28: nCP = 863;
break;
885 case 29: nCP = 850;
break;
886 case 31: nCP = 852;
break;
887 case 34: nCP = 852;
break;
888 case 35: nCP = 852;
break;
889 case 36: nCP = 860;
break;
890 case 37: nCP = 850;
break;
891 case 38: nCP = 866;
break;
892 case 55: nCP = 850;
break;
893 case 64: nCP = 852;
break;
894 case 77: nCP = 936;
break;
895 case 78: nCP = 949;
break;
896 case 79: nCP = 950;
break;
897 case 80: nCP = 874;
break;
898 case 87:
return QStringLiteral(
"ISO-8859-1" );
899 case 88: nCP = 1252;
break;
900 case 89: nCP = 1252;
break;
901 case 100: nCP = 852;
break;
902 case 101: nCP = 866;
break;
903 case 102: nCP = 865;
break;
904 case 103: nCP = 861;
break;
905 case 104: nCP = 895;
break;
906 case 105: nCP = 620;
break;
907 case 106: nCP = 737;
break;
908 case 107: nCP = 857;
break;
909 case 108: nCP = 863;
break;
910 case 120: nCP = 950;
break;
911 case 121: nCP = 949;
break;
912 case 122: nCP = 936;
break;
913 case 123: nCP = 932;
break;
914 case 124: nCP = 874;
break;
915 case 134: nCP = 737;
break;
916 case 135: nCP = 852;
break;
917 case 136: nCP = 857;
break;
918 case 150: nCP = 10007;
break;
919 case 151: nCP = 10029;
break;
920 case 200: nCP = 1250;
break;
921 case 201: nCP = 1251;
break;
922 case 202: nCP = 1254;
break;
923 case 203: nCP = 1253;
break;
924 case 204: nCP = 1257;
break;
930 return QStringLiteral(
"CP%1" ).arg( nCP );
static endian_t endian()
Returns whether this machine uses big or little endian.
This class represents a coordinate reference system (CRS).
static QgsCoordinateReferenceSystem fromWkt(const QString &wkt)
Creates a CRS from a WKT spatial ref sys definition string.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool setAttribute(int field, const QVariant &attr)
Set an attribute's value by field index.
void initAttributes(int fieldCount)
Initialize this feature with the given number of fields.
void setFields(const QgsFields &fields, bool initAttributes=false)
Assign a field map with the feature to allow attribute access by attribute name.
void setId(QgsFeatureId id)
Sets the feature ID for this feature.
void clearGeometry()
Removes any geometry associated with the feature.
void setValid(bool validity)
Sets the validity of the feature.
bool isValid() const
Returns the validity of this feature.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Encapsulate a field in an attribute table or data source.
QVariant::Type subType() const
If the field is a collection, gets its element's type.
Container of fields for a vector layer.
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Appends a field. The field must have unique name, otherwise it is rejected (returns false)
int count() const
Returns number of items.
QgsField at(int i) const
Gets field at particular index (must be in range 0..N-1)
A geometry is the spatial representation of a feature.
void fromWkb(unsigned char *wkb, int length)
Set the geometry, feeding in the buffer containing OGC Well-Known Binary and the buffer's length.
static QString readShapefileEncoding(const QString &path)
Reads the encoding of the shapefile at the specified path (where path is the location of the "....
static bool readOgrFeatureAttributes(OGRFeatureH ogrFet, const QgsFields &fields, QgsFeature &feature, QTextCodec *encoding)
Reads all attributes from an OGR feature into a QgsFeature.
static QgsGeometry ogrGeometryToQgsGeometry(OGRGeometryH geom)
Converts an OGR geometry representation to a QgsGeometry object.
static QString OGRSpatialReferenceToWkt(OGRSpatialReferenceH srs)
Returns a WKT string corresponding to the specified OGR srs object.
static QgsFeature readOgrFeature(OGRFeatureH ogrFet, const QgsFields &fields, QTextCodec *encoding)
Reads an OGR feature and converts it to a QgsFeature.
static QStringList cStringListToQStringList(char **stringList)
Converts a c string list to a QStringList.
static QgsFields readOgrFields(OGRFeatureH ogrFet, QTextCodec *encoding)
Reads an OGR feature and returns a corresponding fields collection.
static QgsWkbTypes::Type ogrGeometryTypeToQgsWkbType(OGRwkbGeometryType ogrGeomType)
Converts a OGRwkbGeometryType to QgsWkbTypes::Type.
static QgsCoordinateReferenceSystem OGRSpatialReferenceToCrs(OGRSpatialReferenceH srs)
Returns a QgsCoordinateReferenceSystem corresponding to the specified OGR srs object,...
static QgsFeatureList stringToFeatureList(const QString &string, const QgsFields &fields, QTextCodec *encoding)
Attempts to parse a string representing a collection of features using OGR.
static QString readShapefileEncodingFromCpg(const QString &path)
Reads the encoding of the shapefile at the specified path (where path is the location of the "....
static bool readOgrFeatureGeometry(OGRFeatureH ogrFet, QgsFeature &feature)
Reads the geometry from an OGR feature into a QgsFeature.
static QgsFields stringToFields(const QString &string, QTextCodec *encoding)
Attempts to retrieve the fields from a string representing a collection of features using OGR.
static QString readShapefileEncodingFromLdid(const QString &path)
Reads the encoding of the shapefile at the specified path (where path is the location of the "....
static QVariant getOgrFeatureAttribute(OGRFeatureH ogrFet, const QgsFields &fields, int attIndex, QTextCodec *encoding, bool *ok=nullptr)
Retrieves an attribute value from an OGR feature.
static bool hasM(Type type) SIP_HOLDGIL
Tests whether a WKB type contains m values.
Type
The WKB type describes the number of dimensions a geometry has.
static Type zmType(Type type, bool hasZ, bool hasM) SIP_HOLDGIL
Returns the modified input geometry type according to hasZ / hasM.
static Type flatType(Type type) SIP_HOLDGIL
Returns the flat type for a WKB type.
static bool hasZ(Type type) SIP_HOLDGIL
Tests whether a WKB type contains the z-dimension.
void CORE_EXPORT fast_delete_and_close(dataset_unique_ptr &dataset, GDALDriverH driver, const QString &path)
Performs a fast close of an unwanted GDAL dataset handle by deleting the underlying data store.
std::unique_ptr< std::remove_pointer< OGRFeatureH >::type, OGRFeatureDeleter > ogr_feature_unique_ptr
Scoped OGR feature.
std::unique_ptr< std::remove_pointer< GDALDatasetH >::type, GDALDatasetCloser > dataset_unique_ptr
Scoped GDAL dataset.
std::unique_ptr< std::remove_pointer< OGRDataSourceH >::type, OGRDataSourceDeleter > ogr_datasource_unique_ptr
Scoped OGR data source.
unsigned long long qgssize
Qgssize is used instead of size_t, because size_t is stdlib type, unknown by SIP, and it would be har...
void * OGRSpatialReferenceH
QList< QgsFeature > QgsFeatureList
std::unique_ptr< QgsLineString > ogrGeometryToQgsLineString(OGRGeometryH geom)
std::unique_ptr< QgsMultiLineString > ogrGeometryToQgsMultiLineString(OGRGeometryH geom)
#define OGR_F_IsFieldSetAndNotNull
std::unique_ptr< QgsMultiPoint > ogrGeometryToQgsMultiPoint(OGRGeometryH geom)
std::unique_ptr< QgsPoint > ogrGeometryToQgsPoint(OGRGeometryH geom)
void CORE_EXPORT operator()(GDALDatasetH datasource)
Destroys an gdal dataset, using the correct gdal calls.
void CORE_EXPORT operator()(GDALWarpOptions *options)
Destroys GDAL warp options, using the correct gdal calls.
void CORE_EXPORT operator()(OGRDataSourceH source)
Destroys an OGR data source, using the correct gdal calls.
void CORE_EXPORT operator()(OGRFeatureH feature)
Destroys an OGR feature, using the correct gdal calls.
void CORE_EXPORT operator()(OGRFieldDefnH definition)
Destroys an OGR field definition, using the correct gdal calls.
void CORE_EXPORT operator()(OGRGeometryH geometry)
Destroys an OGR geometry, using the correct gdal calls.