Skip to content

Commit

Permalink
[postgis] Fix creation of new Z/M enabled, curved geometry type layers
Browse files Browse the repository at this point in the history
(cherry picked from commit 07746db)
  • Loading branch information
nyalldawson committed Feb 12, 2019
1 parent 05dd5f1 commit a61abe5
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion src/providers/postgres/qgspostgresprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3769,6 +3769,46 @@ bool QgsPostgresProvider::convertField( QgsField &field, const QMap<QString, QVa
return true;
}


void postgisGeometryType( QgsWkbTypes::Type wkbType, QString &geometryType, int &dim )
{
dim = 2;
QgsWkbTypes::Type flatType = QgsWkbTypes::flatType( wkbType );
geometryType = QgsWkbTypes::displayString( flatType ).toUpper();
switch ( flatType )
{
case QgsWkbTypes::Unknown:
geometryType = QStringLiteral( "GEOMETRY" );
break;

case QgsWkbTypes::NoGeometry:
geometryType.clear();
dim = 0;
break;

default:
break;
}

if ( QgsWkbTypes::hasZ( wkbType ) && QgsWkbTypes::hasM( wkbType ) )
{
dim = 4;
}
else if ( QgsWkbTypes::hasZ( wkbType ) )
{
dim = 3;
}
else if ( QgsWkbTypes::hasM( wkbType ) )
{
geometryType += QLatin1String( "M" );
dim = 3;
}
else if ( wkbType >= QgsWkbTypes::Point25D && wkbType <= QgsWkbTypes::MultiPolygon25D )
{
dim = 3;
}
}

QgsVectorLayerExporter::ExportError QgsPostgresProvider::createEmptyLayer( const QString &uri,
const QgsFields &fields,
QgsWkbTypes::Type wkbType,
Expand Down Expand Up @@ -3953,7 +3993,7 @@ QgsVectorLayerExporter::ExportError QgsPostgresProvider::createEmptyLayer( const
int dim = 2;
long srid = srs.postgisSrid();

QgsPostgresConn::postgisWkbType( wkbType, geometryType, dim );
postgisGeometryType( wkbType, geometryType, dim );

// create geometry column
if ( !geometryType.isEmpty() )
Expand Down

0 comments on commit a61abe5

Please sign in to comment.