Skip to content

Commit 6c870e7

Browse files
committed
add count command
1 parent e496d00 commit 6c870e7

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ repos:
44
hooks:
55
- id: ruff
66
name: lint with ruff
7+
args: [--fix]
78
- id: ruff
89
name: sort imports with ruff
910
args: [--select, I, --fix]

src/bcdata/cli.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66

77
import click
88
from cligj import compact_opt, indent_opt, quiet_opt, verbose_opt
9-
from shapely.geometry.linestring import LineString
10-
from shapely.geometry.multilinestring import MultiLineString
11-
from shapely.geometry.multipoint import MultiPoint
12-
from shapely.geometry.multipolygon import MultiPolygon
13-
from shapely.geometry.point import Point
14-
from shapely.geometry.polygon import Polygon
159

1610
import bcdata
1711
from bcdata.database import Database
@@ -27,6 +21,7 @@ def configure_logging(verbosity):
2721
def complete_dataset_names(ctx, param, incomplete):
2822
return [k for k in bcdata.list_tables() if k.startswith(incomplete)]
2923

24+
3025
# bounds handling direct from rasterio
3126
# https://github.com/mapbox/rasterio/blob/master/rasterio/rio/options.py
3227
# https://github.com/mapbox/rasterio/blob/master/rasterio/rio/clip.py
@@ -202,6 +197,13 @@ def dem(
202197
help="A valid CQL or ECQL query",
203198
)
204199
@click.option("--out_file", "-o", help="Output file")
200+
@click.option(
201+
"--count",
202+
"-c",
203+
default=None,
204+
type=int,
205+
help="Number of features to request and dump",
206+
)
205207
@bounds_opt
206208
@click.option(
207209
"--bounds-crs",
@@ -219,7 +221,7 @@ def dem(
219221
@lowercase_opt
220222
@verbose_opt
221223
@quiet_opt
222-
def dump(dataset, query, out_file, bounds, bounds_crs, no_clean, lowercase, verbose, quiet):
224+
def dump(dataset, query, out_file, count, bounds, bounds_crs, no_clean, lowercase, verbose, quiet):
223225
"""Write DataBC features to stdout as GeoJSON feature collection.
224226
225227
\b
@@ -240,7 +242,13 @@ def dump(dataset, query, out_file, bounds, bounds_crs, no_clean, lowercase, verb
240242
else:
241243
clean = True
242244
data = bcdata.get_data(
243-
table, query=query, bounds=bounds, bounds_crs=bounds_crs, lowercase=lowercase, clean=clean
245+
table,
246+
query=query,
247+
count=count,
248+
bounds=bounds,
249+
bounds_crs=bounds_crs,
250+
lowercase=lowercase,
251+
clean=clean,
244252
)
245253
if out_file:
246254
with open(out_file, "w") as sink:

tests/test_cli.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import os
23

34
from click.testing import CliRunner
@@ -73,6 +74,14 @@ def test_cat_bounds_ll():
7374
assert len(result.output.split("\n")) == 4
7475

7576

77+
def test_dump():
78+
runner = CliRunner()
79+
result = runner.invoke(cli, ["dump", AIRPORTS_TABLE, "--count", 1])
80+
assert result.exit_code == 0
81+
assert json.loads(result.output)["type"] == "FeatureCollection"
82+
assert len(json.loads(result.output)["features"]) == 1
83+
84+
7685
def test_bc2pg():
7786
runner = CliRunner()
7887
result = runner.invoke(cli, ["bc2pg", AIRPORTS_TABLE, "--db_url", DB_URL])

tests/test_wfs.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import pytest
2-
import json
32
import requests
43
import requests_mock
54
import stamina
@@ -94,9 +93,7 @@ def test_get_data_lowercase():
9493

9594
def test_get_data_crs():
9695
data = bcdata.get_data(AIRPORTS_TABLE, crs="EPSG:3005")
97-
assert (
98-
data["crs"]["properties"]["name"] == 'urn:ogc:def:crs:EPSG::3005'
99-
)
96+
assert data["crs"]["properties"]["name"] == "urn:ogc:def:crs:EPSG::3005"
10097

10198

10299
def test_get_features():
@@ -159,8 +156,6 @@ def test_clean():
159156

160157
def test_no_clean():
161158
data = bcdata.get_data(
162-
AIRPORTS_TABLE,
163-
query="AIRPORT_NAME='Terrace (Northwest Regional) Airport'",
164-
clean=False
159+
AIRPORTS_TABLE, query="AIRPORT_NAME='Terrace (Northwest Regional) Airport'", clean=False
165160
)
166161
assert "SE_ANNO_CAD_DATA" in data["features"][0]["properties"].keys()

0 commit comments

Comments
 (0)