Skip to content

Commit

Permalink
standardize cat and dump
Browse files Browse the repository at this point in the history
  • Loading branch information
smnorris committed Dec 17, 2024
1 parent afa8bb6 commit ddc2b11
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 42 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```

Expand All @@ -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.
Expand All @@ -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

Expand Down Expand Up @@ -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.
Expand All @@ -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]
Expand All @@ -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.
Expand Down Expand Up @@ -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.
```

Expand Down
2 changes: 1 addition & 1 deletion src/bcdata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
15 changes: 6 additions & 9 deletions src/bcdata/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,20 @@ 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",
help="Promote features to multipart",
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
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
21 changes: 0 additions & 21 deletions src/bcdata/wfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit ddc2b11

Please sign in to comment.