当前位置: 首页>>代码示例>>Python>>正文


Python utilities.load_test_vector_layer函数代码示例

本文整理汇总了Python中safe.test.utilities.load_test_vector_layer函数的典型用法代码示例。如果您正苦于以下问题:Python load_test_vector_layer函数的具体用法?Python load_test_vector_layer怎么用?Python load_test_vector_layer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了load_test_vector_layer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_size_needed

    def test_size_needed(self):
        """Test we can add the size when it is needed."""
        # A building layer should be always false.
        layer = load_test_vector_layer(
            'gisv4', 'exposure', 'buildings.geojson')
        layer.keywords['inasafe_fields'] = {
            population_count_field['key']: population_count_field['field_name']
        }
        self.assertFalse(_size_is_needed(layer))
        layer.keywords['inasafe_fields'] = {
            female_ratio_field['key']: female_ratio_field['field_name']
        }
        self.assertFalse(_size_is_needed(layer))

        # But a road layer should be true only if it has a absolute value.
        layer = load_test_vector_layer(
            'gisv4', 'exposure', 'roads.geojson')

        layer.keywords['inasafe_fields'] = {
            population_count_field['key']: population_count_field['field_name']
        }
        self.assertTrue(_size_is_needed(layer))

        layer.keywords['inasafe_fields'] = {
            female_ratio_field['key']: female_ratio_field['field_name']
        }
        self.assertFalse(_size_is_needed(layer))
开发者ID:timlinux,项目名称:inasafe,代码行数:27,代码来源:test_prepare_vector_layer.py

示例2: test_pre_processors_earthquake_contour

    def test_pre_processors_earthquake_contour(self):
        """Test the pre_processors_earthquake_contour"""
        hazard_layer = load_test_raster_layer(
            'gisv4', 'hazard', 'earthquake.asc')
        exposure_layer = load_test_vector_layer(
            'gisv4', 'exposure', 'building-points.geojson')
        impact_function = ImpactFunction()
        impact_function.exposure = exposure_layer
        impact_function.hazard = hazard_layer
        impact_function.crs = QgsCoordinateReferenceSystem(4326)
        status, message = impact_function.prepare()
        self.assertEqual(PREPARE_SUCCESS, status, message)

        self.assertTrue(
            pre_processor_earthquake_contour['condition'](impact_function))

        hazard_layer = load_test_raster_layer(
            'hazard', 'classified_flood_20_20.asc')
        exposure_layer = load_test_vector_layer(
            'gisv4', 'exposure', 'places.geojson')
        impact_function = ImpactFunction()
        impact_function.exposure = exposure_layer
        impact_function.hazard = hazard_layer
        impact_function.crs = QgsCoordinateReferenceSystem(4326)
        status, message = impact_function.prepare()
        self.assertEqual(PREPARE_SUCCESS, status, message)

        # not ok, since the hazard is flood, not earthquake
        self.assertFalse(
            pre_processor_earthquake_contour['condition'](impact_function))
开发者ID:inasafe,项目名称:inasafe,代码行数:30,代码来源:test_preprocessors.py

示例3: test_profiling

    def test_profiling(self):
        """Test running impact function on test data."""
        hazard_layer = load_test_vector_layer(
            'gisv4', 'hazard', 'classified_vector.geojson')
        exposure_layer = load_test_vector_layer(
            'gisv4', 'exposure', 'building-points.geojson')
        aggregation_layer = load_test_vector_layer(
            'gisv4', 'aggregation', 'small_grid.geojson')

        # Set up impact function
        impact_function = ImpactFunction()
        impact_function.aggregation = aggregation_layer
        impact_function.exposure = exposure_layer
        impact_function.hazard = hazard_layer
        status, message = impact_function.run()
        self.assertEqual(ANALYSIS_FAILED_BAD_INPUT, status, message)
        impact_function.prepare()
        status, message = impact_function.run()
        self.assertEqual(ANALYSIS_SUCCESS, status, message)
        message = impact_function.performance_log_message().to_text()
        expected_result = get_control_text(
            'test-profiling-logs.txt')

        for line in expected_result:
            line = line.replace('\n', '')
            if line == '' or line == '-':
                continue
            self.assertIn(line, message)

        # Notes(IS): For some unknown reason I need to do this to make
        # test_provenance pass
        del hazard_layer
开发者ID:ismailsunni,项目名称:inasafe,代码行数:32,代码来源:test_impact_function.py

