mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
Merge pull request #5827 from nirvn/spatialite_zm
[spatialite provider] Fix ZM support
This commit is contained in:
commit
3d1d82e7d2
@ -56,10 +56,10 @@ QgsNewSpatialiteLayerDialog::QgsNewSpatialiteLayerDialog( QWidget *parent, Qt::W
|
||||
restoreGeometry( settings.value( QStringLiteral( "Windows/NewSpatiaLiteLayer/geometry" ) ).toByteArray() );
|
||||
|
||||
mGeometryTypeBox->addItem( tr( "Point" ), QStringLiteral( "POINT" ) );
|
||||
mGeometryTypeBox->addItem( tr( "Line" ), QStringLiteral( "LINE" ) );
|
||||
mGeometryTypeBox->addItem( tr( "Line" ), QStringLiteral( "LINESTRING" ) );
|
||||
mGeometryTypeBox->addItem( tr( "Polygon" ), QStringLiteral( "POLYGON" ) );
|
||||
mGeometryTypeBox->addItem( tr( "MultiPoint" ), QStringLiteral( "MULTIPOINT" ) );
|
||||
mGeometryTypeBox->addItem( tr( "MultiLine" ), QStringLiteral( "MULTILINE" ) );
|
||||
mGeometryTypeBox->addItem( tr( "MultiLine" ), QStringLiteral( "MULTILINESTRING" ) );
|
||||
mGeometryTypeBox->addItem( tr( "MultiPolygon" ), QStringLiteral( "MULTIPOLYGON" ) );
|
||||
|
||||
mAddAttributeButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionNewAttribute.svg" ) ) );
|
||||
@ -147,6 +147,24 @@ QString QgsNewSpatialiteLayerDialog::selectedType() const
|
||||
return mGeometryTypeBox->currentData( Qt::UserRole ).toString();
|
||||
}
|
||||
|
||||
QString QgsNewSpatialiteLayerDialog::selectedZM() const
|
||||
{
|
||||
if ( mGeometryWithZCheckBox->isChecked() && !mGeometryWithMCheckBox->isChecked() )
|
||||
{
|
||||
return QStringLiteral( "XYZ" );
|
||||
}
|
||||
else if ( !mGeometryWithZCheckBox->isChecked() && mGeometryWithMCheckBox->isChecked() )
|
||||
{
|
||||
return QStringLiteral( "XYM" );
|
||||
}
|
||||
else if ( mGeometryWithZCheckBox->isChecked() && mGeometryWithMCheckBox->isChecked() )
|
||||
{
|
||||
return QStringLiteral( "XYZM" );
|
||||
}
|
||||
|
||||
return QStringLiteral( "XY" );
|
||||
}
|
||||
|
||||
void QgsNewSpatialiteLayerDialog::checkOk()
|
||||
{
|
||||
bool created = !leLayerName->text().isEmpty() &&
|
||||
@ -320,7 +338,8 @@ bool QgsNewSpatialiteLayerDialog::createDb()
|
||||
settings.setValue( QStringLiteral( "SpatiaLite/connections/selected" ), fi.fileName() + tr( "@" ) + fi.canonicalFilePath() );
|
||||
settings.setValue( key, fi.canonicalFilePath() );
|
||||
|
||||
QMessageBox::information( nullptr, tr( "SpatiaLite Database" ), tr( "Registered new database!" ) );
|
||||
// Reload connections to refresh browser panel
|
||||
QgisApp::instance()->reloadConnections();
|
||||
}
|
||||
|
||||
pbnFindSRID->setEnabled( true );
|
||||
@ -366,11 +385,12 @@ bool QgsNewSpatialiteLayerDialog::apply()
|
||||
|
||||
QgsDebugMsg( sql ); // OK
|
||||
|
||||
QString sqlAddGeom = QStringLiteral( "select AddGeometryColumn(%1,%2,%3,%4,2)" )
|
||||
QString sqlAddGeom = QStringLiteral( "select AddGeometryColumn(%1,%2,%3,%4,%5)" )
|
||||
.arg( quotedValue( leLayerName->text() ),
|
||||
quotedValue( leGeometryColumn->text() ) )
|
||||
.arg( mCrsId.split( ':' ).value( 1, QStringLiteral( "0" ) ).toInt() )
|
||||
.arg( quotedValue( selectedType() ) );
|
||||
.arg( quotedValue( selectedType() ) )
|
||||
.arg( quotedValue( selectedZM() ) );
|
||||
QgsDebugMsg( sqlAddGeom ); // OK
|
||||
|
||||
QString sqlCreateIndex = QStringLiteral( "select CreateSpatialIndex(%1,%2)" )
|
||||
@ -426,6 +446,9 @@ bool QgsNewSpatialiteLayerDialog::apply()
|
||||
leGeometryColumn->text() ), leLayerName->text(), QStringLiteral( "spatialite" ) );
|
||||
if ( layer->isValid() )
|
||||
{
|
||||
// Reload connections to refresh browser panel
|
||||
QgisApp::instance()->reloadConnections();
|
||||
|
||||
// register this layer with the central layers registry
|
||||
QList<QgsMapLayer *> myList;
|
||||
myList << layer;
|
||||
|
@ -55,6 +55,8 @@ class APP_EXPORT QgsNewSpatialiteLayerDialog: public QDialog, private Ui::QgsNew
|
||||
private:
|
||||
//! Returns the selected geometry type
|
||||
QString selectedType() const;
|
||||
//! Returns the selected Z dimension and/or M measurement
|
||||
QString selectedZM() const;
|
||||
|
||||
//! Create a new database
|
||||
bool createDb();
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -29,6 +29,8 @@ extern "C"
|
||||
#include "qgsrectangle.h"
|
||||
#include "qgsvectorlayerexporter.h"
|
||||
#include "qgsfields.h"
|
||||
#include "qgswkbtypes.h"
|
||||
|
||||
#include <list>
|
||||
#include <queue>
|
||||
#include <fstream>
|
||||
@ -356,7 +358,7 @@ class QgsSpatiaLiteProvider: public QgsVectorDataProvider
|
||||
unsigned char **wkb, int *geom_size,
|
||||
int dims );
|
||||
int computeSizeFromGeosWKB3D( const unsigned char *blob, int size,
|
||||
int type, int nDims, int little_endian,
|
||||
QgsWkbTypes::Type type, int nDims, int little_endian,
|
||||
int endian_arch );
|
||||
int computeSizeFromGeosWKB2D( const unsigned char *blob, int size,
|
||||
int type, int nDims, int little_endian,
|
||||
@ -366,17 +368,6 @@ class QgsSpatiaLiteProvider: public QgsVectorDataProvider
|
||||
|
||||
void insertDefaultValue( int fieldIndex, QString defaultVal );
|
||||
|
||||
enum GEOS_3D
|
||||
{
|
||||
GEOS_3D_POINT = -2147483647,
|
||||
GEOS_3D_LINESTRING = -2147483646,
|
||||
GEOS_3D_POLYGON = -2147483645,
|
||||
GEOS_3D_MULTIPOINT = -2147483644,
|
||||
GEOS_3D_MULTILINESTRING = -2147483643,
|
||||
GEOS_3D_MULTIPOLYGON = -2147483642,
|
||||
GEOS_3D_GEOMETRYCOLLECTION = -2147483641,
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles an error encountered while executing an sql statement.
|
||||
*/
|
||||
|
@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>450</width>
|
||||
<width>490</width>
|
||||
<height>627</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -142,6 +142,24 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1" colspan="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="mGeometryWithZCheckBox">
|
||||
<property name="text">
|
||||
<string>Include Z dimension</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="mGeometryWithMCheckBox">
|
||||
<property name="text">
|
||||
<string>Include M values</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="4" column="1" colspan="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="leSRID">
|
||||
@ -175,7 +193,7 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="4" colspan="3">
|
||||
<item row="5" colspan="3">
|
||||
<widget class="QGroupBox" name="groupBox1">
|
||||
<property name="title">
|
||||
<string>New field</string>
|
||||
@ -265,7 +283,7 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" colspan="3">
|
||||
<item row="6" colspan="3">
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>Fields list</string>
|
||||
@ -339,7 +357,7 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" colspan="3">
|
||||
<item row="7" colspan="3">
|
||||
<widget class="QgsCollapsibleGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Advanced options</string>
|
||||
|
@ -28,7 +28,8 @@ from qgis.core import (QgsVectorLayer,
|
||||
QgsFieldConstraints,
|
||||
QgsVectorLayerUtils,
|
||||
QgsSettings,
|
||||
QgsDefaultValue)
|
||||
QgsDefaultValue,
|
||||
QgsWkbTypes)
|
||||
|
||||
from qgis.testing import start_app, unittest
|
||||
from utilities import unitTestDataPath
|
||||
@ -91,6 +92,33 @@ class TestQgsSpatialiteProvider(unittest.TestCase, ProviderTestCase):
|
||||
sql += "VALUES (1, 'toto', GeomFromText('POLYGON((0 0,1 0,1 1,0 1,0 0))', 4326))"
|
||||
cur.execute(sql)
|
||||
|
||||
# table with Z dimension geometry
|
||||
sql = "CREATE TABLE test_z (id INTEGER NOT NULL PRIMARY KEY, name TEXT NOT NULL)"
|
||||
cur.execute(sql)
|
||||
sql = "SELECT AddGeometryColumn('test_z', 'geometry', 4326, 'POINT', 'XYZ')"
|
||||
cur.execute(sql)
|
||||
sql = "INSERT INTO test_z (id, name, geometry) "
|
||||
sql += "VALUES (1, 'toto', GeomFromText('POINT Z (0 0 1)', 4326))"
|
||||
cur.execute(sql)
|
||||
|
||||
# table with M value geometry
|
||||
sql = "CREATE TABLE test_m (id INTEGER NOT NULL PRIMARY KEY, name TEXT NOT NULL)"
|
||||
cur.execute(sql)
|
||||
sql = "SELECT AddGeometryColumn('test_m', 'geometry', 4326, 'POINT', 'XYM')"
|
||||
cur.execute(sql)
|
||||
sql = "INSERT INTO test_m (id, name, geometry) "
|
||||
sql += "VALUES (1, 'toto', GeomFromText('POINT M (0 0 1)', 4326))"
|
||||
cur.execute(sql)
|
||||
|
||||
# table with Z dimension and M value geometry
|
||||
sql = "CREATE TABLE test_zm (id INTEGER NOT NULL PRIMARY KEY, name TEXT NOT NULL)"
|
||||
cur.execute(sql)
|
||||
sql = "SELECT AddGeometryColumn('test_zm', 'geometry', 4326, 'POINT', 'XYZM')"
|
||||
cur.execute(sql)
|
||||
sql = "INSERT INTO test_zm (id, name, geometry) "
|
||||
sql += "VALUES (1, 'toto', GeomFromText('POINT ZM (0 0 1 1)', 4326))"
|
||||
cur.execute(sql)
|
||||
|
||||
# table with multiple column primary key
|
||||
sql = "CREATE TABLE test_pg_mk (id INTEGER NOT NULL, name TEXT NOT NULL, PRIMARY KEY(id,name))"
|
||||
cur.execute(sql)
|
||||
@ -308,6 +336,31 @@ class TestQgsSpatialiteProvider(unittest.TestCase, ProviderTestCase):
|
||||
self.assertEqual(sum_id1, 32)
|
||||
self.assertEqual(sum_id2, 32)
|
||||
|
||||
def test_zm(self):
|
||||
"""Test Z dimension and M value"""
|
||||
l = QgsVectorLayer("dbname=%s table='test_z' (geometry) key='id'" % self.dbname, "test_z", "spatialite")
|
||||
self.assertTrue(l.isValid())
|
||||
self.assertTrue(QgsWkbTypes.hasZ(l.wkbType()))
|
||||
feature = l.getFeature(1)
|
||||
geom = feature.geometry().constGet()
|
||||
self.assertEqual(geom.z(), 1.0)
|
||||
|
||||
l = QgsVectorLayer("dbname=%s table='test_m' (geometry) key='id'" % self.dbname, "test_m", "spatialite")
|
||||
self.assertTrue(l.isValid())
|
||||
self.assertTrue(QgsWkbTypes.hasM(l.wkbType()))
|
||||
feature = l.getFeature(1)
|
||||
geom = feature.geometry().constGet()
|
||||
self.assertEqual(geom.m(), 1.0)
|
||||
|
||||
l = QgsVectorLayer("dbname=%s table='test_zm' (geometry) key='id'" % self.dbname, "test_zm", "spatialite")
|
||||
self.assertTrue(l.isValid())
|
||||
self.assertTrue(QgsWkbTypes.hasZ(l.wkbType()))
|
||||
self.assertTrue(QgsWkbTypes.hasM(l.wkbType()))
|
||||
feature = l.getFeature(1)
|
||||
geom = feature.geometry().constGet()
|
||||
self.assertEqual(geom.z(), 1.0)
|
||||
self.assertEqual(geom.m(), 1.0)
|
||||
|
||||
def test_case(self):
|
||||
"""Test case sensitivity issues"""
|
||||
l = QgsVectorLayer("dbname=%s table='test_n' (geometry) key='id'" % self.dbname, "test_n1", "spatialite")
|
||||
|
Loading…
x
Reference in New Issue
Block a user