bcdata 0.7.9__tar.gz → 0.7.11__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. {bcdata-0.7.9 → bcdata-0.7.11}/CHANGES.txt +9 -0
  2. {bcdata-0.7.9/bcdata.egg-info → bcdata-0.7.11}/PKG-INFO +4 -2
  3. {bcdata-0.7.9 → bcdata-0.7.11}/README.md +3 -1
  4. {bcdata-0.7.9 → bcdata-0.7.11}/bcdata/__init__.py +1 -1
  5. {bcdata-0.7.9 → bcdata-0.7.11}/bcdata/bc2pg.py +26 -5
  6. {bcdata-0.7.9 → bcdata-0.7.11}/bcdata/cli.py +5 -2
  7. {bcdata-0.7.9 → bcdata-0.7.11/bcdata.egg-info}/PKG-INFO +4 -2
  8. {bcdata-0.7.9 → bcdata-0.7.11}/tests/test_bc2pg.py +39 -0
  9. {bcdata-0.7.9 → bcdata-0.7.11}/LICENSE.txt +0 -0
  10. {bcdata-0.7.9 → bcdata-0.7.11}/bcdata/bcdc.py +0 -0
  11. {bcdata-0.7.9 → bcdata-0.7.11}/bcdata/database.py +0 -0
  12. {bcdata-0.7.9 → bcdata-0.7.11}/bcdata/wcs.py +0 -0
  13. {bcdata-0.7.9 → bcdata-0.7.11}/bcdata/wfs.py +0 -0
  14. {bcdata-0.7.9 → bcdata-0.7.11}/bcdata.egg-info/SOURCES.txt +0 -0
  15. {bcdata-0.7.9 → bcdata-0.7.11}/bcdata.egg-info/dependency_links.txt +0 -0
  16. {bcdata-0.7.9 → bcdata-0.7.11}/bcdata.egg-info/entry_points.txt +0 -0
  17. {bcdata-0.7.9 → bcdata-0.7.11}/bcdata.egg-info/not-zip-safe +0 -0
  18. {bcdata-0.7.9 → bcdata-0.7.11}/bcdata.egg-info/requires.txt +0 -0
  19. {bcdata-0.7.9 → bcdata-0.7.11}/bcdata.egg-info/top_level.txt +0 -0
  20. {bcdata-0.7.9 → bcdata-0.7.11}/pyproject.toml +0 -0
  21. {bcdata-0.7.9 → bcdata-0.7.11}/requirements.txt +0 -0
  22. {bcdata-0.7.9 → bcdata-0.7.11}/setup.cfg +0 -0
  23. {bcdata-0.7.9 → bcdata-0.7.11}/setup.py +0 -0
  24. {bcdata-0.7.9 → bcdata-0.7.11}/tests/test_bcdata.py +0 -0
  25. {bcdata-0.7.9 → bcdata-0.7.11}/tests/test_bcdc.py +0 -0
  26. {bcdata-0.7.9 → bcdata-0.7.11}/tests/test_cli.py +0 -0
@@ -1,6 +1,15 @@
1
1
  Changes
2
2
  =======
3
3
 
