Skip to content
Permalink
Browse files

- added warning and chance to cancel Natural break classification for

  dataset >50k records
- modified test script to generate gowing sizes tables (for timing)
  • Loading branch information
vmora committed Jul 12, 2013
1 parent 18cff28 commit 40e53e08a18cc2a8efca9a6bf5a8c8f93912851a
Showing with 34 additions and 21 deletions.
  1. +9 −0 src/gui/symbology-ng/qgsgraduatedsymbolrendererv2widget.cpp
  2. +25 −21 tests/src/python/test_qgsissue6483.py
@@ -482,6 +482,15 @@ void QgsGraduatedSymbolRendererV2Widget::classifyGraduated()
else // default should be quantile for now
mode = QgsGraduatedSymbolRendererV2::Quantile;


// Jenks is n^2 complexity, warn for big dataset (more than 50k records)
// and give the user the chance to cancel
if ( QgsGraduatedSymbolRendererV2::Jenks == mode
&& mLayer->featureCount() > 50000 )
{
if ( QMessageBox::Cancel == QMessageBox::question( this, tr( "Warning" ), tr( "Natural break classification (Jenks) is O(n2) complexity, your classification may take a long time." ), QMessageBox::Cancel, QMessageBox::Ok ) ) return;
}

// create and set new renderer
QApplication::setOverrideCursor( Qt::WaitCursor );
QgsGraduatedSymbolRendererV2* r = QgsGraduatedSymbolRendererV2::createRenderer(
@@ -14,6 +14,7 @@

import os
import random
import math

from qgis.core import *
from qgis.gui import *
@@ -45,23 +46,29 @@ def setUpClass(cls):
sql = "SELECT InitSpatialMetadata()"
cur.execute(sql)

# simple table with primary key
sql = "CREATE TABLE test_mpg (id SERIAL PRIMARY KEY, height DOUBLE)"
cur.execute(sql)
sql = "SELECT AddGeometryColumn('test_mpg', 'geometry', 4326, 'MULTIPOLYGON', 'XY')"
cur.execute(sql)
for i in range(0,253):
for j in range (0,253):
sql = "INSERT INTO test_mpg (height, geometry) "
sql += "VALUES ("+str(random.random())+", GeomFromText('MULTIPOLYGON((("
sql += str(i) + " " + str(j) + ","
sql += str(i+1) + " " + str(j) + ","
sql += str(i+1) + " " + str(j+1) + ","
sql += str(i) + " " + str(j+1) + ","
sql += str(i) + " " + str(j) + ")))', 4326))"
cur.execute(sql)

con.commit()
# growing size tables
nbOrders = 7
for order in range(0,nbOrders):
size = 10000*pow(2,order);
tab = "test_mpg_" + str(size) + "_rows"
print "creating table " + tab + " " + str(order) + "/" + str(nbOrders)
sql = "CREATE TABLE " + tab + " (id SERIAL PRIMARY KEY, height DOUBLE)"
cur.execute(sql)
sql = "SELECT AddGeometryColumn('" + tab + "', 'geometry', 4326, 'MULTIPOLYGON', 'XY')"
cur.execute(sql)
r = int(math.sqrt(size))
for i in range(0,r):
for j in range (0,r):
sql = "INSERT INTO " + tab + " (height, geometry) "
sql += "VALUES ("+str(random.random())+", GeomFromText('MULTIPOLYGON((("
sql += str(i) + " " + str(j) + ","
sql += str(i+1) + " " + str(j) + ","
sql += str(i+1) + " " + str(j+1) + ","
sql += str(i) + " " + str(j+1) + ","
sql += str(i) + " " + str(j) + ")))', 4326))"
cur.execute(sql)
con.commit()

con.close()

@classmethod
@@ -81,10 +88,7 @@ def tearDown(self):
pass

def test_Nothing(self):
"""Create spatialite database"""
layer = QgsVectorLayer("dbname=test.sqlite table=test_mpg (geometry)", "test_mpg", "spatialite")
assert(layer.isValid())
assert(layer.hasGeometryType())
"""do nothing"""



0 comments on commit 40e53e0

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