Skip to content

Commit

Permalink
- added warning and chance to cancel Natural break classification for
Browse files Browse the repository at this point in the history
  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 40e53e0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
9 changes: 9 additions & 0 deletions src/gui/symbology-ng/qgsgraduatedsymbolrendererv2widget.cpp
Expand Up @@ -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(
Expand Down
46 changes: 25 additions & 21 deletions tests/src/python/test_qgsissue6483.py
Expand Up @@ -14,6 +14,7 @@

import os
import random
import math

from qgis.core import *
from qgis.gui import *
Expand Down Expand Up @@ -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
Expand All @@ -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"""



Expand Down

0 comments on commit 40e53e0

Please sign in to comment.