Skip to content
Permalink
Browse files

Merge pull request #2653 from SebDieBln/MemoryLayerNoGeometry

[FEATURE] allow geometryless memory layers
  • Loading branch information
nyalldawson committed Jan 9, 2016
2 parents 4e1cf3c + 6ef2f5d commit a54c8b162ecc4c493184e0b30074000120bbdf39
@@ -38,7 +38,6 @@ QgsVectorLayer *QgsNewMemoryLayerDialog::runAndCreateLayer( QWidget *parent )
}

QGis::WkbType geometrytype = dialog.selectedType();
QString crsId = dialog.crs().authid();

QString geomType;
switch ( geometrytype )
@@ -61,11 +60,18 @@ QgsVectorLayer *QgsNewMemoryLayerDialog::runAndCreateLayer( QWidget *parent )
case QGis::WKBMultiPolygon:
geomType = "multipolygon";
break;
case QGis::WKBNoGeometry:
geomType = "none";
break;
default:
geomType = "point";
}

QString layerProperties = QString( "%1?crs=%2&memoryid=%3" ).arg( geomType, crsId, QUuid::createUuid().toString() );
QString layerProperties = QString( "%1?" ).arg( geomType );
if ( QGis::WKBNoGeometry != geometrytype )
layerProperties.append( QString( "crs=%1&" ).arg( dialog.crs().authid() ) );
layerProperties.append( QString( "memoryid=%1" ).arg( QUuid::createUuid().toString() ) );

QString name = dialog.layerName().isEmpty() ? tr( "New scratch layer" ) : dialog.layerName();
QgsVectorLayer* newLayer = new QgsVectorLayer( layerProperties, name, QString( "memory" ) );
return newLayer;
@@ -97,7 +103,11 @@ QgsNewMemoryLayerDialog::~QgsNewMemoryLayerDialog()

QGis::WkbType QgsNewMemoryLayerDialog::selectedType() const
{
if ( mPointRadioButton->isChecked() )
if ( !buttonGroupGeometry->isChecked() )
{
return QGis::WKBNoGeometry;
}
else if ( mPointRadioButton->isChecked() )
{
return QGis::WKBPoint;
}
@@ -60,6 +60,8 @@ QgsMemoryProvider::QgsMemoryProvider( const QString& uri )
mWkbType = QGis::WKBMultiLineString;
else if ( geometry == "multipolygon" )
mWkbType = QGis::WKBMultiPolygon;
else if ( geometry == "none" )
mWkbType = QGis::WKBNoGeometry;
else
mWkbType = QGis::WKBUnknown;

@@ -201,6 +203,9 @@ QString QgsMemoryProvider::dataSourceUri( bool expandAuthConfig ) const
case QGis::WKBMultiPolygon :
geometry = "MultiPolygon";
break;
case QGis::WKBNoGeometry :
geometry = "None";
break;
default:
geometry = "";
break;
@@ -24,50 +24,64 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="buttonGroup1">
<widget class="QGroupBox" name="buttonGroupGeometry">
<property name="title">
<string>Type</string>
<string>Geometry type and CRS</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QRadioButton" name="mPointRadioButton">
<property name="text">
<string>Point</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QRadioButton" name="mLineRadioButton">
<property name="text">
<string>Line</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QRadioButton" name="mPolygonRadioButton">
<property name="text">
<string>Polygon</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="mMultiPointRadioButton">
<property name="text">
<string>Multipoint</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QRadioButton" name="mMultiLineRadioButton">
<property name="text">
<string>Multiline</string>
</property>
</widget>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QRadioButton" name="mMultiPointRadioButton">
<property name="text">
<string>Multipoint</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QRadioButton" name="mMultiPolygonRadioButton">
<property name="text">
<string>Multipolygon</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QRadioButton" name="mPolygonRadioButton">
<property name="text">
<string>Polygon</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QRadioButton" name="mPointRadioButton">
<property name="text">
<string>Point</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QRadioButton" name="mLineRadioButton">
<property name="text">
<string>Line</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QRadioButton" name="mMultiLineRadioButton">
<property name="text">
<string>Multiline</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="2">
<widget class="QRadioButton" name="mMultiPolygonRadioButton">
<property name="text">
<string>Multipolygon</string>
<item>
<widget class="QgsProjectionSelectionWidget" name="mCrsSelector" native="true">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item>
@@ -88,13 +102,6 @@
</item>
</layout>
</item>
<item>
<widget class="QgsProjectionSelectionWidget" name="mCrsSelector" native="true">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
@@ -144,14 +151,14 @@
</customwidgets>
<tabstops>
<tabstop>mNameLineEdit</tabstop>
<tabstop>buttonGroupGeometry</tabstop>
<tabstop>mPointRadioButton</tabstop>
<tabstop>mLineRadioButton</tabstop>
<tabstop>mPolygonRadioButton</tabstop>
<tabstop>mMultiPointRadioButton</tabstop>
<tabstop>mMultiLineRadioButton</tabstop>
<tabstop>mMultiPolygonRadioButton</tabstop>
<tabstop>mCrsSelector</tabstop>
<tabstop>mButtonBox</tabstop>
</tabstops>
<resources/>
<connections>
@@ -69,20 +69,30 @@ def setUpClass(cls):
def tearDownClass(cls):
"""Run after all tests"""

def testPointCtor(self):
layer = QgsVectorLayer("Point", "test", "memory")
assert layer.isValid(), "Failed to create valid point memory layer"
def testCtors(self):
testVectors = ["Point", "LineString", "Polygon", "MultiPoint", "MultiLineString", "MultiPolygon", "None"]
for v in testVectors:
layer = QgsVectorLayer(v, "test", "memory")
assert layer.isValid(), "Failed to create valid %s memory layer" % (v)

def testLayerGeometry(self):
layer = QgsVectorLayer("Point", "test", "memory")
testVectors = [("Point", QGis.Point, QGis.WKBPoint),
("LineString", QGis.Line, QGis.WKBLineString),
("Polygon", QGis.Polygon, QGis.WKBPolygon),
("MultiPoint", QGis.Point, QGis.WKBMultiPoint),
("MultiLineString", QGis.Line, QGis.WKBMultiLineString),
("MultiPolygon", QGis.Polygon, QGis.WKBMultiPolygon),
("None", QGis.NoGeometry, QGis.WKBNoGeometry)]
for v in testVectors:
layer = QgsVectorLayer(v[0], "test", "memory")

myMessage = ('Expected: %s\nGot: %s\n' %
(QGis.Point, layer.geometryType()))
assert layer.geometryType() == QGis.Point, myMessage
myMessage = ('Expected: %s\nGot: %s\n' %
(v[1], layer.geometryType()))
assert layer.geometryType() == v[1], myMessage

myMessage = ('Expected: %s\nGot: %s\n' %
(QGis.WKBPoint, layer.wkbType()))
assert layer.wkbType() == QGis.WKBPoint, myMessage
myMessage = ('Expected: %s\nGot: %s\n' %
(v[2], layer.wkbType()))
assert layer.wkbType() == v[2], myMessage

def testAddFeatures(self):
layer = QgsVectorLayer("Point", "test", "memory")

0 comments on commit a54c8b1

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