Example #1
0
 def test_modelerfieldautoextent(self):
     outputs = processing.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)
Example #2
0
    def checkSagaIsInstalled(ignoreRegistrySettings=False):
        if 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 processing settings dialog, and check that the SAGA\n"
                        + "folder is correctly configured")

        settings = QSettings()
        SAGA_INSTALLED = "/ProcessingQGIS/SagaInstalled"
        if not ignoreRegistrySettings:
            if settings.contains(SAGA_INSTALLED):
                return

        try:
            from processing import runalg
            result = runalg("saga:polygoncentroids", polygons(), 0, None)
            if result is None or not os.path.exists(result['CENTROIDS']):
                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)
Example #3
0
    def checkSagaIsInstalled(ignorePreviousState=False):
        if 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 processing settings dialog, and \
                    check that the SAGA\n' \
                    + 'folder is correctly configured'

        if not ignorePreviousState:
            if SagaUtils.isSagaInstalled:
                return

        try:
            from processing import runalg
            result = runalg('saga:polygoncentroids', polygons(), 0, None)
            if result is None or not os.path.exists(result['CENTROIDS']):
                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

        SagaUtils.isSagaInstalled = True
Example #4
0
    def checkSagaIsInstalled(ignorePreviousState=False):
        if 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 processing settings dialog, and \
                    check that the SAGA\n' \
                    + 'folder is correctly configured'

        if not ignorePreviousState:
            if SagaUtils.isSagaInstalled:
                return

        try:
            from processing import runalg
            result = runalg('saga:polygoncentroids', polygons(), 0, None)
            if result is None or not os.path.exists(result['CENTROIDS']):
                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

        SagaUtils.isSagaInstalled = True
Example #5
0
 def test_modelerfieldautoextent(self):
     outputs = processing.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(unicode(dataset.ReadAsArray(0).tolist()))
     self.assertEqual(strhash, 2026100494)
Example #6
0
 def test_qgiscountpointsinpolygon(self):
     outputs=processing.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=processing.getfeatures(layer)
     self.assertEqual(2, len(features))
     feature=features.next()
     attrs=feature.attributes()
     expectedvalues=["1","1.1","string a","6"]
     values=[str(attr) for attr in attrs]
     self.assertEqual(expectedvalues, values)
Example #7
0
 def testWrongformat(self):
     outputs=processing.runalg("qgis:countpointsinpolygon",polygons(),points(),"NUMPOINTS",ProcessingUtils.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=processing.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)
Example #8
0
 def testWrongformat(self):
     outputs=processing.runalg("qgis:countpointsinpolygon",polygons(),points(),"NUMPOINTS",getTempFilename("wrongext"))
     output=outputs['OUTPUT']
     self.assertTrue(output.endswith('shp'))
     layer=dataobjects.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=processing.features(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)
Example #9
0
 def test_qgiscountpointsinpolygon(self):
     outputs = processing.runalg(
         "qgis:countpointsinpolygon", polygons(), points(), "NUMPOINTS", self.getOutputFile()
     )
     output = outputs["OUTPUT"]
     layer = dataobjects.getObjectFromUri(output, True)
     fields = layer.pendingFields()
     expectednames = ["ID", "POLY_NUM_A", "POLY_ST_A", "NUMPOINTS"]
     expectedtypes = ["Integer", "Real", "String", "Real"]
     names = [unicode(f.name()) for f in fields]
     types = [unicode(f.typeName()) for f in fields]
     self.assertEqual(expectednames, names)
     self.assertEqual(expectedtypes, types)
     features = processing.features(layer)
     self.assertEqual(2, len(features))
     feature = features.next()
     attrs = feature.attributes()
     expectedvalues = ["1", "1.1", "string a", "6"]
     values = [unicode(attr) for attr in attrs]
     self.assertEqual(expectedvalues, values)
Example #10
0
 def test_qgiscountpointsinpolygon(self):
     outputs = processing.runalg('qgis:countpointsinpolygon', polygons(),
                                 points(), 'NUMPOINTS',
                                 self.getOutputFile())
     output = outputs['OUTPUT']
     layer = dataobjects.getObjectFromUri(output, True)
     fields = layer.pendingFields()
     expectednames = ['ID', 'POLY_NUM_A', 'POLY_ST_A', 'NUMPOINTS']
     expectedtypes = ['Integer', 'Real', 'String', 'Real']
     names = [unicode(f.name()) for f in fields]
     types = [unicode(f.typeName()) for f in fields]
     self.assertEqual(expectednames, names)
     self.assertEqual(expectedtypes, types)
     features = processing.features(layer)
     self.assertEqual(2, len(features))
     feature = features.next()
     attrs = feature.attributes()
     expectedvalues = ['1', '1.1', 'string a', '6']
     values = [unicode(attr) for attr in attrs]
     self.assertEqual(expectedvalues, values)
Example #11
0
 def test_scripthexgridfromlayerbounds(self):
     outputs=processing.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=processing.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()))
Example #12
0
 def test_qgiscountpointsinpolygon(self):
     outputs = processing.runalg('qgis:countpointsinpolygon', polygons(),
                                 points(), 'NUMPOINTS',
                                 self.getOutputFile())
     output = outputs['OUTPUT']
     layer = dataobjects.getObjectFromUri(output, True)
     fields = layer.pendingFields()
     expectednames = ['ID', 'POLY_NUM_A', 'POLY_ST_A', 'NUMPOINTS']
     expectedtypes = ['Integer', 'Real', 'String', 'Real']
     names = [unicode(f.name()) for f in fields]
     types = [unicode(f.typeName()) for f in fields]
     self.assertEqual(expectednames, names)
     self.assertEqual(expectedtypes, types)
     features = processing.features(layer)
     self.assertEqual(2, len(features))
     feature = features.next()
     attrs = feature.attributes()
     expectedvalues = ['1', '1.1', 'string a', '6']
     values = [unicode(attr) for attr in attrs]
     self.assertEqual(expectedvalues, values)
Example #13
0
 def test_scripthexgridfromlayerbounds(self):
     outputs = processing.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 = processing.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()))
Example #14
0
 def testWrongformat(self):
     outputs = processing.runalg('qgis:countpointsinpolygon', polygons(),
                                 points(), 'NUMPOINTS',
                                 getTempFilename('wrongext'))
     output = outputs['OUTPUT']
     self.assertTrue(output.endswith('shp'))
     layer = dataobjects.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 = processing.features(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_runandload(self):
     processing.runandload("qgis:countpointsinpolygon", polygons(),
                           points(), "NUMPOINTS", None)
     layer = getfromname("Result")
     self.assertIsNotNone(layer)
Example #16
0
 def test_runandload(self):
     processing.runandload('qgis:countpointsinpolygon', polygons(),
                           points(), 'NUMPOINTS', None)
     layer = getObjectFromName('Result')
     self.assertIsNotNone(layer)
Example #17
0
 def test_runandload(self):
     processing.runandload("qgis:countpointsinpolygon",polygons(),points(),"NUMPOINTS", None)
     layer = getObjectFromName("Result")
     self.assertIsNotNone(layer)
Example #18
0
 def test_runandload(self):
     processing.runandload('qgis:countpointsinpolygon', polygons(),
                           points(), 'NUMPOINTS', None)
     layer = getObjectFromName('Result')
     self.assertIsNotNone(layer)