bcdata 0.12.2__tar.gz → 0.12.3__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.
- {bcdata-0.12.2 → bcdata-0.12.3}/CHANGES.txt +5 -0
- {bcdata-0.12.2/bcdata.egg-info → bcdata-0.12.3}/PKG-INFO +1 -1
- {bcdata-0.12.2 → bcdata-0.12.3}/bcdata/__init__.py +1 -1
- {bcdata-0.12.2 → bcdata-0.12.3}/bcdata/bc2pg.py +27 -14
- {bcdata-0.12.2 → bcdata-0.12.3}/bcdata/bcdc.py +14 -3
- {bcdata-0.12.2 → bcdata-0.12.3}/bcdata/database.py +2 -1
- {bcdata-0.12.2 → bcdata-0.12.3/bcdata.egg-info}/PKG-INFO +1 -1
- {bcdata-0.12.2 → bcdata-0.12.3}/bcdata.egg-info/SOURCES.txt +1 -0
- bcdata-0.12.3/tests/t.py +3 -0
- {bcdata-0.12.2 → bcdata-0.12.3}/tests/test_bc2pg.py +13 -1
- {bcdata-0.12.2 → bcdata-0.12.3}/tests/test_bcdc.py +9 -0
- {bcdata-0.12.2 → bcdata-0.12.3}/LICENSE.txt +0 -0
- {bcdata-0.12.2 → bcdata-0.12.3}/README.md +0 -0
- {bcdata-0.12.2 → bcdata-0.12.3}/bcdata/cli.py +0 -0
- {bcdata-0.12.2 → bcdata-0.12.3}/bcdata/wcs.py +0 -0
- {bcdata-0.12.2 → bcdata-0.12.3}/bcdata/wfs.py +0 -0
- {bcdata-0.12.2 → bcdata-0.12.3}/bcdata.egg-info/dependency_links.txt +0 -0
- {bcdata-0.12.2 → bcdata-0.12.3}/bcdata.egg-info/entry_points.txt +0 -0
- {bcdata-0.12.2 → bcdata-0.12.3}/bcdata.egg-info/not-zip-safe +0 -0
- {bcdata-0.12.2 → bcdata-0.12.3}/bcdata.egg-info/requires.txt +0 -0
- {bcdata-0.12.2 → bcdata-0.12.3}/bcdata.egg-info/top_level.txt +0 -0
- {bcdata-0.12.2 → bcdata-0.12.3}/pyproject.toml +0 -0
- {bcdata-0.12.2 → bcdata-0.12.3}/requirements.txt +0 -0
- {bcdata-0.12.2 → bcdata-0.12.3}/setup.cfg +0 -0
- {bcdata-0.12.2 → bcdata-0.12.3}/setup.py +0 -0
- {bcdata-0.12.2 → bcdata-0.12.3}/tests/test_cli.py +0 -0
- {bcdata-0.12.2 → bcdata-0.12.3}/tests/test_wcs.py +0 -0
- {bcdata-0.12.2 → bcdata-0.12.3}/tests/test_wfs.py +0 -0
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
Changes
|
|
2
2
|
=======
|
|
3
3
|
|
|
4
|
+
0.12.3 (2024-11-12)
|
|
5
|
+
------------------
|
|
6
|
+
- ensure --geometry_type option is used correctly (#198)
|
|
7
|
+
- handle WHSE_ADMIN_BOUNDARIES.ADM_NR_DISTRICTS_SPG/WHSE_ADMIN_BOUNDARIES.ADM_NR_DISTRICTS_SP (#200)
|
|
8
|
+
|
|
4
9
|
0.12.2 (2024-08-15)
|
|
5
10
|
------------------
|
|
6
11
|
- fix error where incorrect schema returned for datasets with multiple resources (#196)
|
|
@@ -62,6 +62,16 @@ def bc2pg( # noqa: C901
|
|
|
62
62
|
if table:
|
|
63
63
|
table_name = table.lower()
|
|
64
64
|
|
|
65
|
+
# take note if geometry type is specified as option
|
|
66
|
+
geometry_type_opt = geometry_type
|
|
67
|
+
|
|
68
|
+
# do not promote to multi if singlepart specified,
|
|
69
|
+
# otherwise default to always promoting to multipart in case mixed types are returned
|
|
70
|
+
if geometry_type_opt and geometry_type_opt.upper() in ["POINT", "LINE", "POLYGON"]:
|
|
71
|
+
promote_to_multi = False
|
|
72
|
+
else:
|
|
73
|
+
promote_to_multi = True
|
|
74
|
+
|
|
65
75
|
# connect to target db
|
|
66
76
|
db = Database(db_url)
|
|
67
77
|
|
|
@@ -152,6 +162,7 @@ def bc2pg( # noqa: C901
|
|
|
152
162
|
table_name,
|
|
153
163
|
table_definition["schema"],
|
|
154
164
|
geometry_type,
|
|
165
|
+
promote_to_multi,
|
|
155
166
|
table_definition["comments"],
|
|
156
167
|
primary_key,
|
|
157
168
|
)
|
|
@@ -187,20 +198,22 @@ def bc2pg( # noqa: C901
|
|
|
187
198
|
# cast to everything multipart because responses can have mixed types
|
|
188
199
|
# geopandas does not have a built in function:
|
|
189
200
|
# https://gis.stackexchange.com/questions/311320/casting-geometry-to-multi-using-geopandas
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
201
|
+
# (but only cast if geometry_type is not specified to be singlepart)
|
|
202
|
+
if promote_to_multi:
|
|
203
|
+
df["geom"] = [
|
|
204
|
+
MultiPoint([feature]) if isinstance(feature, Point) else feature
|
|
205
|
+
for feature in df["geom"]
|
|
206
|
+
]
|
|
207
|
+
df["geom"] = [
|
|
208
|
+
MultiLineString([feature])
|
|
209
|
+
if isinstance(feature, LineString)
|
|
210
|
+
else feature
|
|
211
|
+
for feature in df["geom"]
|
|
212
|
+
]
|
|
213
|
+
df["geom"] = [
|
|
214
|
+
MultiPolygon([feature]) if isinstance(feature, Polygon) else feature
|
|
215
|
+
for feature in df["geom"]
|
|
216
|
+
]
|
|
204
217
|
|
|
205
218
|
# run the load in two parts, one with geoms, one with no geoms
|
|
206
219
|
log.info(f"Writing {dataset} to database as {schema_name}.{table_name}")
|
|
@@ -95,7 +95,7 @@ def get_table_definition(table_name):
|
|
|
95
95
|
# if there are no matching results, let the user know
|
|
96
96
|
if r.json()["result"]["count"] == 0:
|
|
97
97
|
log.warning(
|
|
98
|
-
f"BC Data
|
|
98
|
+
f"BC Data Catalogue API search provides no results for: {table_name}"
|
|
99
99
|
)
|
|
100
100
|
else:
|
|
101
101
|
# iterate through results of search (packages)
|
|
@@ -111,7 +111,16 @@ def get_table_definition(table_name):
|
|
|
111
111
|
):
|
|
112
112
|
# confirm that object name matches table name and schema is present
|
|
113
113
|
if (
|
|
114
|
-
|
|
114
|
+
(
|
|
115
|
+
table_name == resource["object_name"]
|
|
116
|
+
# hack to handle object name / table name mismatch for NR Districts
|
|
117
|
+
or (
|
|
118
|
+
table_name
|
|
119
|
+
== "WHSE_ADMIN_BOUNDARIES.ADM_NR_DISTRICTS_SPG"
|
|
120
|
+
and resource["object_name"]
|
|
121
|
+
== "WHSE_ADMIN_BOUNDARIES.ADM_NR_DISTRICTS_SP"
|
|
122
|
+
)
|
|
123
|
+
)
|
|
115
124
|
and "details" in resource.keys()
|
|
116
125
|
and resource["details"] != ""
|
|
117
126
|
):
|
|
@@ -129,6 +138,8 @@ def get_table_definition(table_name):
|
|
|
129
138
|
|
|
130
139
|
# add primary key if present in bcdata.primary_keys
|
|
131
140
|
if table_name.lower() in bcdata.primary_keys:
|
|
132
|
-
table_definition["primary_key"] = bcdata.primary_keys[
|
|
141
|
+
table_definition["primary_key"] = bcdata.primary_keys[
|
|
142
|
+
table_name.lower()
|
|
143
|
+
].upper()
|
|
133
144
|
|
|
134
145
|
return table_definition
|
|
@@ -134,6 +134,7 @@ class Database(object):
|
|
|
134
134
|
table_name,
|
|
135
135
|
table_details,
|
|
136
136
|
geom_type,
|
|
137
|
+
promote_to_multi=True,
|
|
137
138
|
table_comments=None,
|
|
138
139
|
primary_key=None,
|
|
139
140
|
):
|
|
@@ -181,7 +182,7 @@ class Database(object):
|
|
|
181
182
|
|
|
182
183
|
# make everything multipart
|
|
183
184
|
# (some datasets have mixed singlepart/multipart geometries)
|
|
184
|
-
if geom_type[:5] != "MULTI":
|
|
185
|
+
if promote_to_multi and geom_type[:5] != "MULTI":
|
|
185
186
|
geom_type = "MULTI" + geom_type
|
|
186
187
|
columns.append(Column("geom", Geometry(geom_type, srid=3005)))
|
|
187
188
|
metadata_obj = MetaData()
|
bcdata-0.12.3/tests/t.py
ADDED
|
@@ -19,6 +19,13 @@ STREAMS_TABLE = "whse_basemapping.fwa_stream_networks_sp"
|
|
|
19
19
|
def test_bc2pg():
|
|
20
20
|
bcdata.bc2pg(AIRPORTS_TABLE, DB_URL)
|
|
21
21
|
assert AIRPORTS_TABLE in DB_CONNECTION.tables
|
|
22
|
+
# ensure the data is defaulting to multipart
|
|
23
|
+
r = DB_CONNECTION.query(
|
|
24
|
+
"""
|
|
25
|
+
SELECT ST_geometrytype(geom) from whse_imagery_and_base_maps.gsr_airports_svw limit 1
|
|
26
|
+
"""
|
|
27
|
+
)
|
|
28
|
+
assert r[0][0] == "ST_MultiPoint"
|
|
22
29
|
DB_CONNECTION.execute("drop table " + AIRPORTS_TABLE)
|
|
23
30
|
|
|
24
31
|
|
|
@@ -74,7 +81,12 @@ def test_bc2pg_schema():
|
|
|
74
81
|
|
|
75
82
|
def test_bc2pg_geometry_type():
|
|
76
83
|
bcdata.bc2pg(AIRPORTS_TABLE, DB_URL, count=10, geometry_type="POINT")
|
|
77
|
-
|
|
84
|
+
r = DB_CONNECTION.query(
|
|
85
|
+
"""
|
|
86
|
+
SELECT ST_geometrytype(geom) from whse_imagery_and_base_maps.gsr_airports_svw limit 1
|
|
87
|
+
"""
|
|
88
|
+
)
|
|
89
|
+
assert r[0][0] == "ST_Point"
|
|
78
90
|
DB_CONNECTION.execute("drop table " + AIRPORTS_TABLE)
|
|
79
91
|
|
|
80
92
|
|
|
@@ -75,3 +75,12 @@ def test_get_table_definition_format_oracle_sde():
|
|
|
75
75
|
assert table_definition["description"]
|
|
76
76
|
assert table_definition["comments"]
|
|
77
77
|
assert table_definition["schema"]
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def test_get_table_definition_nr_districts():
|
|
81
|
+
table_definition = bcdc.get_table_definition(
|
|
82
|
+
"WHSE_ADMIN_BOUNDARIES.ADM_NR_DISTRICTS_SPG"
|
|
83
|
+
)
|
|
84
|
+
assert table_definition["description"]
|
|
85
|
+
assert table_definition["comments"]
|
|
86
|
+
assert table_definition["schema"]
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|