示例4: test_pre_processors_nearby_places

    def test_pre_processors_nearby_places(self):
        """Test the pre_processors_nearby_places"""
        hazard_layer = load_test_raster_layer(
            'gisv4', 'hazard', 'earthquake.asc')
        exposure_layer = load_test_vector_layer(
            'gisv4', 'exposure', 'building-points.geojson')
        impact_function = ImpactFunction()
        impact_function.exposure = exposure_layer
        impact_function.hazard = hazard_layer
        impact_function.crs = QgsCoordinateReferenceSystem(4326)
        status, message = impact_function.prepare()
        self.assertEqual(PREPARE_SUCCESS, status, message)

        # The exposure is not place but buildings
        self.assertFalse(
            pre_processors_nearby_places['condition'](impact_function))

        hazard_layer = load_test_raster_layer(
            'gisv4', 'hazard', 'earthquake.asc')
        exposure_layer = load_test_vector_layer(
            'gisv4', 'exposure', 'places.geojson')
        impact_function = ImpactFunction()
        impact_function.exposure = exposure_layer
        impact_function.hazard = hazard_layer
        impact_function.crs = QgsCoordinateReferenceSystem(4326)
        status, message = impact_function.prepare()
        self.assertEqual(PREPARE_SUCCESS, status, message)

        # EQ on places, it must be OK.
        self.assertTrue(
            pre_processors_nearby_places['condition'](impact_function))
开发者ID:inasafe,项目名称:inasafe,代码行数:31,代码来源:test_preprocessors.py

示例5: test_old_fields_keywords

    def test_old_fields_keywords(self):
        """The IF is not ready with we have some wrong inasafe_fields."""
        hazard_layer = load_test_vector_layer(
            'gisv4', 'hazard', 'classified_vector.geojson')
        exposure_layer = load_test_vector_layer(
            'gisv4', 'exposure', 'building-points.geojson',
            clone=True)
        aggregation_layer = load_test_vector_layer(
            'gisv4', 'aggregation', 'small_grid.geojson')

        impact_function = ImpactFunction()
        impact_function.aggregation = aggregation_layer
        impact_function.exposure = exposure_layer
        impact_function.hazard = hazard_layer
        status, message = impact_function.prepare()

        # The layer should be fine.
        self.assertEqual(PREPARE_SUCCESS, status, message)

        # Now, we remove one field
        exposure_layer.startEditing()
        field = exposure_layer.keywords['inasafe_fields'].values()[0]
        index = exposure_layer.fieldNameIndex(field)
        exposure_layer.deleteAttribute(index)
        exposure_layer.commitChanges()

        # It shouldn't be fine as we removed one field which
        # was in inasafe_fields
        status, message = impact_function.prepare()
        self.assertNotEqual(PREPARE_SUCCESS, status, message)
开发者ID:ismailsunni,项目名称:inasafe,代码行数:30,代码来源:test_impact_function.py

示例6: test_aggregation_summary

    def test_aggregation_summary(self):
        """Test we can aggregate the aggregate hazard to the aggregation."""
        aggregate_hazard = load_test_vector_layer(
            'gisv4',
            'intermediate',
            'aggregate_classified_hazard_summary.geojson')

        aggregation = load_test_vector_layer(
            'gisv4',
            'aggregation',
            'aggregation_cleaned.geojson',
            clone=True)

        number_of_fields = aggregation.fields().count()

        layer = aggregation_summary(aggregate_hazard, aggregation)

        check_inasafe_fields(layer)

        # I need the number of unique exposure
        pattern = exposure_count_field['key']
        pattern = pattern.replace('%s', '')
        unique_exposure = []
        inasafe_fields = aggregate_hazard.keywords['inasafe_fields']
        for key, name_field in inasafe_fields.iteritems():
            if key.endswith(pattern):
                unique_exposure.append(key.replace(pattern, ''))

        self.assertEqual(
            layer.fields().count(),
            len(unique_exposure) + number_of_fields + 1
        )
开发者ID:akbargumbira,项目名称:inasafe,代码行数:32,代码来源:test_summary.py

示例7: test_is_polygonal_layer

    def test_is_polygonal_layer(self):
        """Test we can get the correct attributes back"""
        # Polygon layer
        layer = load_test_vector_layer(
            'aggregation',
            'district_osm_jakarta.geojson',
            clone=True
        )
        message = 'isPolygonLayer, %s layer should be polygonal' % layer
        self.assertTrue(is_polygon_layer(layer), message)

        # Point layer
        layer = load_test_vector_layer('hazard', 'volcano_point.geojson')
        message = '%s layer should be polygonal' % layer
        self.assertFalse(is_polygon_layer(layer), message)

        # Raster layer
        layer = clone_raster_layer(
            name='earthquake',
            extension='.tif',
            include_keywords=True,
            source_directory=standard_data_path('hazard')
        )
        message = ('%s raster layer should not be polygonal' % layer)
        self.assertFalse(is_polygon_layer(layer), message)
开发者ID:akbargumbira,项目名称:inasafe,代码行数:25,代码来源:test_gis.py

