Skip to content
Permalink
Browse files

Add provider test to ensure that extent is correctly calculated

for layers with 1 point and also no features

The first scenario should return an 'empty' rectangle with x/y
min/max matching just the single point's coordinate, the
second scenario must return a null rectangle (not an empty 0,0
rectangle!)
  • Loading branch information
nyalldawson committed Nov 18, 2017
1 parent af6b4cc commit 1cfd6ee829cd48639371cd1215e71b4d72f1d6bd
Showing with 31 additions and 2 deletions.
  1. +31 −2 tests/src/python/providertestbase.py
@@ -184,6 +184,14 @@ def getSubsetString2(self):
"""Individual providers may need to override this depending on their subset string formats"""
return '"cnt" > 100 and "cnt" < 400'

def getSubsetString3(self):
"""Individual providers may need to override this depending on their subset string formats"""
return '"name"=\'Apple\''

def getSubsetStringNoMatching(self):
"""Individual providers may need to override this depending on their subset string formats"""
return '"name"=\'AppleBearOrangePear\''

def testOrderBy(self):
try:
self.disableCompiler()
@@ -281,9 +289,30 @@ def testMaxValue(self):
def testExtent(self):
reference = QgsGeometry.fromRect(
QgsRectangle(-71.123, 66.33, -65.32, 78.3))
provider_extent = QgsGeometry.fromRect(self.source.extent())
provider_extent = self.source.extent()
self.assertAlmostEqual(provider_extent.xMinimum(), -71.123, 3)
self.assertAlmostEqual(provider_extent.xMaximum(), -65.32, 3)
self.assertAlmostEqual(provider_extent.yMinimum(), 66.33, 3)
self.assertAlmostEqual(provider_extent.yMaximum(), 78.3, 3)

# with only one point
subset = self.getSubsetString3()
self.source.setSubsetString(subset)
self.assertEqual(self.source.featureCount(), 1)
provider_extent = self.source.extent()
self.source.setSubsetString(None)
self.assertAlmostEqual(provider_extent.xMinimum(), -68.2, 3)
self.assertAlmostEqual(provider_extent.xMaximum(), -68.2, 3)
self.assertAlmostEqual(provider_extent.yMinimum(), 70.8, 3)
self.assertAlmostEqual(provider_extent.yMaximum(), 70.8, 3)

self.assertTrue(QgsGeometry.compare(provider_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001))
# with no points
subset = self.getSubsetStringNoMatching()
self.source.setSubsetString(subset)
self.assertEqual(self.source.featureCount(), 0)
provider_extent = self.source.extent()
self.source.setSubsetString(None)
self.assertTrue(provider_extent.isNull())

def testUnique(self):
self.assertEqual(set(self.source.uniqueValues(1)), set([-200, 100, 200, 300, 400]))

0 comments on commit 1cfd6ee

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