Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added dicogis/cli/__init__.py
Empty file.
73 changes: 73 additions & 0 deletions dicogis/cli/cmd_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#! python3 # noqa: E265

# ############################################################################
# ########## Libraries #############
# ##################################

# standard lib
import logging
from pathlib import Path
from typing import Annotated, Optional

# 3rd party
import typer

# project
from dicogis.__about__ import __title__

# ############################################################################
# ########## Globals ###############
# ##################################

cli_list = typer.Typer(help="List (inventory) operations.")
state = {"verbose": False}
APP_NAME = f"{__title__}_list"
logger = logging.getLogger(__name__)


# ############################################################################
# ########## Functions #############
# ##################################


@cli_list.command(
help="List geodata and extract metadata into an Excel (.xlsx) spreadsheet file."
)
def inventory(
input_folder: Annotated[
Optional[Path],
typer.Option(
dir_okay=True,
file_okay=False,
readable=True,
resolve_path=True,
envvar="DICOGIS_START_FOLDER",
),
],
formats: Annotated[
str,
typer.Option(
envvar="DICOGIS_FORMATS_LIST",
),
] = "shp,geotiff,geojson,kml",
):
"""Command to list geodata starting from a

Args:
input_folder (Annotated[Optional[Path], typer.Option): _description_
"""
typer.echo(
f"Analysing geodata stored in {input_folder}. Targetted formats: {formats}"
)
app_dir = typer.get_app_dir(APP_NAME)
logger.warning(f"DicoGIS folder: {app_dir}")

# TODO: check if specified formats are supported


# ############################################################################
# #### Stand alone program ########
# #################################
if __name__ == "__main__":
"""standalone execution"""
cli_list()
82 changes: 82 additions & 0 deletions dicogis/cli/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#! python3 # noqa: E265

# ############################################################################
# ########## Libraries #############
# ##################################

# standard lib
import logging
from typing import Annotated, Optional

# 3rd party
import typer

# project
from dicogis.__about__ import __title__, __version__
from dicogis.cli.cmd_list import cli_list

# ############################################################################
# ########## Globals ###############
# ##################################

cli_dicogis = typer.Typer()
state = {"verbose": False}
APP_NAME = __title__
logger = logging.getLogger(__name__)


# ############################################################################
# ########## Functions #############
# ##################################


def version_callback(value: bool):
"""Special callback to show verison and exit.

See: https://typer.tiangolo.com/tutorial/options/version/

Raises:
typer.Exit: CLI exit
"""
if value:
typer.echo(f"{__title__} {__version__}")
raise typer.Exit()


@cli_dicogis.callback()
def main(
verbose: bool = False,
version: Annotated[
Optional[bool],
typer.Option(
"--version",
callback=version_callback,
is_eager=True,
help="Show version and exit.",
),
] = None,
):
"""Common options to commands or option only applicable to the main command.

Args:
verbose (bool, optional): enable verbose mode. Defaults to False.
version (Annotated[ Optional[bool], typer.Option, optional): show version and
exit. Defaults to version_callback.
"""
if verbose:
state["verbose"] = True
if version:
typer.echo(f"{__title__} {__version__}")
raise typer.Exit()


# integrate subcommands
cli_dicogis.add_typer(cli_list, name="list")


# ############################################################################
# #### Stand alone program ########
# #################################
if __name__ == "__main__":
"""standalone execution"""
cli_dicogis()
31 changes: 31 additions & 0 deletions dicogis/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from enum import Enum


class FormatsVector(str, Enum):
"""Supported vectors formats.

Args:
str (_type_): _description_
Enum (_type_): _description_
"""

esri_shapefile = "shp"
geojson = "GeoJSON"
gml = "GML"
kml = "KML"
mapinfo_tab = "tab"


class FormatsRaster(str, Enum):
"""Suported raster formats.

Args:
str (_type_): _description_
Enum (_type_): _description_
"""

geotiff = "geotiff"
jpeg = "jpeg"


SUPPORTED_FORMATS = [*FormatsVector, *FormatsRaster]
Empty file added dicogis/listing/__init__.py
Empty file.
94 changes: 94 additions & 0 deletions dicogis/listing/formats_matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#! python3 # noqa: E265

"""
Matching table of formats and their extensions, types, etc.

Resources:

- https://app.isogeo.com/api/v1/formats
- https://github.com/isogeo/isogeo-worker-client-fme/blob/master/lib/formats/file.js

"""

# #############################################################################
# ########## Libraries #############
# ##################################

# package
from dicogis.listing.models import FormatMatcher

# ##############################################################################
# ############ Globals ############
# #################################

FORMATS_MATRIX = {
# Esri SDE
"arcsde": FormatMatcher(
data_structure="both",
name="ESRI SDE Geodatabase",
alternative_names=["arcsde", "geodatabase_sde", "sde", "sde30"],
storage_kind="sgbd",
extension=".sde",
dependencies_required=[],
dependencies_optional=[],
),
# Esri FileGeoDatabase
"filegdb": FormatMatcher(
data_structure="both",
name="ESRI File Geodatabase",
alternative_names=["esri_filegdb"],
storage_kind="directory",
extension=".gdb",
dependencies_required=[],
dependencies_optional=[],
),
# GeoTIFF
"geotiff": FormatMatcher(
data_structure="raster",
name="geotiff",
alternative_names=["geotiff", "tiff"],
storage_kind="files",
extension=".tif",
dependencies_required=["tab", "tfw"],
dependencies_optional=[".aux", ".aux.xml", ".lgo", ".txt", ".wld"],
),
# Esri Shapefiles
"shp": FormatMatcher(
data_structure="vector",
name="ESRI Shapefile",
alternative_names=["esri_shp", "esri_shape", "shapefile", "shapefiles"],
storage_kind="files",
extension=".shp",
dependencies_required=[".dbf", ".shx"],
dependencies_optional=[
".atx",
".cpg",
".fbn",
".fbx",
".ixs",
".mxs",
".prj",
".sbn",
".sbx",
".shp.xml",
],
),
# PostGIS
"postgis": FormatMatcher(
data_structure="both",
name="PostGIS",
alternative_names=["postgis", "pgis", "postgresql_postgis"],
storage_kind="sgbd",
extension=".pgconf",
dependencies_required=[],
dependencies_optional=[],
),
}

# #############################################################################
# ##### Stand alone program ########
# ##################################
if __name__ == "__main__":
"""Standalone execution and development tests"""
for i in FORMATS_MATRIX:
assert isinstance(FORMATS_MATRIX.get(i), FormatMatcher)
Loading