Skip to content
Permalink
Browse files

Merge pull request #3507 from alexbruy/memory-provider-25d

Add support for 2.5D geometries to memory provider
  • Loading branch information
alexbruy committed Oct 6, 2016
2 parents 5d64a8b + eeb8269 commit dcdf91b09a2dcc4d9e9f54b5dcaf2fdd6bba18a9
@@ -52,17 +52,6 @@
from processing.tools import dataobjects, spatialite, postgis


GEOM_TYPE_MAP = {
QgsWkbTypes.NullGeometry: 'none',
QgsWkbTypes.Point: 'Point',
QgsWkbTypes.LineString: 'LineString',
QgsWkbTypes.Polygon: 'Polygon',
QgsWkbTypes.MultiPoint: 'MultiPoint',
QgsWkbTypes.MultiLineString: 'MultiLineString',
QgsWkbTypes.MultiPolygon: 'MultiPolygon',
}


TYPE_MAP = {
str: QVariant.String,
float: QVariant.Double,
@@ -561,7 +550,7 @@ def __init__(self, destination, encoding, fields, geometryType,
if self.destination.startswith(self.MEMORY_LAYER_PREFIX):
self.isNotFileBased = True

uri = GEOM_TYPE_MAP[geometryType] + "?uuid=" + str(uuid.uuid4())
uri = QgsWkbTypes.displayString(geometryType) + "?uuid=" + str(uuid.uuid4())
if crs.isValid():
uri += '&crs=' + crs.authid()
fieldsdesc = []
@@ -608,7 +597,7 @@ def _runSQL(sql):
if geometryType != QgsWkbTypes.NullGeometry:
_runSQL("SELECT AddGeometryColumn('{schema}', '{table}', 'the_geom', {srid}, '{typmod}', 2)".format(
table=uri.table().lower(), schema=uri.schema(), srid=crs.authid().split(":")[-1],
typmod=GEOM_TYPE_MAP[geometryType].upper()))
typmod=QgsWkbTypes.displayString(geometryType).upper()))

self.layer = QgsVectorLayer(uri.uri(), uri.table(), "postgres")
self.writer = self.layer.dataProvider()
@@ -640,7 +629,7 @@ def _runSQL(sql):
if geometryType != QgsWkbTypes.NullGeometry:
_runSQL("SELECT AddGeometryColumn('{table}', 'the_geom', {srid}, '{typmod}', 2)".format(
table=uri.table().lower(), srid=crs.authid().split(":")[-1],
typmod=GEOM_TYPE_MAP[geometryType].upper()))
typmod=QgsWkbTypes.displayString(geometryType).upper()))

self.layer = QgsVectorLayer(uri.uri(), uri.table(), "spatialite")
self.writer = self.layer.dataProvider()
@@ -7505,7 +7505,7 @@ QgsVectorLayer *QgisApp::pasteToNewMemoryVector()
if ( !feature.hasGeometry() )
continue;

QgsWkbTypes::Type type = QgsWkbTypes::flatType( feature.geometry().wkbType() );
QgsWkbTypes::Type type = feature.geometry().wkbType();

if ( type == QgsWkbTypes::Unknown || type == QgsWkbTypes::NoGeometry )
continue;
@@ -7535,7 +7535,7 @@ QgsVectorLayer *QgisApp::pasteToNewMemoryVector()

QgsWkbTypes::Type wkbType = !typeCounts.isEmpty() ? typeCounts.keys().value( 0 ) : QgsWkbTypes::NoGeometry;

QString typeName = wkbType != QgsWkbTypes::NoGeometry ? QString( QgsWkbTypes::displayString( wkbType ) ).remove( "WKB" ) : "none";
QString typeName = wkbType != QgsWkbTypes::NoGeometry ? QgsWkbTypes::displayString( wkbType ) : "none";

if ( features.isEmpty() )
{
@@ -7590,7 +7590,7 @@ QgsVectorLayer *QgisApp::pasteToNewMemoryVector()
if ( !feature.hasGeometry() )
continue;

QgsWkbTypes::Type type = QgsWkbTypes::flatType( feature.geometry().wkbType() );
QgsWkbTypes::Type type = feature.geometry().wkbType();
if ( type == QgsWkbTypes::Unknown || type == QgsWkbTypes::NoGeometry )
continue;

@@ -47,23 +47,14 @@ QgsMemoryProvider::QgsMemoryProvider( const QString& uri )
geometry = url.path();
}

geometry = geometry.toLower();
if ( geometry == "point" )
mWkbType = QgsWkbTypes::Point;
else if ( geometry == "linestring" )
mWkbType = QgsWkbTypes::LineString;
else if ( geometry == "polygon" )
mWkbType = QgsWkbTypes::Polygon;
else if ( geometry == "multipoint" )
mWkbType = QgsWkbTypes::MultiPoint;
else if ( geometry == "multilinestring" )
mWkbType = QgsWkbTypes::MultiLineString;
else if ( geometry == "multipolygon" )
mWkbType = QgsWkbTypes::MultiPolygon;
else if ( geometry == "none" )
if ( geometry.toLower() == "none" )
{
mWkbType = QgsWkbTypes::NoGeometry;
}
else
mWkbType = QgsWkbTypes::Unknown;
{
mWkbType = QgsWkbTypes::parseType( geometry );
}

