示例#1
0
    def test_set_layers(self):
        """
        Test set up aggregator's layers work
        """

        hazard = QgsVectorLayer(
            standard_data_path('hazard', 'multipart_polygons_osm_4326.shp'),
            'hazard', 'ogr')
        exposure = QgsVectorLayer(
            standard_data_path('exposure', 'buildings_osm_4326.shp'), 'impact',
            'ogr')

        aggregation_layer = QgsVectorLayer(
            os.path.join(BOUNDDATA, 'kabupaten_jakarta.shp'),
            'test aggregation', 'ogr')

        # Test in
        #   aoi mode (use None)
        #   not aoi mode (use aggregation_layer)
        for agg_layer in [None, aggregation_layer]:
            aggregator = Aggregator(self.extent, None)
            aggregator.set_layers(hazard, exposure)
            self.assertEquals(aggregator.exposure_layer, exposure)
            self.assertEquals(aggregator.hazard_layer, hazard)
            layer = aggregator.layer
            extent = layer.extent()
            x_min, y_min, x_max, y_max = \
                extent.xMinimum(), extent.yMinimum(), \
                extent.xMaximum(), extent.yMaximum()
            self.assertAlmostEquals(self.extent[0], x_min)
            self.assertAlmostEquals(self.extent[1], y_min)
            self.assertAlmostEquals(self.extent[2], x_max)
            self.assertAlmostEquals(self.extent[3], y_max)
            self.assertTrue(aggregator.safe_layer.is_vector)
            _ = agg_layer
示例#2
0
    def test_setup_target_field(self):
        """Test setup up target field is correct.
        """
        layer = QgsVectorLayer(
            os.path.join(BOUNDDATA, 'kabupaten_jakarta.shp'),
            'test aggregation', 'ogr')
        aggregator = Aggregator(self.extent, None)
        self.assertFalse(aggregator._setup_target_field(layer))

        impact_layer_name = os.path.join(TESTDATA,
                                         'aggregation_test_impact_vector.shp')
        impact_layer = QgsVectorLayer(impact_layer_name, 'test', 'ogr')
        self.assertTrue(aggregator._setup_target_field(impact_layer))
    def test_setup_target_field(self):
        """Test setup up target field is correct.
        """
        layer = QgsVectorLayer(
            os.path.join(BOUNDDATA, 'kabupaten_jakarta.shp'),
            'test aggregation',
            'ogr')
        aggregator = Aggregator(self.extent, None)
        self.assertFalse(aggregator._setup_target_field(layer))

        impact_layer_name = os.path.join(TESTDATA,
                                         'aggregation_test_impact_vector.shp')
        impact_layer = QgsVectorLayer(impact_layer_name,
                                      'test', 'ogr')
        self.assertTrue(aggregator._setup_target_field(impact_layer))
    def test_set_layers(self):
        """
        Test set up aggregator's layers work
        """

        hazard = QgsVectorLayer(
            test_data_path(
                'hazard',
                'multipart_polygons_osm_4326.shp'),
            'hazard',
            'ogr'
        )
        exposure = QgsVectorLayer(
            test_data_path(
                'exposure',
                'buildings_osm_4326.shp'),
            'impact',
            'ogr'
        )

        aggregation_layer = QgsVectorLayer(
            os.path.join(BOUNDDATA, 'kabupaten_jakarta.shp'),
            'test aggregation',
            'ogr')

        # Test in
        #   aoi mode (use None)
        #   not aoi mode (use aggregation_layer)
        for agg_layer in [None, aggregation_layer]:
            aggregator = Aggregator(self.extent, None)
            aggregator.set_layers(hazard, exposure)
            self.assertEquals(aggregator.exposure_layer, exposure)
            self.assertEquals(aggregator.hazard_layer, hazard)
            layer = aggregator.layer
            extent = layer.extent()
            x_min, y_min, x_max, y_max = \
                extent.xMinimum(), extent.yMinimum(), \
                extent.xMaximum(), extent.yMaximum()
            self.assertAlmostEquals(self.extent[0], x_min)
            self.assertAlmostEquals(self.extent[1], y_min)
            self.assertAlmostEquals(self.extent[2], x_max)
            self.assertAlmostEquals(self.extent[3], y_max)
            self.assertTrue(aggregator.safe_layer.is_vector)
            _ = agg_layer
示例#5
0
    def _create_aggregator(self, use_aoi_mode):
        """Helper to create aggregator."""

        aggregation_layer = QgsVectorLayer(
            os.path.join(BOUNDDATA, 'kabupaten_jakarta.shp'),
            'test aggregation', 'ogr')
        # Dummy layers. Them are used in aggregator._prepare_layer
        # The extent of the layers must be equal to aggregator.extent
        hazard_layer = exposure_layer = aggregation_layer
        # setting up
        if not use_aoi_mode:
            aggregator = Aggregator(self.extent, aggregation_layer)
        else:
            aggregator = Aggregator(self.extent, None)
        aggregator.set_layers(hazard_layer, exposure_layer)
        aggregator.validate_keywords()

        return aggregator
示例#6
0
    def _create_aggregator(self,
                           use_aoi_mode,
                           use_native_zonal_stats):
        """Helper to create aggregator"""

        aggregation_layer = QgsVectorLayer(
            os.path.join(BOUNDDATA, 'kabupaten_jakarta.shp'),
            'test aggregation',
            'ogr')
        # Dummy layers. Them are used in aggregator._prepare_layer
        # The extent of the layers must be equal to aggregator.extent
        hazard_layer = exposure_layer = aggregation_layer
        # setting up
        if not use_aoi_mode:
            aggregator = Aggregator(self.extent, aggregation_layer)
        else:
            aggregator = Aggregator(self.extent, None)
        aggregator.set_layers(hazard_layer, exposure_layer)
        aggregator.validate_keywords()
        aggregator.use_native_zonal_stats = use_native_zonal_stats

        return aggregator