Skip to content

Commit

Permalink
Merge pull request #728 from nsidc/obe-gdal-remote
Browse files Browse the repository at this point in the history
Cleanup OBE references to `gdal_remote` and "Online" QgsLayerType
  • Loading branch information
trey-stafford authored Aug 17, 2023
2 parents 7e15b46 + 46b14c9 commit 69769b6
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ checkbox.
- [ ] Config lockfile updated (`inv config.export > qgreenland/config/cfg-lock.json`)
- [ ] Environment lockfile updated if needed (`conda-lock`)
- [ ] Version bumped if needed (`bumpversion (major|minor|patch|prerelease|build)`)
- [ ] CHANGELOG.md updated
- [ ] CHANGELOG.md updated (for user-facing changes)
- [ ] Documentation updated if needed
- [ ] New unit tests if needed
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
places" layer. Scale point markers for this layer by population.
* Add new "Internet-required data/Geological Map (1:500 000)" layer from GEUS.
* Add new "Geology/Mineral occurrences" layer from GEUS.
* Update `layer_list.csv` to include new column indicating if each layer is
stored on disk. Internet-required layers take the value `False`.


# v3.0.0alpha4 (2023-07-21)
Expand Down
2 changes: 1 addition & 1 deletion qgreenland/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""
from typing import Literal, Union

QgsLayerType = Literal["Vector", "Raster", "Online"]
VectorOrRaster = Literal["Vector", "Raster"]
QgsLayerProviderType = Literal["gdal", "ogr", "wms", "wfs", "wcs"]

ResamplingMethod = Literal["bilinear", "nearest"]
Expand Down
4 changes: 2 additions & 2 deletions qgreenland/constants/misc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from qgreenland._typing import QgsLayerProviderType, QgsLayerType
from qgreenland._typing import QgsLayerProviderType, VectorOrRaster

PROVIDER_LAYERTYPE_MAPPING: dict[QgsLayerProviderType, QgsLayerType] = {
PROVIDER_VECTOR_OR_RASTER_MAPPING: dict[QgsLayerProviderType, VectorOrRaster] = {
"gdal": "Raster",
"wms": "Raster",
"wfs": "Vector",
Expand Down
4 changes: 1 addition & 3 deletions qgreenland/models/config/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ def provenance(self) -> str:
return f"# Data fetched via HTTP from {[str(u) for u in self.urls]}"


# TODO: OnlineRaster/OnlineVector asset types? The thing that makes this a
# "gdal_remote" layer is the `/vsicurl/` prefix. Otherwise, this is created as a
# regular layer with a URL as its path.
# TODO: OnlineRaster/OnlineVector asset types?
class OnlineAsset(DatasetAsset):
"""A QGIS online layer that is not fetched, but is accessed by QGIS."""

Expand Down
4 changes: 3 additions & 1 deletion qgreenland/test/util/config/test_config_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,16 @@ def test_export_config_csv(full_cfg):
{
**common,
"Layer Title": "Example online",
"Vector or Raster": "Online",
"Vector or Raster": "Raster",
"Internet Required?": "False",
},
{
**common,
"Layer Title": "Example raster",
"Vector or Raster": "Raster",
"Layer Size": "619 Bytes",
"Layer Size Bytes": "619",
"Internet Required?": "True",
},
]

Expand Down
2 changes: 1 addition & 1 deletion qgreenland/test/util/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ def test_layer_compile_dir(raster_layer_node):
assert expected == actual


def test_vector_or_raster_gdal_remote(online_layer_node):
def test_vector_or_raster(online_layer_node):
assert layer_util.vector_or_raster(online_layer_node) == "Raster"
15 changes: 10 additions & 5 deletions qgreenland/util/config/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from humanize import naturalsize

from qgreenland._typing import QgsLayerType
from qgreenland._typing import VectorOrRaster
from qgreenland.models.config import Config
from qgreenland.models.config.asset import OnlineAsset
from qgreenland.util.fs import directory_contents, directory_size_bytes
Expand Down Expand Up @@ -82,16 +82,20 @@ def export_config_csv(
if not layer_cfg.in_package:
continue

layer_type: QgsLayerType
vector_or_raster_data: VectorOrRaster
internet_required: bool

vector_or_raster_data = vector_or_raster(layer_node)

if isinstance(layer_cfg.input.asset, OnlineAsset):
layer_type = "Online"
# Online layers have no size on disk.
layer_size_bytes = 0
internet_required = False
else:
layer_fp = get_layer_compile_filepath(layer_node)
layer_dir = layer_fp.parent
layer_size_bytes = directory_size_bytes(layer_dir)
layer_type = vector_or_raster(layer_node)
internet_required = True

dataset_cfg = layer_cfg.input.dataset

Expand All @@ -101,13 +105,14 @@ def export_config_csv(
"Subgroup": "/".join(layer_node.group_name_path[1:]),
"Layer Title": layer_cfg.title,
"Layer Description": layer_cfg.description,
"Vector or Raster": layer_type,
"Vector or Raster": vector_or_raster_data,
"Data Source Title": dataset_cfg.metadata.title,
"Data Source Abstract": dataset_cfg.metadata.abstract,
"Data Source Citation": dataset_cfg.metadata.citation.text,
"Data Source Citation URL": dataset_cfg.metadata.citation.url,
"Layer Size": naturalsize(layer_size_bytes),
"Layer Size Bytes": layer_size_bytes,
"Internet Required?": internet_required,
}
)

Expand Down
10 changes: 5 additions & 5 deletions qgreenland/util/layer.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
from pathlib import Path

import qgreenland.exceptions as exc
from qgreenland._typing import QgsLayerType
from qgreenland.constants.misc import PROVIDER_LAYERTYPE_MAPPING
from qgreenland._typing import VectorOrRaster
from qgreenland.constants.misc import PROVIDER_VECTOR_OR_RASTER_MAPPING
from qgreenland.constants.paths import COMPILE_PACKAGE_DIR, RELEASE_LAYERS_DIR
from qgreenland.models.config.asset import OnlineAsset
from qgreenland.models.config.layer import Layer
from qgreenland.util.fs import get_layer_fp
from qgreenland.util.tree import LayerNode


def vector_or_raster(layer_node: LayerNode) -> QgsLayerType:
def vector_or_raster(layer_node: LayerNode) -> VectorOrRaster:
layer_cfg = layer_node.layer_cfg
if type(layer_cfg.input.asset) is OnlineAsset:
return PROVIDER_LAYERTYPE_MAPPING[layer_cfg.input.asset.provider]
return PROVIDER_VECTOR_OR_RASTER_MAPPING[layer_cfg.input.asset.provider]
else:
layer_path = get_layer_compile_filepath(layer_node)
return _vector_or_raster_from_fp(layer_path)
Expand Down Expand Up @@ -57,7 +57,7 @@ def _layer_dirname_from_cfg(layer_cfg: Layer) -> str:
return layer_cfg.title


def _vector_or_raster_from_fp(fp: Path) -> QgsLayerType:
def _vector_or_raster_from_fp(fp: Path) -> VectorOrRaster:
if fp.suffix == ".tif":
return "Raster"
elif fp.suffix == ".gpkg":
Expand Down

0 comments on commit 69769b6

Please sign in to comment.