4
+ 0.7.11 (2023-06-28)
5
+ ------------------
6
+ - fix conflicting bc2pg short option definitions (#134)
7
+
8
+ 0.7.10 (2023-06-28)
9
+ ------------------
10
+ - add bc2pg option --geometry_type to avoid issues when type sniffing (#132)
11
+ - fix appending to table with name different from source (#133)
12
+
4
13
  0.7.9 (2023-06-13)
5
14
  ------------------
6
15
  - fix geometry type checking (#131)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bcdata
3
- Version: 0.7.9
3
+ Version: 0.7.11
4
4
  Summary: Python tools for quick access to DataBC geo-data available via WFS
5
5
  Home-page: https://github.com/smnorris/bcdata
6
6
  Author: Simon Norris
@@ -139,11 +139,13 @@ Options:
139
139
  environment variable if set
140
140
  --table TEXT Destination table name
141
141
  --schema TEXT Destination schema name
142
+ --geometry_type TEXT Spatial type of geometry column
142
143
  --query TEXT A valid CQL or ECQL query
143
144
  -c, --count INTEGER Total number of features to load
144
145
  -p, --pagesize INTEGER Maximum request size
145
146
  -k, --primary_key TEXT Primary key of dataset
146
- -s, --schema_only Dump only the object definitions (schema), not data
147
+ -s, --sortby TEXT Name of sort field
148
+ -e, --schema_only Create empty table from catalogue schema
147
149
  -a, --append Append to existing table
148
150
  -t, --no_timestamp Do not add download timestamp to bcdata meta table
149
151
  -v, --verbose Increase verbosity.
@@ -117,11 +117,13 @@ Options:
117
117
  environment variable if set
118
118
  --table TEXT Destination table name
119
119
  --schema TEXT Destination schema name
120
+ --geometry_type TEXT Spatial type of geometry column
120
121
  --query TEXT A valid CQL or ECQL query
121
122
  -c, --count INTEGER Total number of features to load
122
123
  -p, --pagesize INTEGER Maximum request size
123
124
  -k, --primary_key TEXT Primary key of dataset
124
- -s, --schema_only Dump only the object definitions (schema), not data
125
+ -s, --sortby TEXT Name of sort field
126
+ -e, --schema_only Create empty table from catalogue schema
125
127
  -a, --append Append to existing table
126
128
  -t, --no_timestamp Do not add download timestamp to bcdata meta table
127
129
  -v, --verbose Increase verbosity.
@@ -11,4 +11,4 @@ from .bc2pg import bc2pg
11
11
  from .wcs import get_dem
12
12
 
13
13
 
14
- __version__ = "0.7.9"
14
+ __version__ = "0.7.11"
@@ -15,12 +15,25 @@ from bcdata.database import Database
15
15
 
16
16
  log = logging.getLogger(__name__)
17
17
 
18
+ SUPPORTED_TYPES = [
19
+ "POINT",
20
+ "POINTZ",
21
+ "MULTIPOINT",
22
+ "MULTIPOINTZ",
23
+ "LINESTRING",
24
+ "MULTILINESTRING",
25
+ "MULTILINESTRINGZ",
26
+ "POLYGON",
27
+ "MULTIPOLYGON",
28
+ ]
29
+
18
30
 
19
31
  def bc2pg(
20
32
  dataset,
21
33
  db_url,
22
34
  table=None,
23
35
  schema=None,
36
+ geometry_type=None,
24
37
  query=None,
25
38
  count=None,
26
39
  sortby=None,
@@ -44,16 +57,24 @@ def bc2pg(
44
57
  # if appending, get column names from db
45
58
  if append:
46
59
  # make sure table actually exists
47
- if dataset.lower() not in db.tables:
48
- raise ValueError(f"{dataset} does not exist, nothing to append to")
60
+ if schema_name + "." + table_name not in db.tables:
61
+ raise ValueError(
62
+ f"{schema_name}.{table_name} does not exist, nothing to append to"
63
+ )
49
64
  column_names = db.get_columns(schema_name, table_name)
50
65
 
51
66
  # if not appending, define and create table
52
67
  else:
53
68
  # get info about the table from catalouge
54
69
  table_comments, table_details = bcdata.get_table_definition(dataset)
55
- # find geometry type(s) in first 10 records and take the first one
56
- geom_type = bcdata.get_types(dataset, 10)[0]
70
+
71
+ # check that provided geometry type is valid
72
+ if geometry_type and geometry_type not in SUPPORTED_TYPES:
73
+ raise ValueError("Geometry type {geometry_type} is not supported")
74
+
75
+ # if geometry type is not provided, infer from first 10 records in dataset
76
+ if not geometry_type:
77
+ geometry_type = bcdata.get_types(dataset, 10)[0]
57
78
 
58
79
  # build the table definition and create table
59
80
  table = db.define_table(
@@ -61,7 +82,7 @@ def bc2pg(
61
82
  table_name,
62
83
  table_details,
63
84
  table_comments,
64
- geom_type,
85
+ geometry_type,
65
86
  primary_key,
66
87
  append,
67
88
  )
@@ -300,6 +300,7 @@ def cat(
300
300
  )
301
301
  @click.option("--table", help="Destination table name")
302
302
  @click.option("--schema", help="Destination schema name")
303
+ @click.option("--geometry_type", help="Spatial type of geometry column")
303
304
  @click.option(
304
305
  "--query",
305
306
  help="A valid CQL or ECQL query",
@@ -315,10 +316,10 @@ def cat(
315
316
  @click.option("--primary_key", "-k", default=None, help="Primary key of dataset")
316
317
  @click.option("--sortby", "-s", help="Name of sort field")
317
318
  @click.option(
319
+ "-e",
318
320
  "--schema_only",
319
- "-s",
320
321
  is_flag=True,
321
- help="Dump only the object definitions (schema), not data",
322
+ help="Create empty table from catalogue schema",
322
323
  )
323
324
  @click.option(
324
325
  "--append",
@@ -339,6 +340,7 @@ def bc2pg(
339
340
  db_url,
340
341
  table,
341
342
  schema,
343
+ geometry_type,
342
344
  query,
343
345
  count,
344
346
  pagesize,
@@ -370,6 +372,7 @@ def bc2pg(
370
372
  table=table,
371
373
  schema=schema,
372
374
  query=query,
375
+ geometry_type=geometry_type.upper(),
373
376
  count=count,
374
377
  pagesize=pagesize,
375
378
  primary_key=primary_key,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bcdata
3
- Version: 0.7.9
3
+ Version: 0.7.11
4
4
  Summary: Python tools for quick access to DataBC geo-data available via WFS
5
5
  Home-page: https://github.com/smnorris/bcdata
6
6
  Author: Simon Norris
@@ -139,11 +139,13 @@ Options:
139
139
  environment variable if set
140
140
  --table TEXT Destination table name
141
141
  --schema TEXT Destination schema name
142
+ --geometry_type TEXT Spatial type of geometry column
142
143
  --query TEXT A valid CQL or ECQL query
143
144
  -c, --count INTEGER Total number of features to load
144
145
  -p, --pagesize INTEGER Maximum request size
145
146
  -k, --primary_key TEXT Primary key of dataset
146
- -s, --schema_only Dump only the object definitions (schema), not data
147
+ -s, --sortby TEXT Name of sort field
148
+ -e, --schema_only Create empty table from catalogue schema
147
149
  -a, --append Append to existing table
148
150
  -t, --no_timestamp Do not add download timestamp to bcdata meta table
149
151
  -v, --verbose Increase verbosity.
@@ -1,3 +1,5 @@
1
+ import pytest
2
+
1
3
  import bcdata
2
4
  from bcdata.database import Database
3
5
 
@@ -41,6 +43,22 @@ def test_bc2pg_schema():
41
43
  DB_CONNECTION.execute("drop schema testschema cascade")
42
44
 
43
45
 
46
+ def test_bc2pg_geometry_type():
47
+ bcdata.bc2pg(AIRPORTS_TABLE, DB_URL, count=10, geometry_type="POINT")
48
+ assert AIRPORTS_TABLE in DB_CONNECTION.tables
49
+ DB_CONNECTION.execute("drop table " + AIRPORTS_TABLE)
50
+
51
+
52
+ def test_bc2pg_geometry_type_mismatch():
53
+ with pytest.raises(Exception):
54
+ bcdata.bc2pg(AIRPORTS_TABLE, DB_URL, count=10, geometry_type="LINESTRING")
55
+
56
+
57
+ def test_bc2pg_geometry_type_invalid():
58
+ with pytest.raises(Exception):
59
+ bcdata.bc2pg(AIRPORTS_TABLE, DB_URL, count=10, geometry_type="MULTIPOLYGONZ")
60
+
61
+
44
62
  def test_bc2pg_z():
45
63
  bcdata.bc2pg(STREAMS_TABLE, DB_URL, query="WATERSHED_GROUP_CODE='VICT'")
46
64
  assert STREAMS_TABLE in DB_CONNECTION.tables
@@ -111,3 +129,24 @@ def test_bc2pg_append():
111
129
  r = DB_CONNECTION.query("select * from whse_imagery_and_base_maps.gsr_airports_svw")
112
130
  assert len(r) == 2
113
131
  DB_CONNECTION.execute("drop table " + AIRPORTS_TABLE)
132
+
133
+
134
+ def test_bc2pg_append_to_other():
135
+ bcdata.bc2pg(AIRPORTS_TABLE, DB_URL, schema_only=True, table="arpt")
136
+ bcdata.bc2pg(
137
+ AIRPORTS_TABLE,
138
+ DB_URL,
139
+ table="arpt",
140
+ query="AIRPORT_NAME='Terrace (Northwest Regional) Airport'",
141
+ append=True,
142
+ )
143
+ bcdata.bc2pg(
144
+ AIRPORTS_TABLE,
145
+ DB_URL,
146
+ table="arpt",
147
+ query="AIRPORT_NAME='Victoria International Airport'",
148
+ append=True,
149
+ )
150
+ r = DB_CONNECTION.query("select * from whse_imagery_and_base_maps.arpt")
151
+ assert len(r) == 2
152
+ DB_CONNECTION.execute("drop table whse_imagery_and_base_maps.arpt")
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes