Skip to content

Commit

Permalink
Issue173 (#174)
Browse files Browse the repository at this point in the history
* fix #173

* note new options in readmen

* document the typical use case
  • Loading branch information
smnorris committed Apr 4, 2024
1 parent 099e3aa commit e608766
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 19 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.10.3 ()
------------------
- add missing --bounds option to bc2pg (#173)

0.10.2 (2024-03-01)
------------------
- improve connection management for better stability (#171)
Expand Down
39 changes: 22 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,25 +119,30 @@ Usage: bcdata bc2pg [OPTIONS] DATASET

Download a DataBC WFS layer to postgres

$ bcdata bc2pg bc-airports --db_url postgresql://postgres:postgres@localhost:5432/postgis
$ bcdata bc2pg whse_imagery_and_base_maps.gsr_airports_svw

Options:
-db, --db_url TEXT Target database url, defaults to $DATABASE_URL
environment variable if set
--table TEXT Destination table name
--schema TEXT Destination schema name
--geometry_type TEXT Spatial type of geometry column
--query TEXT A valid CQL or ECQL query
-c, --count INTEGER Total number of features to load
-k, --primary_key TEXT Primary key of dataset
-s, --sortby TEXT Name of sort field
-e, --schema_only Create empty table from catalogue schema
-a, --append Append to existing table
-r, --refresh Truncate from existing table before load
-t, --no_timestamp Do not log download to bcdata.log
-v, --verbose Increase verbosity.
-q, --quiet Decrease verbosity.
--help Show this message and exit.
-db, --db_url TEXT Target database url, defaults to
$DATABASE_URL environment variable if set
--table TEXT Destination table name
--schema TEXT Destination schema name
--geometry_type TEXT Spatial type of geometry column
--query TEXT A valid CQL or ECQL query
--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
-c, --count INTEGER Total number of features to load
-k, --primary_key TEXT Primary key of dataset
-s, --sortby TEXT Name of sort field
-e, --schema_only Create empty table from catalogue schema
-a, --append Append to existing table
-r, --refresh Truncate from existing table before load
-t, --no_timestamp Do not log download to bcdata.log
-v, --verbose Increase verbosity.
-q, --quiet Decrease verbosity.
--help Show this message and exit.
```

#### cat
Expand Down
4 changes: 4 additions & 0 deletions bcdata/bc2pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def bc2pg( # noqa: C901
schema=None,
geometry_type=None,
query=None,
bounds=None,
bounds_crs=None,
count=None,
sortby=None,
primary_key=None,
Expand Down Expand Up @@ -82,6 +84,8 @@ def bc2pg( # noqa: C901
urls = bcdata.define_requests(
dataset,
query=query,
bounds=bounds,
bounds_crs=bounds_crs,
count=count,
sortby=sortby,
crs="epsg:3005",
Expand Down
15 changes: 13 additions & 2 deletions bcdata/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,13 @@ def clear_cache(verbose, quiet):
"--query",
help="A valid CQL or ECQL query",
)
@bounds_opt
@click.option(
"--bounds-crs",
"--bounds_crs",
help="CRS of provided bounds",
default="EPSG:3005",
)
@click.option(
"--count",
"-c",
Expand Down Expand Up @@ -362,6 +369,8 @@ def bc2pg(
schema,
geometry_type,
query,
bounds,
bounds_crs,
count,
primary_key,
sortby,
Expand All @@ -372,10 +381,10 @@ def bc2pg(
verbose,
quiet,
):
"""Download a DataBC WFS layer to postgres
"""Load a DataBC WFS layer to a postgres db
\b
$ bcdata bc2pg bc-airports --db_url postgresql://postgres:postgres@localhost:5432/postgis
$ bcdata bc2pg whse_imagery_and_base_maps.gsr_airports_svw
"""
# for this command, default to INFO level logging
verbosity = verbose - quiet
Expand Down Expand Up @@ -411,6 +420,8 @@ def bc2pg(
table=table,
schema=schema,
query=query,
bounds=bounds,
bounds_crs=bounds_crs,
geometry_type=geometry_type,
count=count,
primary_key=primary_key,
Expand Down
22 changes: 22 additions & 0 deletions tests/test_bc2pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,28 @@ def test_bc2pg_count():
DB_CONNECTION.execute("drop table " + AIRPORTS_TABLE)


def test_bc2pg_bounds():
bcdata.bc2pg(AIRPORTS_TABLE, DB_URL, bounds=[1188000, 377051, 1207437, 390361])
assert AIRPORTS_TABLE in DB_CONNECTION.tables
r = DB_CONNECTION.query(
"select airport_name from whse_imagery_and_base_maps.gsr_airports_svw"
)
assert len(r) == 8
DB_CONNECTION.execute("drop table " + AIRPORTS_TABLE)


def test_bc2pg_bounds_count():
bcdata.bc2pg(
AIRPORTS_TABLE, DB_URL, bounds=[1188000, 377051, 1207437, 390361], count=6
)
assert AIRPORTS_TABLE in DB_CONNECTION.tables
r = DB_CONNECTION.query(
"select airport_name from whse_imagery_and_base_maps.gsr_airports_svw"
)
assert len(r) == 6
DB_CONNECTION.execute("drop table " + AIRPORTS_TABLE)


def test_bc2pg_table():
bcdata.bc2pg(AIRPORTS_TABLE, DB_URL, table="testtable")
assert "whse_imagery_and_base_maps.testtable" in DB_CONNECTION.tables
Expand Down

0 comments on commit e608766

Please sign in to comment.