Beispiel #1
0
    def test_simplify_geometry(self):
        """HRA: test _simplify_geometry function."""
        from natcap.invest.hra import _simplify_geometry

        complicated_vector_path = os.path.join(TEST_DATA,
                                               'complicated_vector.gpkg')
        expected_simplified_vector_path = os.path.join(
            TEST_DATA, 'simplified_vector.gpkg')
        target_simplified_vector_path = os.path.join(self.workspace_dir,
                                                     'simplified_vector.gpkg')
        # Create an existing target vector to test if it's properly removed
        open(target_simplified_vector_path, 'a').close()

        tolerance = 3000  # in meters
        _simplify_geometry(complicated_vector_path, tolerance,
                           target_simplified_vector_path)

        pygeoprocessing.testing.assert_vectors_equal(
            target_simplified_vector_path, expected_simplified_vector_path,
            1E-6)
Beispiel #2
0
    def test_simplify_geometry_lines(self):
        """HRA: test _simplify_geometry does not alter geometry given lines."""
        from natcap.invest.hra import _simplify_geometry

        srs = osr.SpatialReference()
        srs.ImportFromEPSG(EPSG_CODE)
        base_lines_path = os.path.join(self.workspace_dir, 'base_lines.gpkg')
        lines = [LineString([(0.0, 0.0), (10.0, 10.0)])]
        pygeoprocessing.testing.sampledata.create_vector_on_disk(
            lines, srs.ExportToWkt(),
            filename=base_lines_path, vector_format='GPKG')

        target_simplified_vector_path = os.path.join(
            self.workspace_dir, 'simplified_vector.gpkg')

        tolerance = 3000  # in meters
        _simplify_geometry(
            base_lines_path, tolerance, target_simplified_vector_path)

        pygeoprocessing.testing.assert_vectors_equal(
            target_simplified_vector_path, base_lines_path,
            1E-6)
Beispiel #3
0
    def test_simplify_geometry_lines(self):
        """HRA: test _simplify_geometry does not alter geometry given lines."""
        from natcap.invest.hra import _simplify_geometry
        from natcap.invest.utils import _assert_vectors_equal

        srs = osr.SpatialReference()
        srs.ImportFromEPSG(EPSG_CODE)
        projection_wkt = srs.ExportToWkt()
        base_lines_path = os.path.join(self.workspace_dir, 'base_lines.gpkg')
        lines = [LineString([(0.0, 0.0), (10.0, 10.0)])]
        pygeoprocessing.shapely_geometry_to_vector(
            lines, base_lines_path, projection_wkt, 'GPKG',
            ogr_geom_type=ogr.wkbLineString)

        target_simplified_vector_path = os.path.join(
            self.workspace_dir, 'simplified_vector.gpkg')

        tolerance = 3000  # in meters
        _simplify_geometry(
            base_lines_path, tolerance, target_simplified_vector_path)

        _assert_vectors_equal(
            target_simplified_vector_path, base_lines_path)