Beispiel #1
0
    def test_polygonize_raster(self):
        """Test we can polygonize a raster layer."""
        layer = load_test_raster_layer('hazard', 'classified_flood_20_20.asc')

        expected_keywords = layer.keywords.copy()
        title = polygonize_steps['output_layer_name'] % (
            layer.keywords['layer_purpose'])
        expected_keywords[
            layer_geometry['key']] = layer_geometry_polygon['key']
        expected_keywords['title'] = title

        expected_keywords['inasafe_fields'] = {
            hazard_value_field['key']: hazard_value_field['field_name'][0:10]}

        polygonized = polygonize(layer)

        self.assertDictEqual(polygonized.keywords, expected_keywords)

        self.assertEqual(polygonized.featureCount(), 400)

        expected_count = {
            '1': 133,
            '2': 134,
            '3': 133,
        }

        inasafe_fields = polygonized.keywords.get('inasafe_fields')
        field_name = inasafe_fields.get(hazard_value_field['key'])

        for value, count in expected_count.iteritems():
            expression = '"%s" = \'%s\'' % (field_name, value)
            request = QgsFeatureRequest().setFilterExpression(expression)
            self.assertEqual(
                sum(1 for _ in polygonized.getFeatures(request)), count)
Beispiel #2
0
    def test_polygonize_raster(self):
        """Test we can polygonize a raster layer."""
        layer = load_test_raster_layer('hazard', 'classified_flood_20_20.asc')

        expected_keywords = layer.keywords.copy()
        title = polygonize_steps['output_layer_name'] % (
            layer.keywords['layer_purpose'])
        expected_keywords[
            layer_geometry['key']] = layer_geometry_polygon['key']
        expected_keywords['title'] = title

        expected_keywords['inasafe_fields'] = {
            hazard_value_field['key']: hazard_value_field['field_name'][0:10]}

        polygonized = polygonize(layer)

        self.assertDictEqual(polygonized.keywords, expected_keywords)

        self.assertEqual(polygonized.featureCount(), 400)

        expected_count = {
            '1': 133,
            '2': 134,
            '3': 133,
        }

        inasafe_fields = polygonized.keywords.get('inasafe_fields')
        field_name = inasafe_fields.get(hazard_value_field['key'])

        for value, count in expected_count.iteritems():
            expression = '"%s" = \'%s\'' % (field_name, value)
            request = QgsFeatureRequest().setFilterExpression(expression)
            self.assertEqual(
                sum(1 for _ in polygonized.getFeatures(request)), count)