示例8: test_provenance_without_aggregation

    def test_provenance_without_aggregation(self):
        """Test provenance of impact function without aggregation."""
        hazard_layer = load_test_vector_layer(
            'gisv4', 'hazard', 'classified_vector.geojson')
        exposure_layer = load_test_vector_layer(
            'gisv4', 'exposure', 'building-points.geojson')

        hazard = definition(hazard_layer.keywords['hazard'])
        exposure = definition(exposure_layer.keywords['exposure'])
        hazard_category = definition(hazard_layer.keywords['hazard_category'])

        expected_provenance = {
            'gdal_version': gdal.__version__,
            'host_name': gethostname(),
            'map_title': get_map_title(hazard, exposure, hazard_category),
            'map_legend_title': exposure['layer_legend_title'],
            'inasafe_version': get_version(),
            'pyqt_version': PYQT_VERSION_STR,
            'qgis_version': QGis.QGIS_VERSION,
            'qt_version': QT_VERSION_STR,
            'user': getpass.getuser(),
            'os': readable_os_version(),
            'aggregation_layer': None,
            'aggregation_layer_id': None,
            'exposure_layer': exposure_layer.source(),
            'exposure_layer_id': exposure_layer.id(),
            'hazard_layer': hazard_layer.source(),
            'hazard_layer_id': hazard_layer.id(),
            'analysis_question': get_analysis_question(hazard, exposure),
            'aggregation_keywords': None,
            'exposure_keywords': deepcopy(exposure_layer.keywords),
            'hazard_keywords': deepcopy(hazard_layer.keywords),
        }

        # Set up impact function
        impact_function = ImpactFunction()
        impact_function.exposure = exposure_layer
        impact_function.hazard = hazard_layer
        status, message = impact_function.prepare()
        self.assertEqual(PREPARE_SUCCESS, status, message)
        status, message = impact_function.run()
        self.assertEqual(ANALYSIS_SUCCESS, status, message)

        self.maxDiff = None

        expected_provenance.update({
            'action_checklist': impact_function.action_checklist(),
            'analysis_extent': impact_function.analysis_extent.exportToWkt(),
            'impact_function_name': impact_function.name,
            'impact_function_title': impact_function.title,
            'notes': impact_function.notes(),
            'requested_extent': impact_function.requested_extent,
            'data_store_uri': impact_function.datastore.uri_path,
            'start_datetime': impact_function.start_datetime,
            'end_datetime': impact_function.end_datetime,
            'duration': impact_function.duration
        })

        self.assertDictEqual(expected_provenance, impact_function.provenance)
开发者ID:ismailsunni,项目名称:inasafe,代码行数:59,代码来源:test_impact_function.py

示例9: test_clip_vector

    def test_clip_vector(self):
        """Test we can smart clip two layers, like indivisible polygons."""

        analysis = load_test_vector_layer(
            'gisv4', 'analysis', 'analysis.geojson')

        exposure = load_test_vector_layer(
            'gisv4', 'exposure', 'buildings.geojson')

        layer = smart_clip(exposure, analysis)
        self.assertEqual(layer.featureCount(), 9)
开发者ID:timlinux,项目名称:inasafe,代码行数:11,代码来源:test_smart_clip.py

示例10: test_clip_vector

    def test_clip_vector(self):
        """Test we can clip two layers, like buildings and aggregation."""

        aggregation = load_test_vector_layer(
            'gisv4', 'aggregation', 'small_grid.geojson')

        exposure = load_test_vector_layer(
            'gisv4', 'exposure', 'building-points.geojson')

        layer = clip(exposure, aggregation)
        self.assertEqual(layer.featureCount(), 9)
开发者ID:inasafe,项目名称:inasafe,代码行数:11,代码来源:test_clip.py

示例11: test_impact_function_behaviour

    def test_impact_function_behaviour(self):
        """Test behaviour of impact function."""
        hazard_layer = load_test_vector_layer(
            'hazard', 'flood_multipart_polygons.shp')
        exposure_layer = load_test_vector_layer('exposure', 'roads.shp')

        impact_function = ImpactFunction()
        impact_function.exposure = exposure_layer
        impact_function.hazard = hazard_layer
        impact_function.prepare()
        self.assertEqual(impact_function.name, 'Flood Polygon On Road Line')
        self.assertEqual(impact_function.title, 'be affected')
开发者ID:ismailsunni,项目名称:inasafe,代码行数:12,代码来源:test_impact_function.py

