Skip to content

Commit

Permalink
Merge pull request #878 from koordinates/disable-vrts
Browse files Browse the repository at this point in the history
Disable VRTs, unless specifically flagged on
  • Loading branch information
olsen232 committed Jun 22, 2023
2 parents 454e56f + ebf08f0 commit 0b75839
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/pages/raster_datasets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ For instance, every tile in a dataset must have the same CRS. If newly added til
Git LFS
~~~~~~~
For technical reasons, raster tiles are stored within the repository using `Git LFS <git_lfs_>`_, instead of the more fundamental backend store which is the "Git Object Database". For more details, see the section on :doc:`Git LFS </pages/git_lfs>`.

VRT files
~~~~~~~~~
Setting an environment variable ``KART_RASTER_VRTS=1`` when creating the Kart working copy or checking out a commit will cause Kart to create a `VRT <vrt_>`_ (Virtual Raster) file for each raster dataset. This single file comprises a mosaic of all the tiles in the working copy that belong to that dataset, so that if you load this file in your tile-editing software, you have effectively loaded the entire dataset. The individual tiles are referenced by the VRT, rather than the data from each tile being duplicated in the VRT. Creation of VRTs is still experimental but should become the default in a future version of Kart.
4 changes: 3 additions & 1 deletion kart/raster/v1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import functools
import os
import re

from kart.core import all_blobs_in_tree
Expand Down Expand Up @@ -81,7 +82,8 @@ def convert_tile_to_format(cls, source_path, dest_path, target_format):
def write_mosaic_for_directory(cls, directory_path):
from kart.raster.mosaic_util import write_vrt_for_directory

write_vrt_for_directory(directory_path)
if os.environ.get("KART_RASTER_VRTS"):
write_vrt_for_directory(directory_path)

@classmethod
def get_tile_path_pattern(
Expand Down
18 changes: 17 additions & 1 deletion tests/raster/test_workingcopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,9 @@ def test_working_copy_conflicting_extension(cli_runner, data_archive):
assert "More than one tile found in working copy with the same name" in r.stderr


def test_working_copy_vrt(cli_runner, data_archive):
def test_working_copy_vrt(cli_runner, data_archive, monkeypatch):
monkeypatch.setenv("KART_RASTER_VRTS", "1")

with data_archive("raster/elevation.tgz") as repo_path:
vrt_path = repo_path / "elevation" / "elevation.vrt"

Expand All @@ -757,6 +759,20 @@ def test_working_copy_vrt(cli_runner, data_archive):
assert '<SourceFilename relativeToVRT="1">EK.tif</SourceFilename>' in vrt_text


def test_working_copy_vrt_disabled(cli_runner, data_archive, monkeypatch):
with data_archive("raster/elevation.tgz") as repo_path:

shutil.rmtree(repo_path / "elevation")

r = cli_runner.invoke(
["create-workingcopy", "--delete-existing", "--discard-changes"]
)
assert r.exit_code == 0, r.stderr

vrt_path = repo_path / "elevation" / "elevation.vrt"
assert not vrt_path.is_file()


@pytest.mark.skipif(is_windows, reason="copy-on-write not supported on windows")
def test_working_copy_reflink(cli_runner, data_archive, check_tile_is_reflinked):
# This test will show as passed if Kart's reflinks are working,
Expand Down

0 comments on commit 0b75839

Please sign in to comment.