Skip to content

Commit

Permalink
V0.7.2 (#115)
Browse files Browse the repository at this point in the history
* bump version

* fix #114
  • Loading branch information
smnorris authored Sep 26, 2022
1 parent 5142e61 commit abee8c7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 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.7.2 (2022-09-26)
------------------
- bc2pg - handle geometries with Z values (#114)

0.7.1 (2022-09-26)
------------------
- bc2pg - add missing --sortby option
Expand Down
2 changes: 1 addition & 1 deletion bcdata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from .wcs import get_dem


__version__ = "0.7.1"
__version__ = "0.7.2"

BCDC_API_URL = "https://catalogue.data.gov.bc.ca/api/3/action/"
WFS_URL = "https://openmaps.gov.bc.ca/geo/pub/wfs"
Expand Down
33 changes: 26 additions & 7 deletions bcdata/wfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,9 @@ def get_types(dataset, count=10):
table = validate_name(dataset)
log.info("Getting feature geometry type")
# get features and find distinct types where geom is not empty
features = [f for f in get_features(table, count=count)]
geom_types = list(
set(
[
f["geometry"]["type"].upper()
for f in get_features(table, count=count)
if f["geometry"]
]
)
set([f["geometry"]["type"].upper() for f in features if f["geometry"]])
)
if len(geom_types) > 1:
typestring = ",".join(geom_types)
Expand All @@ -300,4 +295,28 @@ def get_types(dataset, count=10):
"MULTIPOLYGON",
):
raise ValueError("Geometry type {geomtype} is not supported")
# if Z coordinates are supplied, modify the type accordingly
# (presuming that all )
# (points and lines only, presumably there are no 3d polygon features)
for i in range(len(geom_types)):
if (
geom_types[i] == "POINT"
and len(features[0]["geometry"]["coordinates"]) == 3
):
geom_types[i] = "POINTZ"
if (
geom_types[i] == "MULTIPOINT"
and len(features[0]["geometry"]["coordinates"][0]) == 3
):
geom_types[i] = "POINTZ"
if (
geom_types[i] == "LINESTRING"
and len(features[0]["geometry"]["coordinates"][0]) == 3
):
geom_types[i] = "LINESTRINGZ"
if (
geom_types[i] == "MULTILINESTRING"
and len(features[0]["geometry"]["coordinates"][0][0]) == 3
):
geom_types[i] = "MULTILINESTRINGZ"
return geom_types
6 changes: 6 additions & 0 deletions tests/test_bcdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
BEC_KEY = "biogeoclimatic-ecosystem-classification-bec-map"
ASSESSMENTS_TABLE = "whse_fish.pscis_assessment_svw"
GLACIERS_TABLE = "whse_basemapping.fwa_glaciers_poly"
STREAMS_TABLE = "whse_basemapping.fwa_stream_networks_sp"


def test_validate_table_lowercase():
Expand Down Expand Up @@ -69,6 +70,11 @@ def test_get_mixed_types():
assert len(data) == 2


def test_get_types_z():
data = bcdata.get_types(STREAMS_TABLE)
assert data[0] == "LINESTRINGZ"


def test_get_features():
data = [f for f in bcdata.get_features(AIRPORTS_TABLE)]
assert len(data) == 455
Expand Down

0 comments on commit abee8c7

Please sign in to comment.