示例12: test_reclassify_vector

    def test_reclassify_vector(self):
        """Test we can reclassify a continuous vector layer."""

        classes = {
            1: [None, 0.0],  # value <= 0.0
            2: [0.0, 1],  # 0.0 < value <= 1
            10: [1, 1.5],  # 1 < value <= 1.5 and gap in output classes
            11: [1.3, None]  # value > 1.5
        }
        ranges = {
            exposure_structure['key']: {
                'flood_hazard_classes': {
                    'active': True,
                    'classes': classes
                }
            }
        }

        # Let's add a vector layer.
        layer = load_test_vector_layer(
            'hazard', 'continuous_vector.geojson', clone=True)
        layer.keywords['thresholds'] = ranges

        self.assertEqual(layer.featureCount(), 400)
        classified = reclassify(layer, exposure_structure['key'])
        self.assertEqual(layer.featureCount(), 375)

        expected_field = hazard_class_field['field_name']
        self.assertEqual(classified.fieldNameIndex(expected_field), 1)

        self.assertEqual(
            layer.keywords['inasafe_fields'][hazard_class_field['key']],
            hazard_class_field['field_name'])

        """
开发者ID:timlinux,项目名称:inasafe,代码行数:35,代码来源:test_reclassify.py

示例13: test_sum_fields

    def test_sum_fields(self):
        """Test sum_fields method."""
        layer = load_test_vector_layer(
            'gisv4', 'exposure', 'population_multi_fields.geojson', clone=True)
        sum_fields(
            layer, exposure_id_field['key'], ['F_0_4', 'F_5_9', 'F_9_15'])
        exposure_id__idx = layer.fieldNameIndex(
            exposure_id_field['field_name'])
        F_0_4__idx = layer.fieldNameIndex('F_0_4')
        F_5_9__idx = layer.fieldNameIndex('F_5_9')
        F_9_15__idx = layer.fieldNameIndex('F_9_15')
        for feature in layer.getFeatures():
            sum_value = (
                feature[F_0_4__idx] + feature[F_5_9__idx] + feature[
                    F_9_15__idx])
            self.assertEqual(feature[exposure_id__idx], sum_value)

        new_field__idx = layer.fieldNameIndex(female_count_field['field_name'])
        # Check if the new field doesn't exist
        self.assertEqual(new_field__idx, -1)
        sum_fields(layer, female_count_field['key'], ['F_0_4', 'F_5_9'])
        new_field__idx = layer.fieldNameIndex(female_count_field['field_name'])
        for feature in layer.getFeatures():
            sum_value = (feature[F_0_4__idx] + feature[F_5_9__idx])
            self.assertEqual(feature[new_field__idx], sum_value)
开发者ID:timlinux,项目名称:inasafe,代码行数:25,代码来源:test_prepare_vector_layer.py

示例14: test_size_post_processor

    def test_size_post_processor(self):
        """Test size, size rate, productivity post processor."""
        impact_layer = load_test_vector_layer(
            'impact',
            'indivisible_polygon_impact.geojson',
            clone_to_memory=True)
        impact_layer.keywords['exposure_keywords'] = {
            'exposure': 'population'
        }
        self.assertIsNotNone(impact_layer)

        # Test the size post processor.
        result, message = run_single_post_processor(
            impact_layer,
            post_processor_size)
        self.assertTrue(result, message)

        # Check if new field is added
        impact_fields = impact_layer.dataProvider().fieldNameMap().keys()
        self.assertIn(size_field['field_name'], impact_fields)

        # Test the size rate post processor.
        result, message = run_single_post_processor(
            impact_layer,
            post_processor_size_rate)
        self.assertTrue(result, message)

        # Check if new field is added
        impact_fields = impact_layer.dataProvider().fieldNameMap().keys()
        self.assertIn(feature_value_field['field_name'], impact_fields)
开发者ID:akbargumbira,项目名称:inasafe,代码行数:30,代码来源:test_postprocessors.py

示例15: test_recompute_counts

    def test_recompute_counts(self):
        """Test we can recompute counts in a layer."""
        layer = load_test_vector_layer(
            'gisv4', 'exposure', 'population.geojson',
            clone=True)

        self.assertIn(
            female_count_field['key'], layer.keywords['inasafe_fields'])

        layer = prepare_vector_layer(layer)
        layer = from_counts_to_ratios(layer)

        self.assertIn(
            female_count_field['key'], layer.keywords['inasafe_fields'])
        self.assertIn(
            female_ratio_field['key'], layer.keywords['inasafe_fields'])

        # Check that each feature has correct ratio
        for feature in layer.getFeatures():
            manual_ratio = feature[female_count_field['field_name']] / feature[
                population_count_field['field_name']]
            diff = abs(
                manual_ratio - feature[female_ratio_field['field_name']])

            self.assertTrue(diff < 10 ** -2, diff)
开发者ID:ismailsunni,项目名称:inasafe,代码行数:25,代码来源:test_count_to_ratio.py


注:本文中的safe.test.utilities.load_test_vector_layer函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。