def checkSagaIsInstalled(ignoreRegistrySettings=False): if SextanteUtils.isWindows(): path = SagaUtils.sagaPath() if path == "": return "SAGA folder is not configured.\nPlease configure it before running SAGA algorithms." cmdpath = os.path.join(path, "saga_cmd.exe") if not os.path.exists(cmdpath): return ( "The specified SAGA folder does not contain a valid SAGA executable.\n" + "Please, go to the SEXTANTE settings dialog, and check that the SAGA\n" + "folder is correctly configured") settings = QSettings() SAGA_INSTALLED = "/SextanteQGIS/SagaInstalled" if not ignoreRegistrySettings: if settings.contains(SAGA_INSTALLED): return try: from sextante import runalg result = runalg("saga:thiessenpolygons", points(), None) if not os.path.exists(result['POLYGONS']): return "It seems that SAGA is not correctly installed in your system.\nPlease install it before running SAGA algorithms." except: s = traceback.format_exc() return "Error while checking SAGA installation. SAGA might not be correctly configured.\n" + s settings.setValue(SAGA_INSTALLED, True)
def checkGrassIsInstalled(ignoreRegistrySettings=False): if SextanteUtils.isWindows(): path = GrassUtils.grassPath() if path == "": return "GRASS folder is not configured.\nPlease configure it before running SAGA algorithms." cmdpath = os.path.join(path, "bin","r.out.gdal.exe") if not os.path.exists(cmdpath): return ("The specified GRASS folder does not contain a valid set of GRASS modules.\n" + "Please, go to the SEXTANTE settings dialog, and check that the GRASS\n" + "folder is correctly configured") settings = QSettings() GRASS_INSTALLED = "/SextanteQGIS/GrassInstalled" if not ignoreRegistrySettings: if settings.contains(GRASS_INSTALLED): return try: from sextante import runalg result = runalg("grass:v.voronoi", points(),False,False,"270778.60198,270855.745301,4458921.97814,4458983.8488",-1,0.0001, 0, None) if not os.path.exists(result['output']): return "It seems that GRASS is not correctly installed and configured in your system.\nPlease install it before running GRASS algorithms." except: s = traceback.format_exc() return "Error while checking GRASS installation. GRASS might not be correctly configured.\n" + s; settings.setValue(GRASS_INSTALLED, True)
def checkSagaIsInstalled(ignoreRegistrySettings=False): if SextanteUtils.isWindows(): path = SagaUtils.sagaPath() if path == "": return "SAGA folder is not configured.\nPlease configure it before running SAGA algorithms." cmdpath = os.path.join(path, "saga_cmd.exe") if not os.path.exists(cmdpath): return ("The specified SAGA folder does not contain a valid SAGA executable.\n" + "Please, go to the SEXTANTE settings dialog, and check that the SAGA\n" + "folder is correctly configured") settings = QSettings() if not ignoreRegistrySettings: SAGA_INSTALLED = "/SextanteQGIS/SagaInstalled" if settings.contains(SAGA_INSTALLED): return try: from sextante.core.Sextante import runalg result = runalg("saga:thiessenpolygons", points(), None) if not os.path.exists(result['POLYGONS']): return "It seems that SAGA is not correctly installed in your system.\nPlease install it before running SAGA algorithms." except: s = traceback.format_exc() return "Error while checking SAGA installation. SAGA might not be correctly configured.\n" + s; settings.setValue(SAGA_INSTALLED, True)
def checkGrassIsInstalled(ignoreRegistrySettings=False): if SextanteUtils.isWindows(): path = GrassUtils.grassPath() if path == "": return "GRASS folder is not configured.\nPlease configure it before running SAGA algorithms." cmdpath = os.path.join(path, "bin","r.out.gdal.exe") if not os.path.exists(cmdpath): return ("The specified GRASS folder does not contain a valid set of GRASS modules.\n" + "Please, go to the SEXTANTE settings dialog, and check that the GRASS\n" + "folder is correctly configured") settings = QSettings() GRASS_INSTALLED = "/SextanteQGIS/GrassInstalled" if not ignoreRegistrySettings: if settings.contains(GRASS_INSTALLED): return try: from sextante import runalg result = runalg("grass:v.voronoi", points(),False,False,"270778.60198,270855.745301,4458921.97814,4458983.8488",-1,0.0001,None) if not os.path.exists(result['output']): return "It seems that GRASS is not correctly installed and configured in your system.\nPlease install it before running GRASS algorithms." except: s = traceback.format_exc() return "Error while checking GRASS installation. GRASS might not be correctly configured.\n" + s; settings.setValue(GRASS_INSTALLED, True)
def test_attributeValues(self): layer = sextante.getobject(points()) attributeValues = values(layer, "ID") i = 1 for value in attributeValues['ID']: self.assertEqual(int(i), int(value)) i += 1 self.assertEquals(13, i)
def test_featuresWithSelection(self): layer = sextante.getobject(points()) feature = layer.getFeatures().next() selected = [feature.id()] layer.setSelectedFeatures(selected) features = sextante.getfeatures(layer) self.assertEqual(1, len(features)) layer.setSelectedFeatures([])
def test_attributeValues(self): layer = sextante.getobject(points()) attributeValues = values(layer, "ID") i = 1 for value in attributeValues['ID']: self.assertEqual(int(i), int(value)) i+=1 self.assertEquals(13,i)
def test_qgiscountpointsinpolygon(self): outputs=sextante.runalg("qgis:countpointsinpolygon",polygons(),points(),"NUMPOINTS", self.getOutputFile()) output=outputs['OUTPUT'] layer=QGisLayers.getObjectFromUri(output, True) fields=layer.pendingFields() expectednames=['ID','POLY_NUM_A','POLY_ST_A','NUMPOINTS'] expectedtypes=['Integer','Real','String','Real'] names=[str(f.name()) for f in fields] types=[str(f.typeName()) for f in fields] self.assertEqual(expectednames, names) self.assertEqual(expectedtypes, types) features=sextante.getfeatures(layer) self.assertEqual(2, len(features)) feature=features.next() attrs=feature.attributes() expectedvalues=["1","1.1","string a","6"] values=[str(attr.toString()) for attr in attrs] self.assertEqual(expectedvalues, values)
def testWrongformat(self): outputs=sextante.runalg("qgis:countpointsinpolygon",polygons(),points(),"NUMPOINTS",SextanteUtils.getTempFilename("wrongext")) output=outputs['OUTPUT'] self.assertTrue(output.endswith('shp')) layer=QGisLayers.getObjectFromUri(output, True) fields=layer.pendingFields() expectednames=['ID','POLY_NUM_A','POLY_ST_A','NUMPOINTS'] expectedtypes=['Integer','Real','String','Real'] names=[str(f.name()) for f in fields] types=[str(f.typeName()) for f in fields] self.assertEqual(expectednames, names) self.assertEqual(expectedtypes, types) features=sextante.getfeatures(layer) self.assertEqual(2, len(features)) feature=features.next() attrs=feature.attributes() expectedvalues=["1","1.1","string a","6.0"] values=[str(attr) for attr in attrs] self.assertEqual(expectedvalues, values)
def test_modelersagagrass(self): outputs=sextante.runalg("modeler:sagagrass",points(),None) output=outputs['CENTROIDS_ALG1'] layer=QGisLayers.getObjectFromUri(output, True) fields=layer.pendingFields() expectednames=['CAT'] expectedtypes=['Real'] names=[str(f.name()) for f in fields] types=[str(f.typeName()) for f in fields] self.assertEqual(expectednames, names) self.assertEqual(expectedtypes, types) features=sextante.getfeatures(layer) self.assertEqual(12, len(features)) feature=features.next() attrs=feature.attributes() expectedvalues=["1"] values=[str(attr.toString()) for attr in attrs] self.assertEqual(expectedvalues, values) wkt='POINT(270839.65586926 4458983.16267036)' self.assertEqual(wkt, str(feature.geometry().exportToWkt()))
def test_modeleroptionalfield(self): outputs=sextante.runalg("modeler:optionalfield",points(),None) output=outputs['OUTPUT_ALG0'] layer=QGisLayers.getObjectFromUri(output, True) fields=layer.pendingFields() expectednames=['id','value','area','perim'] expectedtypes=['Integer','String','Real','Real'] names=[str(f.name()) for f in fields] types=[str(f.typeName()) for f in fields] self.assertEqual(expectednames, names) self.assertEqual(expectedtypes, types) features=sextante.getfeatures(layer) self.assertEqual(1, len(features)) feature=features.next() attrs=feature.attributes() expectedvalues=["0","all","3592.818848","230.989919"] values=[str(attr.toString()) for attr in attrs] self.assertEqual(expectedvalues, values) wkt='POLYGON((270839.46818665 4458921.97813894,270778.60197966 4458935.96883677,270786.54279065 4458980.04784113,270803.15756434 4458983.84880322,270839.65586926 4458983.16267036,270855.74530134 4458940.79948673,270839.46818665 4458921.97813894))' self.assertEqual(wkt, str(feature.geometry().exportToWkt()))
def testWrongformat(self): outputs = sextante.runalg("qgis:countpointsinpolygon", polygons(), points(), "NUMPOINTS", SextanteUtils.getTempFilename("wrongext")) output = outputs['OUTPUT'] self.assertTrue(output.endswith('shp')) layer = QGisLayers.getObjectFromUri(output, True) fields = layer.pendingFields() expectednames = ['ID', 'POLY_NUM_A', 'POLY_ST_A', 'NUMPOINTS'] expectedtypes = ['Integer', 'Real', 'String', 'Real'] names = [str(f.name()) for f in fields] types = [str(f.typeName()) for f in fields] self.assertEqual(expectednames, names) self.assertEqual(expectedtypes, types) features = sextante.getfeatures(layer) self.assertEqual(2, len(features)) feature = features.next() attrs = feature.attributes() expectedvalues = ["1", "1.1", "string a", "6.0"] values = [str(attr) for attr in attrs] self.assertEqual(expectedvalues, values)
def test_getobject(self): layer = sextante.getobject(points()) self.assertIsNotNone(layer) layer = sextante.getobject("points") self.assertIsNotNone(layer)
def test_runandload(self): sextante.runandload("qgis:countpointsinpolygon", polygons(), points(), "NUMPOINTS", None) layer = getfromname("Result") self.assertIsNotNone(layer)
def test_featuresWithoutSelection(self): layer = sextante.getobject(points()) features = sextante.getfeatures(layer) self.assertEqual(12, len(features))
def test_getobject(self): layer = sextante.getobject(points()); self.assertIsNotNone(layer) layer = sextante.getobject("points"); self.assertIsNotNone(layer)
def test_runandload(self): sextante.runandload("qgis:countpointsinpolygon",polygons(),points(),"NUMPOINTS", None) layer = getfromname("Result") self.assertIsNotNone(layer)