From abee8c74f603693a405dfad6d2e986ff66ecc4fe Mon Sep 17 00:00:00 2001 From: Simon Norris Date: Mon, 26 Sep 2022 14:37:02 -0700 Subject: [PATCH] V0.7.2 (#115) * bump version * fix #114 --- CHANGES.txt | 4 ++++ bcdata/__init__.py | 2 +- bcdata/wfs.py | 33 ++++++++++++++++++++++++++------- tests/test_bcdata.py | 6 ++++++ 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 058c18c..5692689 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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 diff --git a/bcdata/__init__.py b/bcdata/__init__.py index 9cf4c56..50f9bb8 100644 --- a/bcdata/__init__.py +++ b/bcdata/__init__.py @@ -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" diff --git a/bcdata/wfs.py b/bcdata/wfs.py index 85a8492..7034890 100644 --- a/bcdata/wfs.py +++ b/bcdata/wfs.py @@ -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) @@ -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 diff --git a/tests/test_bcdata.py b/tests/test_bcdata.py index 5722c1f..6349605 100644 --- a/tests/test_bcdata.py +++ b/tests/test_bcdata.py @@ -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(): @@ -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