Skip to content

Commit

Permalink
more flexible deps defs and improve readme
Browse files Browse the repository at this point in the history
  • Loading branch information
arbakker committed Nov 24, 2023
1 parent fccefc4 commit 889f136
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 88 deletions.
28 changes: 28 additions & 0 deletions DOCS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# DOCS

> **TODO:** Add graphs for density-check command.
## Densify command

See the following flowchart for a highlevel schematic overview of the `densify` functionality of `geodense`:

```mermaid
flowchart
input([fa:fa-database input data]) --> p_1[get input-crs]
p_1 --> d_1{input-crs<br>type and<br>densification method}
d_1 -->|geographic and linear| output_error([fa:fa-exclamation-triangle error: cannot do linear densification<br> on data in a geographic crs])
d_1 -->|geographic and geodesic| p_3
d_1 -->|projected and linear| p_4[linear densify in input-crs]
d_1 -->|projected and geodesic| p_2
p_4-->d_4
p_3["geodesic densify with<br>ellipse of input-crs or base-geographic-crs"]
p_2[convert to LatLon in<br>base-geographic-crs<br> of input-crs]
p_2 --> p_3
p_3-->d_4{input-crs<br>type and<br>densification method}
d_4 -->|projected and geodesic| p_5[convert back to input-crs]
p_5 -->output
d_4 -->|geographic and geodesic| output([fa:fa-database output data])
d_4 -->|projected and linear| output
style output_error stroke: red,stroke-width:2px
style output stroke: green,stroke-width:2px
```
91 changes: 35 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,84 +2,63 @@

