From ddc2b11fbccd9d3c313f098ba27c2a2a3ebe715a Mon Sep 17 00:00:00 2001 From: Simon Norris Date: Tue, 17 Dec 2024 09:39:31 -0800 Subject: [PATCH] standardize cat and dump --- CHANGES.txt | 4 ++++ README.md | 25 ++++++++++++++----------- src/bcdata/__init__.py | 2 +- src/bcdata/cli.py | 15 ++++++--------- src/bcdata/wfs.py | 21 --------------------- 5 files changed, 25 insertions(+), 42 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index b712685..5fd675c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,10 @@ Changes ======= +0.14.0 (2024-12-17) +------------------ +- simplify WFS module, standardize cat/dump options + 0.13.0 (2024-12-11) ------------------ - support Data Catalogue API changes (#188) diff --git a/README.md b/README.md index 439bbf6..37751dc 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,8 @@ AERODROME_STATUS AIRCRAFT_ACCESS_IND AIRPORT_NAME ``` ### CLI -Commands available via the bcdata command line interface are documented with the `--help` option: + +Commands available via the bcdata command line interface are documented with the --help option ``` @@ -104,7 +105,7 @@ Options: --help Show this message and exit. Commands: - bc2pg Download a DataBC WFS layer to postgres + bc2pg Load a DataBC WFS layer to a postgres db cat Write DataBC features to stdout as GeoJSON feature objects. dem Dump BC DEM to TIFF dump Write DataBC features to stdout as GeoJSON feature collection. @@ -119,7 +120,7 @@ $ bcdata bc2pg --help Usage: bcdata bc2pg [OPTIONS] DATASET - Download a DataBC WFS layer to postgres + Load a DataBC WFS layer to a postgres db $ bcdata bc2pg whse_imagery_and_base_maps.gsr_airports_svw @@ -158,16 +159,18 @@ Usage: bcdata cat [OPTIONS] DATASET Options: --query TEXT A valid CQL or ECQL query + -c, --count INTEGER Number of features to request and dump --bounds TEXT Bounds: "left bottom right top" or "[left, bottom, right, top]". Coordinates are BC Albers (default) or --bounds_crs + --bounds-crs, --bounds_crs TEXT + CRS of provided bounds --indent INTEGER Indentation level for JSON output --compact / --not-compact Use compact separators (',', ':'). --dst-crs, --dst_crs TEXT Destination CRS -s, --sortby TEXT Name of sort field - --bounds-crs, --bounds_crs TEXT - CRS of provided bounds -l, --lowercase Write column/properties names as lowercase + -m, --promote-to-multi Promote features to multipart -v, --verbose Increase verbosity. -q, --quiet Decrease verbosity. --help Show this message and exit. @@ -187,9 +190,8 @@ Options: --bounds TEXT Bounds: "left bottom right top" or "[left, bottom, right, top]". Coordinates are BC Albers (default) or --bounds_crs [required] - --dst-crs, --dst_crs TEXT Destination CRS - --bounds-crs, --bounds_crs TEXT - CRS of provided bounds + --dst-crs TEXT CRS of output file + --bounds-crs TEXT CRS of provided bounds -r, --resolution INTEGER -a, --align Align provided bounds to provincial standard -i, --interpolation [nearest|bilinear|bicubic] @@ -211,20 +213,20 @@ Usage: bcdata dump [OPTIONS] DATASET $ bcdata dump bc-airports --query "AIRPORT_NAME='Victoria Harbour (Shoal Point) Heliport'" $ bcdata dump bc-airports --bounds xmin ymin xmax ymax - It can also be combined to read bounds of a feature dataset using Fiona: + It can also be combined to read bounds of a feature dataset using Fiona:  $ bcdata dump bc-airports --bounds $(fio info aoi.shp --bounds) Options: --query TEXT A valid CQL or ECQL query - -o, --out_file TEXT Output file -c, --count INTEGER Number of features to request and dump --bounds TEXT Bounds: "left bottom right top" or "[left, bottom, right, top]". Coordinates are BC Albers (default) or --bounds_crs --bounds-crs, --bounds_crs TEXT CRS of provided bounds - -nc, --no-clean Do not do any data standardization + -s, --sortby TEXT Name of sort field -l, --lowercase Write column/properties names as lowercase + -m, --promote-to-multi Promote features to multipart -v, --verbose Increase verbosity. -q, --quiet Decrease verbosity. --help Show this message and exit. @@ -261,6 +263,7 @@ Usage: bcdata list [OPTIONS] List DataBC layers available via WFS Options: + -r, --refresh Refresh the cached list --help Show this message and exit. ``` diff --git a/src/bcdata/__init__.py b/src/bcdata/__init__.py index f291818..d6ec031 100644 --- a/src/bcdata/__init__.py +++ b/src/bcdata/__init__.py @@ -22,4 +22,4 @@ raise Exception(f"Failed to download primary key database at {PRIMARY_KEY_DB_URL}") primary_keys = {} -__version__ = "0.14.0dev0" +__version__ = "0.14.0" diff --git a/src/bcdata/cli.py b/src/bcdata/cli.py index 2608cab..d9ff899 100644 --- a/src/bcdata/cli.py +++ b/src/bcdata/cli.py @@ -210,6 +210,8 @@ def dem( help="CRS of provided bounds", default="EPSG:3005", ) +@click.option("--sortby", "-s", help="Name of sort field") +@lowercase_opt @click.option( "--promote-to-multi", "-m", @@ -217,10 +219,11 @@ def dem( is_flag=True, default=False, ) -@lowercase_opt @verbose_opt @quiet_opt -def dump(dataset, query, count, bounds, bounds_crs, lowercase, promote_to_multi, verbose, quiet): +def dump( + dataset, query, count, bounds, bounds_crs, sortby, lowercase, promote_to_multi, verbose, quiet +): """Write DataBC features to stdout as GeoJSON feature collection. \b @@ -242,6 +245,7 @@ def dump(dataset, query, count, bounds, bounds_crs, lowercase, promote_to_multi, count=count, bounds=bounds, bounds_crs=bounds_crs, + sortby=sortby, lowercase=lowercase, promote_to_multi=promote_to_multi, as_gdf=False, @@ -330,13 +334,6 @@ def cat( click.echo(json.dumps(feat, **dump_kwds)) -@cli.command() -@verbose_opt -@quiet_opt -def clear_cache(verbose, quiet): - bcdata.clear_cache() - - @cli.command() @click.argument("dataset", type=click.STRING, shell_complete=complete_dataset_names) @click.option( diff --git a/src/bcdata/wfs.py b/src/bcdata/wfs.py index 5f78fec..f78ecce 100644 --- a/src/bcdata/wfs.py +++ b/src/bcdata/wfs.py @@ -47,27 +47,6 @@ def promote_gdf_to_multi(df): return df -def ensure_single_geometry_type(df): - """If mix of single/multi part geometries are present, promote all geometries to multipart""" - geomtypes = sorted( - [t.upper() for t in df.geometry.geom_type.dropna(axis=0, how="all").unique()], key=len - ) - if len(geomtypes) > 1 and geomtypes[1] == "MULTI" + geomtypes[0]: - df.geometry = [ - MultiPoint([feature]) if isinstance(feature, Point) else feature - for feature in df.geometry - ] - df.geometry = [ - MultiLineString([feature]) if isinstance(feature, LineString) else feature - for feature in df.geometry - ] - df.geometry = [ - MultiPolygon([feature]) if isinstance(feature, Polygon) else feature - for feature in df.geometry - ] - return df - - class ServiceException(Exception): pass