if ( url.hasQueryItem( "crs" ) )
{
@@ -208,34 +199,7 @@ QString QgsMemoryProvider::dataSourceUri( bool expandAuthConfig ) const
Q_UNUSED( expandAuthConfig )

QUrl uri( "memory" );
QString geometry;
switch ( mWkbType )
{
case QgsWkbTypes::Point :
geometry = "Point";
break;
case QgsWkbTypes::LineString :
geometry = "LineString";
break;
case QgsWkbTypes::Polygon :
geometry = "Polygon";
break;
case QgsWkbTypes::MultiPoint :
geometry = "MultiPoint";
break;
case QgsWkbTypes::MultiLineString :
geometry = "MultiLineString";
break;
case QgsWkbTypes::MultiPolygon :
geometry = "MultiPolygon";
break;
case QgsWkbTypes::NoGeometry :
geometry = "None";
break;
default:
geometry = "";
break;
}
QString geometry = QgsWkbTypes::displayString( mWkbType );
uri.addQueryItem( "geometry", geometry );

if ( mCrs.isValid() )
@@ -127,6 +127,30 @@ def testLayerGeometry(self):
("MultiPoint", QgsWkbTypes.PointGeometry, QgsWkbTypes.MultiPoint),
("MultiLineString", QgsWkbTypes.LineGeometry, QgsWkbTypes.MultiLineString),
("MultiPolygon", QgsWkbTypes.PolygonGeometry, QgsWkbTypes.MultiPolygon),
("PointZ", QgsWkbTypes.PointGeometry, QgsWkbTypes.PointZ),
("LineStringZ", QgsWkbTypes.LineGeometry, QgsWkbTypes.LineStringZ),
("PolygonZ", QgsWkbTypes.PolygonGeometry, QgsWkbTypes.PolygonZ),
("MultiPointZ", QgsWkbTypes.PointGeometry, QgsWkbTypes.MultiPointZ),
("MultiLineStringZ", QgsWkbTypes.LineGeometry, QgsWkbTypes.MultiLineStringZ),
("MultiPolygonZ", QgsWkbTypes.PolygonGeometry, QgsWkbTypes.MultiPolygonZ),
("PointM", QgsWkbTypes.PointGeometry, QgsWkbTypes.PointM),
("LineStringM", QgsWkbTypes.LineGeometry, QgsWkbTypes.LineStringM),
("PolygonM", QgsWkbTypes.PolygonGeometry, QgsWkbTypes.PolygonM),
("MultiPointM", QgsWkbTypes.PointGeometry, QgsWkbTypes.MultiPointM),
("MultiLineStringM", QgsWkbTypes.LineGeometry, QgsWkbTypes.MultiLineStringM),
("MultiPolygonM", QgsWkbTypes.PolygonGeometry, QgsWkbTypes.MultiPolygonM),
("PointZM", QgsWkbTypes.PointGeometry, QgsWkbTypes.PointZM),
("LineStringZM", QgsWkbTypes.LineGeometry, QgsWkbTypes.LineStringZM),
("PolygonZM", QgsWkbTypes.PolygonGeometry, QgsWkbTypes.PolygonZM),
("MultiPointZM", QgsWkbTypes.PointGeometry, QgsWkbTypes.MultiPointZM),
("MultiLineStringZM", QgsWkbTypes.LineGeometry, QgsWkbTypes.MultiLineStringZM),
("MultiPolygonZM", QgsWkbTypes.PolygonGeometry, QgsWkbTypes.MultiPolygonZM),
("Point25D", QgsWkbTypes.PointGeometry, QgsWkbTypes.Point25D),
("LineString25D", QgsWkbTypes.LineGeometry, QgsWkbTypes.LineString25D),
("Polygon25D", QgsWkbTypes.PolygonGeometry, QgsWkbTypes.Polygon25D),
("MultiPoint25D", QgsWkbTypes.PointGeometry, QgsWkbTypes.MultiPoint25D),
("MultiLineString25D", QgsWkbTypes.LineGeometry, QgsWkbTypes.MultiLineString25D),
("MultiPolygon25D", QgsWkbTypes.PolygonGeometry, QgsWkbTypes.MultiPolygon25D),
("None", QgsWkbTypes.NullGeometry, QgsWkbTypes.NoGeometry)]
for v in testVectors:
layer = QgsVectorLayer(v[0], "test", "memory")

2 comments on commit dcdf91b

@nyalldawson

This comment has been minimized.

Copy link
Collaborator

@nyalldawson nyalldawson replied Oct 6, 2016

@alexbruy I think you undersold yourself with this commit message :) Doesn't this also bring full support for z/m geometries to processing?

@alexbruy

This comment has been minimized.

Copy link
Contributor Author

@alexbruy alexbruy replied Oct 6, 2016

Yes, it also adds support for Z/M/ZM geometries to Processing temporary outputs which now created as memory layers

Please sign in to comment.
You can’t perform that action at this time.