[![Endpoint Badge](https://img.shields.io/endpoint?url=https%3A%2F%2Fgeodetischeinfrastructuur.github.io%2Fgeodense%2Fbadge.json&style=flat-square&logo=pytest&logoColor=white)](https://geodetischeinfrastructuur.github.io/geodense/)

Python library and CLI tool to **check density** and **densify** linestring and polygon geometries using the geodesic (ellipsoidal great-circle) calculation.
Python library and CLI tool to **check density** and **densify** geometries using the geodesic (ellipsoidal great-circle) calculation for accurate CRS transformations.

Implementation based on [*Eenduidige transformatie van grenzen tussen ETRS89 en RD*](https://geoforum.nl/uploads/default/original/2X/c/c0795baa683bf3845c866ae4c576a880455be02a.pdf)

See the following flowchart for a highlevel schematic overview of the `densify` functionality of `geodense`:

```mermaid
flowchart
input([fa:fa-database input data]) --> p_1[get input-crs]
p_1 --> d_1{input-crs<br>type and<br>densification method}
d_1 -->|geographic and linear| output_error([fa:fa-exclamation-triangle error: cannot do linear densification<br> on data in a geographic crs])
d_1 -->|geographic and geodesic| p_3
d_1 -->|projected and linear| p_4[linear densify in input-crs]
d_1 -->|projected and geodesic| p_2
p_4-->d_4
p_3["geodesic densify with<br>ellipse of input-crs or base-geographic-crs"]
p_2[convert to LatLon in<br>base-geographic-crs<br> of input-crs]
p_2 --> p_3
p_3-->d_4{input-crs<br>type and<br>densification method}
d_4 -->|projected and geodesic| p_5[convert back to input-crs]
p_5 -->output
d_4 -->|geographic and geodesic| output([fa:fa-database output data])
d_4 -->|projected and linear| output
style output_error stroke: red,stroke-width:2px
style output stroke: green,stroke-width:2px
```

## Installation
Requires Python v3.11 or higher.

To install from source check out this repository and run from the root:
Depends on:

```sh
pip install .
```
- `pyproj ~= 3.6.0` -> [requires PROJ 9+](https://pyproj4.github.io/pyproj/stable/installation.html#installing-from-source)
- `shapely ~= 2.0.2` -> [requires GEOS >= 3.5](https://shapely.readthedocs.io/en/stable/index.html#requirements)

## Development
## Usage CLI

> **TODO**: add description how to setup dev environment with conda/miniconda and libmamba solver, and install pyproj with: `conda install -c conda-forge pyproj==3.6.0 --solver=libmamba`
Use either `geodense` or the short `gden` alias:

```txt
$ geodense --help
Requires Python v3.11 or higher.
Usage: geodense [-h] [-v] {densify,check-density} ...
Install/uninstall for development:
Check density of, and densify geometries using the geodesic (ellipsoidal great-circle) calculation for accurate CRS transformations
```sh
pip install -e .
pip uninstall geodense
```
Commands:
{densify,check-density}
Install dev dependencies with:
Options:
-h, --help show this help message and exit
-v, --version show program's version number and exit
```sh
pip install ".[dev]"
Created by https://www.nsgi.nl/
```

Check test coverage (install `coverage` with `pip install coverage` ):
## Usage Docs

```sh
python -m coverage run -p --source=src/geodense -m pytest -v tests && python -m coverage report -m
```
See [`DOCS.md`](https://github.com/GeodetischeInfrastructuur/geodense/blob/main/DOCS.md) for usage docs; for now only containing flow-charts of the `densify` and `check-densify` subcommands.

## Usage CLI
## Development

Use either `geodense` or the short `gden` alias:
> **TODO**: add description how to setup dev environment with conda/miniconda and libmamba solver, and install pyproj with: `conda install -c conda-forge pyproj==3.6.0 --solver=libmamba`
```txt
$ geodense --help
Install/uninstall geodense for development, including dev dependencies (run from root of repository):

Usage: geodense [-h] {list-formats,densify,check-density} ...
```sh
pip install -e ".[dev]"
pip uninstall geodense
```

Check density of, and densify geometries using the geodesic (ellipsoidal great-circle)
calculation for accurate CRS transformations
### Tests

Commands:
{list-formats,densify,check-density}
Run tests:

Options:
-h, --help show this help message and exit
```sh
python3 -m pytest tests/
```

Created by https://www.nsgi.nl/
Check test coverage:

```sh
python3 -m coverage run -p --source=src/geodense -m pytest -v tests && python3 -m coverage report
```
28 changes: 17 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
[project]
name = "geodense"
description = "Check density of, and densify geospatial geometries (GeoJSON format) using the geodesic great-circle calculation for accurate CRS transformations"
description = "Python library and CLI tool to check density and densify geometries using the geodesic (ellipsoidal great-circle) calculation for accurate CRS transformations"
keywords = [
"geojson","geodesic", "densify", "great-circle", "CRS","coordinate reference system", "NSGI"
"geojson",
"geodesic",
"densify",
"great-circle",
"CRS",
"coordinate reference system",
"NSGI",
]
license = { text = "MIT" }
classifiers = [
Expand All @@ -12,10 +18,10 @@ classifiers = [
]
readme = { file = "./README.md", content-type = "text/markdown" }
dependencies = [
"rich-argparse == 1.3.0",
"pyproj == 3.6.0",
"geojson-pydantic == 1.0.1",
"shapely == 2.0.2"
"geojson-pydantic ~= 1.0",
"pyproj ~= 3.6.0",
"rich-argparse ~= 1.3",
"shapely ~= 2.0.2",
]
requires-python = ">=3.11"
dynamic = ["version"]
Expand All @@ -31,7 +37,7 @@ dev = [
"mypy == 1.5.1",
"pytest == 7.4.2",
"pytest-env == 1.0.1",
"ruff == 0.0.291"
"ruff == 0.0.291",
]


Expand Down Expand Up @@ -73,7 +79,7 @@ select = [
"ARG",
"SIM",
"Q",
"ANN"
"ANN",
]
# Avoid enforcing line-length violations (`E501`) - fixed by Black
ignore = ["E501"]
Expand All @@ -95,7 +101,7 @@ fixable = [
"S",
"ARG",
"SIM",
"Q"
"Q",
]
unfixable = []

Expand Down Expand Up @@ -135,11 +141,11 @@ target-version = "py311"
[tool.ruff.per-file-ignores]
"tests/**/*.py" = [
"S101", # asserts allowed
"ANN" # no type annotation required
"ANN", # no type annotation required
]
"util.py" = [
"S101", # asserts allowed
"ANN" # no type annotation required
"ANN", # no type annotation required
]

[tool.ruff.mccabe]
Expand Down
12 changes: 0 additions & 12 deletions src/geodense/_version.py

This file was deleted.

9 changes: 4 additions & 5 deletions src/geodense/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from rich_argparse import RichHelpFormatter

from geodense import add_stderr_logger
from geodense import __version__, add_stderr_logger
from geodense.lib import (
check_density_file,
densify_file,
Expand Down Expand Up @@ -74,12 +74,11 @@ def check_density_cmd(
def main() -> None:
parser = argparse.ArgumentParser(
prog="geodense",
description="Check density of, and densify geometries \
using the geodesic (ellipsoidal great-circle) calculation for accurate CRS transformations",
description="Check density and densify geometries using the geodesic (ellipsoidal great-circle) calculation for accurate CRS transformations",
epilog="Created by https://www.nsgi.nl/",
formatter_class=RichHelpFormatter,
)

parser.add_argument("-v", "--version", action="version", version=__version__)
subparsers = parser.add_subparsers()

densify_parser = subparsers.add_parser(
Expand Down Expand Up @@ -166,7 +165,7 @@ def main() -> None:
func(**vars(args))
except AttributeError as _:
parser.print_help(file=sys.stderr)
sys.exit(0)
sys.exit(1)


if __name__ == "__main__":
Expand Down
7 changes: 3 additions & 4 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from geodense.main import check_density_cmd, main
from geodense.models import DEFAULT_MAX_SEGMENT_LENGTH, GeodenseError

USAGE_STRING = "Usage: geodense [-h] {densify,check-density} ..."
USAGE_REGEX = r"^Usage: geodense (\[.+\])+ \{.*?\}"


@patch("geodense.main.densify_cmd")
Expand Down Expand Up @@ -138,13 +138,12 @@ def test_cli_shows_help_text_stderr_invoked_no_args(capsys):
with pytest.raises(SystemExit), ArgvContext("geodense"):
main()
_, err = capsys.readouterr()
assert err.startswith(USAGE_STRING)
assert "show this help message and exit" in err
assert re.match(USAGE_REGEX, err)


def test_cli_shows_help_text_invoked_help(capsys):
with pytest.raises(SystemExit), ArgvContext("geodense", "--help"):
main()
out, _ = capsys.readouterr()
assert out.startswith(USAGE_STRING)
assert re.match(USAGE_REGEX, out)
assert "show this help message and exit" in out

0 comments on commit 889f136

Please sign in to comment.