def run_script(iface): """ this shall be called from Script Runner""" sextante.alglist() sextante.alghelp("grass:r.los") dem = sys.argv[1] out_uri = sys.argv[2] x = sys.argv[3] y = sys.argv[4] sextante.runalg("grass:r.los", input=dem, coordinate=",".join(x,y), output=out_uri)
def test_sagametricconversions(self): outputs = sextante.runalg("saga:metricconversions", raster(), 0, None) output = outputs['CONV'] self.assertTrue(os.path.isfile(output)) dataset = gdal.Open(output, GA_ReadOnly) strhash = hash(str(dataset.ReadAsArray(0).tolist())) self.assertEqual(strhash, -2137931723)
def test_SagaVectorAlgorithWithUnsupportedInputAndOutputFormat(self): '''this tests both the exporting to shp and then the format change in the output layer''' layer = sextante.getobject(polygonsGeoJson()); feature = layer.getFeatures().next() selected = [feature.id()] layer.setSelectedFeatures(selected) outputs=sextante.runalg("saga:polygoncentroids",polygonsGeoJson(),True, SextanteUtils.getTempFilename("geojson")) layer.setSelectedFeatures([]) output=outputs['CENTROIDS'] layer=QGisLayers.getObjectFromUri(output, True) fields=layer.pendingFields() expectednames=['ID','POLY_NUM_A','POLY_ST_A'] expectedtypes=['Real','Real','String'] 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","1.1","string a"] values=[str(attr.toString()) for attr in attrs] self.assertEqual(expectedvalues, values) wkt='POINT(270787.49991451 4458955.46775295)' self.assertEqual(wkt, str(feature.geometry().exportToWkt()))
def test_sagasortgrid(self): outputs = sextante.runalg("saga:sortgrid", raster(), True, None) output = outputs['OUTPUT'] self.assertTrue(os.path.isfile(output)) dataset = gdal.Open(output, GA_ReadOnly) strhash = hash(str(dataset.ReadAsArray(0).tolist())) self.assertEqual(strhash, 1320073153)
def test_gdalogrogr2ogrWrongExtension(self): outputs = sextante.runalg("gdalogr:ogr2ogr", union(), 3, "", SextanteUtils.getTempFilename("wrongext")) output = outputs['OUTPUT_LAYER'] layer = QGisLayers.getObjectFromUri(output, True) fields = layer.pendingFields() expectednames = [ 'id', 'poly_num_a', 'poly_st_a', 'id_2', 'poly_num_b', 'poly_st_b' ] expectedtypes = [ 'Integer', 'Real', 'String', 'Integer', 'Real', 'String' ] 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(8, len(features)) feature = features.next() attrs = feature.attributes() expectedvalues = ["1", "1.1", "string a", "2", "1", "string a"] values = [str(attr) for attr in attrs] self.assertEqual(expectedvalues, values) wkt = 'POLYGON((270807.08580285 4458940.1594565,270798.42294527 4458914.62661676,270780.81854858 4458914.21983449,270763.52289518 4458920.715993,270760.3449542 4458926.6570575,270763.78234766 4458958.22561242,270794.30290024 4458942.16424502,270807.08580285 4458940.1594565))' self.assertEqual(wkt, str(feature.geometry().exportToWkt()))
def test_gdalogrmerge(self): outputs=sextante.runalg("gdalogr:merge",raster(),False,False,None) output=outputs['OUTPUT'] self.assertTrue(os.path.isfile(output)) dataset=gdal.Open(output, GA_ReadOnly) strhash=hash(str(dataset.ReadAsArray(0).tolist())) self.assertEqual(strhash,-1353696889)
def test_sagasortgrid(self): outputs=sextante.runalg("saga:sortgrid",raster(),True,None) output=outputs['OUTPUT'] self.assertTrue(os.path.isfile(output)) dataset=gdal.Open(output, GA_ReadOnly) strhash=hash(str(dataset.ReadAsArray(0).tolist())) self.assertEqual(strhash,1320073153)
def test_gdalogrsieveWithUnsupportedOutputFormat(self): outputs=sextante.runalg("gdalogr:sieve",raster(),2,0, SextanteUtils.getTempFilename("img")) output=outputs['dst_filename'] self.assertTrue(os.path.isfile(output)) dataset=gdal.Open(output, GA_ReadOnly) strhash=hash(str(dataset.ReadAsArray(0).tolist())) self.assertEqual(strhash,-1353696889)
def test_gdalogrwarpreproject(self): outputs=sextante.runalg("gdalogr:warpreproject",raster(),"EPSG:23030","EPSG:4326",0,0,"",None) output=outputs['OUTPUT'] self.assertTrue(os.path.isfile(output)) dataset=gdal.Open(output, GA_ReadOnly) strhash=hash(str(dataset.ReadAsArray(0).tolist())) self.assertEqual(strhash,-2021328784)
def test_gdalogrsieve(self): outputs=sextante.runalg("gdalogr:sieve",raster(),2,0,None) output=outputs['dst_filename'] self.assertTrue(os.path.isfile(output)) dataset=gdal.Open(output, GA_ReadOnly) strhash=hash(str(dataset.ReadAsArray(0).tolist())) self.assertEqual(strhash,-1353696889)
def test_SagaVectorAlgorithmWithSelection(self): layer = sextante.getobject(polygons2()); feature = layer.getFeatures().next() selected = [feature.id()] layer.setSelectedFeatures(selected) outputs=sextante.runalg("saga:polygoncentroids",polygons2(),True,None) layer.setSelectedFeatures([]) output=outputs['CENTROIDS'] layer=QGisLayers.getObjectFromUri(output, True) fields=layer.pendingFields() expectednames=['ID','POLY_NUM_B','POLY_ST_B'] expectedtypes=['Real','Real','String'] 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=["2","1","string a"] values=[str(attr.toString()) for attr in attrs] self.assertEqual(expectedvalues, values) wkt='POINT(270806.69221918 4458924.97720492)' self.assertEqual(wkt, str(feature.geometry().exportToWkt()))
def test_SagaRasterAlgorithmWithUnsupportedOutputFormat(self): outputs=sextante.runalg("saga:convergenceindex",raster(),0,0,None) output=outputs['RESULT'] self.assertTrue(os.path.isfile(output)) dataset=gdal.Open(output, GA_ReadOnly) strhash=hash(str(dataset.ReadAsArray(0).tolist())) self.assertEqual(strhash,485390137)
def test_sagametricconversions(self): outputs=sextante.runalg("saga:metricconversions",raster(),0,None) output=outputs['CONV'] self.assertTrue(os.path.isfile(output)) dataset=gdal.Open(output, GA_ReadOnly) strhash=hash(str(dataset.ReadAsArray(0).tolist())) self.assertEqual(strhash,-2137931723)
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 test_modelerfieldautoextent(self): outputs=sextante.runalg("modeler:fieldautoextent",polygons(),"POLY_NUM_A",None) output=outputs['USER_GRID_ALG0'] self.assertTrue(os.path.isfile(output)) dataset=gdal.Open(output, GA_ReadOnly) strhash=hash(str(dataset.ReadAsArray(0).tolist())) self.assertEqual(strhash,2026100494)
def test_modelernotinorder(self): outputs=sextante.runalg("modeler:notinorder",raster(),None) output=outputs['CAREA_ALG0'] self.assertTrue(os.path.isfile(output)) dataset=gdal.Open(output, GA_ReadOnly) strhash=hash(str(dataset.ReadAsArray(0).tolist())) self.assertEqual(strhash,-1557050506)
def test_SagaVectorAlgorithmWithSelection(self): layer = sextante.getobject(polygons2()) feature = layer.getFeatures().next() selected = [feature.id()] layer.setSelectedFeatures(selected) outputs = sextante.runalg("saga:polygoncentroids", polygons2(), True, None) layer.setSelectedFeatures([]) output = outputs['CENTROIDS'] layer = QGisLayers.getObjectFromUri(output, True) fields = layer.pendingFields() expectednames = ['ID', 'POLY_NUM_B', 'POLY_ST_B'] expectedtypes = ['Real', 'Real', 'String'] 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 = ["2", "1", "string a"] values = [str(attr.toString()) for attr in attrs] self.assertEqual(expectedvalues, values) wkt = 'POINT(270806.69221918 4458924.97720492)' self.assertEqual(wkt, str(feature.geometry().exportToWkt()))
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_SagaVectorAlgorithWithUnsupportedInputAndOutputFormat(self): '''this tests both the exporting to shp and then the format change in the output layer''' layer = sextante.getobject(polygonsGeoJson()) feature = layer.getFeatures().next() selected = [feature.id()] layer.setSelectedFeatures(selected) outputs = sextante.runalg("saga:polygoncentroids", polygonsGeoJson(), True, SextanteUtils.getTempFilename("geojson")) layer.setSelectedFeatures([]) output = outputs['CENTROIDS'] layer = QGisLayers.getObjectFromUri(output, True) fields = layer.pendingFields() expectednames = ['ID', 'POLY_NUM_A', 'POLY_ST_A'] expectedtypes = ['Real', 'Real', 'String'] 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", "1.1", "string a"] values = [str(attr.toString()) for attr in attrs] self.assertEqual(expectedvalues, values) wkt = 'POINT(270787.49991451 4458955.46775295)' self.assertEqual(wkt, str(feature.geometry().exportToWkt()))
def test_SagaRasterAlgorithmWithUnsupportedOutputFormat(self): outputs=sextante.runalg("saga:convergenceindex",raster(),0,0,SextanteUtils.getTempFilename("img")) output=outputs['RESULT'] self.assertTrue(os.path.isfile(output)) dataset=gdal.Open(output, GA_ReadOnly) strhash=hash(str(dataset.ReadAsArray(0).tolist())) self.assertEqual(strhash, 485390137)
def test_modelersimplemodel(self): outputs=sextante.runalg("modeler:simplemodel",raster(),None) output=outputs['SLOPE_ALG0'] self.assertTrue(os.path.isfile(output)) dataset=gdal.Open(output, GA_ReadOnly) strhash=hash(str(dataset.ReadAsArray(0).tolist())) self.assertEqual(strhash,1891122097)
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 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 test_modeleremptystring(self): outputs = sextante.runalg("modeler:emptystring", union(), None) output = outputs['OUTPUT_LAYER_ALG0'] layer = QGisLayers.getObjectFromUri(output, True) fields = layer.pendingFields() expectednames = [ 'ID', 'POLY_NUM_A', 'POLY_ST_A', 'ID_2', 'POLY_NUM_B', 'POLY_ST_B', 'NewField' ] expectedtypes = [ 'Integer', 'Real', 'String', 'Integer', 'Real', 'String', 'Integer' ] 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(8, len(features)) feature = features.next() attrs = feature.attributes() expectedvalues = ["1", "1.1", "string a", "2", "1", "string a", "10"] values = [str(attr) for attr in attrs] self.assertEqual(expectedvalues, values) wkt = 'POLYGON((270807.08580285 4458940.1594565,270798.42294527 4458914.62661676,270780.81854858 4458914.21983449,270763.52289518 4458920.715993,270760.3449542 4458926.6570575,270763.78234766 4458958.22561242,270794.30290024 4458942.16424502,270807.08580285 4458940.1594565))' self.assertEqual(wkt, str(feature.geometry().exportToWkt()))
def runalg_none(self): result = sextante.runalg(self.alg, *self.args) print bcolors.ENDC self.assertIsNotNone(result, self.msg) if not result: return for p in result.values(): if isinstance(p, str): self.assertTrue(os.path.exists(p), "Output %s exists" % p)
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_scripthexgridfromlayerbounds(self): outputs=sextante.runalg("script:hexgridfromlayerbounds",polygons(),10,None) output=outputs['grid'] layer=QGisLayers.getObjectFromUri(output, True) fields=layer.pendingFields() expectednames=['longitude','latitude'] expectedtypes=['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(117, len(features)) feature=features.next() attrs=feature.attributes() expectedvalues=["270765.621834001","4458907.27146471"] values=[str(attr) for attr in attrs] self.assertEqual(expectedvalues, values) wkt='POLYGON((270771.39533669 4458907.27146471,270768.50858535 4458902.27146471,270762.73508265 4458902.27146471,270759.84833131 4458907.27146471,270762.73508265 4458912.27146471,270768.50858535 4458912.27146471,270771.39533669 4458907.27146471))' self.assertEqual(wkt, str(feature.geometry().exportToWkt()))
def test_gdalogrogr2ogrWrongExtension(self): outputs=sextante.runalg("gdalogr:ogr2ogr",union(),3,"",SextanteUtils.getTempFilename("wrongext")) output=outputs['OUTPUT_LAYER'] layer=QGisLayers.getObjectFromUri(output, True) fields=layer.pendingFields() expectednames=['id','poly_num_a','poly_st_a','id_2','poly_num_b','poly_st_b'] expectedtypes=['Integer','Real','String','Integer','Real','String'] 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(8, len(features)) feature=features.next() attrs=feature.attributes() expectedvalues=["1","1.1","string a","2","1","string a"] values=[str(attr.toString()) for attr in attrs] self.assertEqual(expectedvalues, values) wkt='POLYGON((270807.08580285 4458940.1594565,270798.42294527 4458914.62661676,270780.81854858 4458914.21983449,270763.52289518 4458920.715993,270760.3449542 4458926.6570575,270763.78234766 4458958.22561242,270794.30290024 4458942.16424502,270807.08580285 4458940.1594565))' self.assertEqual(wkt, str(feature.geometry().exportToWkt()))
def test_scriptcreatetilingfromvectorlayer(self): outputs=sextante.runalg("script:createtilingfromvectorlayer",union(),10,None) output=outputs['polygons'] layer=QGisLayers.getObjectFromUri(output, True) fields=layer.pendingFields() expectednames=['longitude','latitude'] expectedtypes=['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(10, len(features)) feature=features.next() attrs=feature.attributes() expectedvalues=["270761.415396242","4458948.29588823"] values=[str(attr) for attr in attrs] self.assertEqual(expectedvalues, values) wkt='POLYGON((270755.54427424 4458901.23378639,270755.54427424 4458995.35799007,270767.28651824 4458995.35799007,270767.28651824 4458901.23378639,270755.54427424 4458901.23378639))' self.assertEqual(wkt, str(feature.geometry().exportToWkt()))
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_modeleremptystring(self): outputs=sextante.runalg("modeler:emptystring",union(),None) output=outputs['OUTPUT_LAYER_ALG0'] layer=QGisLayers.getObjectFromUri(output, True) fields=layer.pendingFields() expectednames=['ID','POLY_NUM_A','POLY_ST_A','ID_2','POLY_NUM_B','POLY_ST_B','NewField'] expectedtypes=['Integer','Real','String','Integer','Real','String','Integer'] 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(8, len(features)) feature=features.next() attrs=feature.attributes() expectedvalues=["1","1.1","string a","2","1","string a","10"] values=[str(attr.toString()) for attr in attrs] self.assertEqual(expectedvalues, values) wkt='POLYGON((270807.08580285 4458940.1594565,270798.42294527 4458914.62661676,270780.81854858 4458914.21983449,270763.52289518 4458920.715993,270760.3449542 4458926.6570575,270763.78234766 4458958.22561242,270794.30290024 4458942.16424502,270807.08580285 4458940.1594565))' 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_SagaVvectorAlgorithmWithSelection(self): layer = sextante.getobject(polygons2()) feature = layer.getFeatures().next() selected = [feature.id()] layer.setSelectedFeatures(selected) outputs = sextante.runalg("saga:polygoncentroids", polygons2(), True, None) output = outputs["CENTROIDS"] layer = QGisLayers.getObjectFromUri(output, True) fields = layer.pendingFields() expectednames = ["ID", "POLY_NUM_B", "POLY_ST_B"] expectedtypes = ["Real", "Real", "String"] 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 = ["2", "1", "string a"] values = [str(attr.toString()) for attr in attrs] self.assertEqual(expectedvalues, values) wkt = "POINT(270820.58189697 4458968.73298999)" self.assertEqual(wkt, str(feature.geometry().exportToWkt()))
def test_scriptascriptthatreturnsanumber(self): outputs=sextante.runalg("script:ascriptthatreturnsanumber") output=outputs['number'] self.assertTrue(10, output)
def test_scriptascriptthatreturnsanumber(self): outputs = sextante.runalg("script:ascriptthatreturnsanumber") output = outputs['number'] self.assertTrue(10, output)