为什么 geopandas 在似乎满足条件时抛出断言错误?
Why does geopandas throw an assertion error, when the conditions seems to be met?
我正在尝试发出 WFS 请求并使用此数据创建 GeoDataFrame(来自 geopandas 库)。但是,当我 运行 我的代码时, assert
引发错误:
assert len(bbox) == 4
我不知道是什么导致了这个错误,当我打印 bb
时,我得到一个由四个坐标组成的字符串,用逗号分隔:
print(bb)
173600,443600,174600,444600
type(bb)
str
这是我的代码:
import geopandas as gpd
from requests import Request
# extract only buildings on and around WUR campus
url = 'https://geodata.nationaalgeoregister.nl/bag/wfs'
layer = 'bag:pand' # see wfs.contents
bb = ','.join(map(str, bbox)) # string of bbox needed for the request url
# Specify the parameters for fetching the data
params = dict(service='WFS', version="2.0.0", request='GetFeature',
typeName=layer, outputFormat='text/xml; subtype=gml/3.2',
srsname='urn:ogc:def:crs:EPSG::28992', bbox=bb)
# Parse the URL with parameters
q = Request('GET', url, params=params).prepare().url
# Read data from URL
BuildingsGDF = gpd.read_file(q)
最后一行 (BuildingsGDF = gdp.read_file(q)
) 从断言中抛出错误,即当我尝试将 WFS 请求的结果读入 GeoDataFrame 对象(来自 geopandas 库)时。
我在 Conda 环境中工作,它有以下软件包:
# packages in environment at /home/sytze/miniconda3/envs/geoscripting:
#
# Name Version Build Channel
_libgcc_mutex 0.1 main conda-forge
affine 2.3.0 pypi_0 pypi
alabaster 0.7.12 py37_0
altair 3.2.0 py37_0 conda-forge
asn1crypto 1.2.0 py37_0 conda-forge
astroid 2.3.2 py37_0 conda-forge
attrs 19.3.0 py_0 conda-forge
babel 2.7.0 py_0 conda-forge
backcall 0.1.0 py37_0
blas 1.0 mkl conda-forge
bleach 3.1.0 py37_0
branca 0.3.1 py_0 conda-forge
bzip2 1.0.8 h7b6447c_0
ca-certificates 2019.11.27 0
cairo 1.14.12 h8948797_3
certifi 2019.11.28 py37_0
cffi 1.13.1 py37h2e261b9_0
chardet 3.0.4 py37_1003 conda-forge
click 7.0 py37_0
click-plugins 1.1.1 py_0 conda-forge
cligj 0.5.0 py37_0
cloudpickle 1.2.2 py_0 conda-forge
cryptography 2.8 py37h1ba5d50_0
curl 7.65.3 hbc83047_0
cycler 0.10.0 py37_0
dbus 1.13.12 h746ee38_0
decorator 4.4.1 py_0 conda-forge
defusedxml 0.6.0 py_0 conda-forge
descartes 1.1.0 py_3 conda-forge
docutils 0.15.2 py37_0 conda-forge
entrypoints 0.3 py37_0
expat 2.2.6 he6710b0_0
fiona 1.8.8 pypi_0 pypi
folium 0.10.0 py_0 conda-forge
fontconfig 2.13.0 h9420a91_0
freetype 2.9.1 h8a8886c_1
freexl 1.0.5 h14c3975_0
gdal 2.3.3 py37hbb2a789_0
geographiclib 1.50 py_0 conda-forge
geopandas 0.6.2 py_0 conda-forge
geopy 1.20.0 py_0 conda-forge
geos 3.7.1 he6710b0_0
giflib 5.1.4 h14c3975_1
glib 2.56.2 hd408876_0
gmp 6.1.2 h6c8ec71_1
gst-plugins-base 1.14.0 hbbd80ab_1
gstreamer 1.14.0 hb453b48_1
hdf4 4.2.13 h3ca952b_2
hdf5 1.10.4 hb1b8bf9_0
icu 58.2 h9c2bf20_1
idna 2.8 py37_0
imagesize 1.1.0 py37_0
importlib_metadata 0.23 py37_0 conda-forge
intel-openmp 2019.4 243
ipykernel 5.1.3 py37h39e3cac_0
ipython 7.9.0 py37h39e3cac_0
ipython_genutils 0.2.0 py37_0
ipywidgets 7.5.1 py_0 conda-forge
isort 4.3.21 py37_0 conda-forge
jedi 0.15.1 py37_0 conda-forge
jeepney 0.4.1 py_0 conda-forge
jinja2 2.10.3 py_0 conda-forge
jpeg 9b h024ee3a_2
json-c 0.13.1 h1bed415_0
jsonschema 3.1.1 py37_0 conda-forge
jupyter 1.0.0 py37_7
jupyter_client 5.3.4 py37_0 conda-forge
jupyter_console 6.0.0 py37_0
jupyter_core 4.6.0 py37_0
kealib 1.4.7 hd0c454d_6
keyring 18.0.0 py37_0 conda-forge
kiwisolver 1.1.0 py37he6710b0_0
krb5 1.16.1 h173b8e3_7
lazy-object-proxy 1.4.2 py37h7b6447c_0
libboost 1.67.0 h46d08c1_4
libcurl 7.65.3 h20c2e04_0
libdap4 3.19.1 h6ec2957_0
libedit 3.1.20181209 hc058e9b_0
libffi 3.2.1 hd88cf55_4
libgcc-ng 9.1.0 hdf63c60_0
libgdal 2.3.3 h2e7e64b_0
libgfortran-ng 7.3.0 hdf63c60_0
libkml 1.3.0 h590aaf7_4
libnetcdf 4.6.1 h11d0813_2
libpng 1.6.37 hbc83047_0
libpq 11.2 h20c2e04_0
libsodium 1.0.16 h1bed415_0
libspatialindex 1.8.5 h20b78c2_2
libspatialite 4.3.0a hb08deb6_19
libssh2 1.8.2 h1ba5d50_0
libstdcxx-ng 9.1.0 hdf63c60_0
libtiff 4.0.10 h2733197_2
libuuid 1.0.3 h1bed415_2
libxcb 1.13 h1bed415_1
libxml2 2.9.9 hea5a465_1
libxslt 1.1.33 h7d1a2b0_0
lxml 4.4.1 py37hefd8a0e_0
mapclassify 2.0.1 py_0 conda-forge
markupsafe 1.1.1 py37h7b6447c_0
matplotlib 3.1.1 py37h5429711_0
mccabe 0.6.1 py37_1
mistune 0.8.4 py37h7b6447c_0
mkl 2019.4 243
mkl-service 2.3.0 py37he904b0f_0
mkl_fft 1.0.14 py37ha843d7b_0
mkl_random 1.1.0 py37hd6b4f25_0
more-itertools 7.2.0 py37_0
munch 2.3.2 py37_0
nbconvert 5.6.0 py37_1 conda-forge
nbformat 4.4.0 py37_0
ncurses 6.1 he6710b0_1
networkx 2.4 py_0 conda-forge
notebook 6.0.1 py37_0 conda-forge
numpy 1.17.2 py37haad9e8e_0
numpy-base 1.17.2 py37hde5b4d6_0
numpydoc 0.9.1 py_0 conda-forge
openjpeg 2.3.0 h05c96fa_1
openssl 1.1.1d h7b6447c_3
osmnx 0.10 py_1 conda-forge
owslib 0.18.0 py_0 conda-forge
packaging 19.2 py_0 conda-forge
pandas 0.25.2 py37he6710b0_0
pandoc 2.2.3.2 0
pandocfilters 1.4.2 py37_1
parso 0.5.1 py_0 conda-forge
patsy 0.5.1 py37_0
pcre 8.43 he6710b0_0
pexpect 4.7.0 py37_0 conda-forge
pickleshare 0.7.5 py37_0
pip 19.3.1 py37_0 conda-forge
pixman 0.38.0 h7b6447c_0
pluggy 0.13.1 py37_0
poppler 0.65.0 h581218d_1
poppler-data 0.4.9 0 conda-forge
progressbar2 3.37.1 py37_0
proj4 5.2.0 he6710b0_1
prometheus_client 0.7.1 py_0 conda-forge
prompt_toolkit 2.0.10 py_0 conda-forge
psutil 5.6.3 py37h7b6447c_0
psycopg2 2.8.3 py37h1ba5d50_0
ptyprocess 0.6.0 py37_0 conda-forge
py 1.8.1 py_0
pycodestyle 2.5.0 py37_0
pycparser 2.19 py37_0
pyflakes 2.1.1 py37_0
pygments 2.4.2 py_0 conda-forge
pylint 2.4.3 py37_0 conda-forge
pyopenssl 19.0.0 py37_0 conda-forge
pyparsing 2.4.2 py_0 conda-forge
pyproj 1.9.6 py37h14380d9_0
pyqt 5.9.2 py37h05f1152_2
pyrsistent 0.15.4 py37h7b6447c_0
pysocks 1.7.1 py37_0 conda-forge
pytest 5.3.2 py37_0
pytest-runner 5.2 py_0
python 3.7.5 h0371630_0
python-dateutil 2.8.0 py37_0
python-utils 2.3.0 py37_0
pytz 2019.3 py_0 conda-forge
pyzmq 18.1.0 py37he6710b0_0
qt 5.9.7 h5867ecd_1
qtawesome 0.6.0 py_0 conda-forge
qtconsole 4.5.5 py_0 conda-forge
qtpy 1.9.0 py_0 conda-forge
rasterio 1.1.1 pypi_0 pypi
rasterstats 0.13.1 pypi_0 pypi
readline 7.0 h7b6447c_5
requests 2.22.0 py37_0 conda-forge
rope 0.14.0 py_0 conda-forge
rtree 0.8.3 py37_0
scipy 1.3.1 py37h7c811a0_0
seaborn 0.9.0 py37_0
secretstorage 3.1.1 py37_0 conda-forge
send2trash 1.5.0 py37_0
setuptools 41.6.0 py37_0 conda-forge
shapely 1.6.4 py37h86c5351_0
simplejson 3.17.0 pypi_0 pypi
sip 4.19.8 py37hf484d3e_0
six 1.12.0 py37_0
snowballstemmer 2.0.0 py_0 conda-forge
snuggs 1.4.7 pypi_0 pypi
sphinx 2.2.1 py_0 conda-forge
sphinxcontrib-applehelp 1.0.1 py_0 conda-forge
sphinxcontrib-devhelp 1.0.1 py_0 conda-forge
sphinxcontrib-htmlhelp 1.0.2 py_0 conda-forge
sphinxcontrib-jsmath 1.0.1 py_0 conda-forge
sphinxcontrib-qthelp 1.0.2 py_0 conda-forge
sphinxcontrib-serializinghtml 1.1.3 py_0 conda-forge
spyder 3.3.6 py37_0 conda-forge
spyder-kernels 0.5.2 py37_0 conda-forge
sqlalchemy 1.3.10 py37h7b6447c_0
sqlite 3.30.1 h7b6447c_0
statsmodels 0.10.1 py37hdd07704_0
terminado 0.8.2 py37_0 conda-forge
testpath 0.4.2 py37_0
tk 8.6.8 hbc83047_0
toolz 0.10.0 py_0 conda-forge
tornado 6.0.3 py37h7b6447c_0
traitlets 4.3.3 py37_0 conda-forge
urllib3 1.24.2 py37_0 conda-forge
vincent 0.4.4 py_1 conda-forge
wcwidth 0.1.7 py37_0
webencodings 0.5.1 py37_1
wheel 0.33.6 py37_0 conda-forge
widgetsnbextension 3.5.1 py37_0 conda-forge
wrapt 1.11.2 py37h7b6447c_0
wurlitzer 1.0.3 py37_0 conda-forge
xerces-c 3.2.2 h780794e_0
xz 5.2.4 h14c3975_4
zeromq 4.3.1 he6710b0_3
zipp 0.6.0 py_0 conda-forge
zlib 1.2.11 h7b6447c_3
zstd 1.3.7 h0b5b093_0
你没有包含四个元素的列表,你有一个字符串。
要解决此问题,请拆分字符串以在断言之前创建一个列表,例如 bb = bb.split(',')
。
我正在尝试发出 WFS 请求并使用此数据创建 GeoDataFrame(来自 geopandas 库)。但是,当我 运行 我的代码时, assert
引发错误:
assert len(bbox) == 4
我不知道是什么导致了这个错误,当我打印 bb
时,我得到一个由四个坐标组成的字符串,用逗号分隔:
print(bb)
173600,443600,174600,444600
type(bb)
str
这是我的代码:
import geopandas as gpd
from requests import Request
# extract only buildings on and around WUR campus
url = 'https://geodata.nationaalgeoregister.nl/bag/wfs'
layer = 'bag:pand' # see wfs.contents
bb = ','.join(map(str, bbox)) # string of bbox needed for the request url
# Specify the parameters for fetching the data
params = dict(service='WFS', version="2.0.0", request='GetFeature',
typeName=layer, outputFormat='text/xml; subtype=gml/3.2',
srsname='urn:ogc:def:crs:EPSG::28992', bbox=bb)
# Parse the URL with parameters
q = Request('GET', url, params=params).prepare().url
# Read data from URL
BuildingsGDF = gpd.read_file(q)
最后一行 (BuildingsGDF = gdp.read_file(q)
) 从断言中抛出错误,即当我尝试将 WFS 请求的结果读入 GeoDataFrame 对象(来自 geopandas 库)时。
我在 Conda 环境中工作,它有以下软件包:
# packages in environment at /home/sytze/miniconda3/envs/geoscripting:
#
# Name Version Build Channel
_libgcc_mutex 0.1 main conda-forge
affine 2.3.0 pypi_0 pypi
alabaster 0.7.12 py37_0
altair 3.2.0 py37_0 conda-forge
asn1crypto 1.2.0 py37_0 conda-forge
astroid 2.3.2 py37_0 conda-forge
attrs 19.3.0 py_0 conda-forge
babel 2.7.0 py_0 conda-forge
backcall 0.1.0 py37_0
blas 1.0 mkl conda-forge
bleach 3.1.0 py37_0
branca 0.3.1 py_0 conda-forge
bzip2 1.0.8 h7b6447c_0
ca-certificates 2019.11.27 0
cairo 1.14.12 h8948797_3
certifi 2019.11.28 py37_0
cffi 1.13.1 py37h2e261b9_0
chardet 3.0.4 py37_1003 conda-forge
click 7.0 py37_0
click-plugins 1.1.1 py_0 conda-forge
cligj 0.5.0 py37_0
cloudpickle 1.2.2 py_0 conda-forge
cryptography 2.8 py37h1ba5d50_0
curl 7.65.3 hbc83047_0
cycler 0.10.0 py37_0
dbus 1.13.12 h746ee38_0
decorator 4.4.1 py_0 conda-forge
defusedxml 0.6.0 py_0 conda-forge
descartes 1.1.0 py_3 conda-forge
docutils 0.15.2 py37_0 conda-forge
entrypoints 0.3 py37_0
expat 2.2.6 he6710b0_0
fiona 1.8.8 pypi_0 pypi
folium 0.10.0 py_0 conda-forge
fontconfig 2.13.0 h9420a91_0
freetype 2.9.1 h8a8886c_1
freexl 1.0.5 h14c3975_0
gdal 2.3.3 py37hbb2a789_0
geographiclib 1.50 py_0 conda-forge
geopandas 0.6.2 py_0 conda-forge
geopy 1.20.0 py_0 conda-forge
geos 3.7.1 he6710b0_0
giflib 5.1.4 h14c3975_1
glib 2.56.2 hd408876_0
gmp 6.1.2 h6c8ec71_1
gst-plugins-base 1.14.0 hbbd80ab_1
gstreamer 1.14.0 hb453b48_1
hdf4 4.2.13 h3ca952b_2
hdf5 1.10.4 hb1b8bf9_0
icu 58.2 h9c2bf20_1
idna 2.8 py37_0
imagesize 1.1.0 py37_0
importlib_metadata 0.23 py37_0 conda-forge
intel-openmp 2019.4 243
ipykernel 5.1.3 py37h39e3cac_0
ipython 7.9.0 py37h39e3cac_0
ipython_genutils 0.2.0 py37_0
ipywidgets 7.5.1 py_0 conda-forge
isort 4.3.21 py37_0 conda-forge
jedi 0.15.1 py37_0 conda-forge
jeepney 0.4.1 py_0 conda-forge
jinja2 2.10.3 py_0 conda-forge
jpeg 9b h024ee3a_2
json-c 0.13.1 h1bed415_0
jsonschema 3.1.1 py37_0 conda-forge
jupyter 1.0.0 py37_7
jupyter_client 5.3.4 py37_0 conda-forge
jupyter_console 6.0.0 py37_0
jupyter_core 4.6.0 py37_0
kealib 1.4.7 hd0c454d_6
keyring 18.0.0 py37_0 conda-forge
kiwisolver 1.1.0 py37he6710b0_0
krb5 1.16.1 h173b8e3_7
lazy-object-proxy 1.4.2 py37h7b6447c_0
libboost 1.67.0 h46d08c1_4
libcurl 7.65.3 h20c2e04_0
libdap4 3.19.1 h6ec2957_0
libedit 3.1.20181209 hc058e9b_0
libffi 3.2.1 hd88cf55_4
libgcc-ng 9.1.0 hdf63c60_0
libgdal 2.3.3 h2e7e64b_0
libgfortran-ng 7.3.0 hdf63c60_0
libkml 1.3.0 h590aaf7_4
libnetcdf 4.6.1 h11d0813_2
libpng 1.6.37 hbc83047_0
libpq 11.2 h20c2e04_0
libsodium 1.0.16 h1bed415_0
libspatialindex 1.8.5 h20b78c2_2
libspatialite 4.3.0a hb08deb6_19
libssh2 1.8.2 h1ba5d50_0
libstdcxx-ng 9.1.0 hdf63c60_0
libtiff 4.0.10 h2733197_2
libuuid 1.0.3 h1bed415_2
libxcb 1.13 h1bed415_1
libxml2 2.9.9 hea5a465_1
libxslt 1.1.33 h7d1a2b0_0
lxml 4.4.1 py37hefd8a0e_0
mapclassify 2.0.1 py_0 conda-forge
markupsafe 1.1.1 py37h7b6447c_0
matplotlib 3.1.1 py37h5429711_0
mccabe 0.6.1 py37_1
mistune 0.8.4 py37h7b6447c_0
mkl 2019.4 243
mkl-service 2.3.0 py37he904b0f_0
mkl_fft 1.0.14 py37ha843d7b_0
mkl_random 1.1.0 py37hd6b4f25_0
more-itertools 7.2.0 py37_0
munch 2.3.2 py37_0
nbconvert 5.6.0 py37_1 conda-forge
nbformat 4.4.0 py37_0
ncurses 6.1 he6710b0_1
networkx 2.4 py_0 conda-forge
notebook 6.0.1 py37_0 conda-forge
numpy 1.17.2 py37haad9e8e_0
numpy-base 1.17.2 py37hde5b4d6_0
numpydoc 0.9.1 py_0 conda-forge
openjpeg 2.3.0 h05c96fa_1
openssl 1.1.1d h7b6447c_3
osmnx 0.10 py_1 conda-forge
owslib 0.18.0 py_0 conda-forge
packaging 19.2 py_0 conda-forge
pandas 0.25.2 py37he6710b0_0
pandoc 2.2.3.2 0
pandocfilters 1.4.2 py37_1
parso 0.5.1 py_0 conda-forge
patsy 0.5.1 py37_0
pcre 8.43 he6710b0_0
pexpect 4.7.0 py37_0 conda-forge
pickleshare 0.7.5 py37_0
pip 19.3.1 py37_0 conda-forge
pixman 0.38.0 h7b6447c_0
pluggy 0.13.1 py37_0
poppler 0.65.0 h581218d_1
poppler-data 0.4.9 0 conda-forge
progressbar2 3.37.1 py37_0
proj4 5.2.0 he6710b0_1
prometheus_client 0.7.1 py_0 conda-forge
prompt_toolkit 2.0.10 py_0 conda-forge
psutil 5.6.3 py37h7b6447c_0
psycopg2 2.8.3 py37h1ba5d50_0
ptyprocess 0.6.0 py37_0 conda-forge
py 1.8.1 py_0
pycodestyle 2.5.0 py37_0
pycparser 2.19 py37_0
pyflakes 2.1.1 py37_0
pygments 2.4.2 py_0 conda-forge
pylint 2.4.3 py37_0 conda-forge
pyopenssl 19.0.0 py37_0 conda-forge
pyparsing 2.4.2 py_0 conda-forge
pyproj 1.9.6 py37h14380d9_0
pyqt 5.9.2 py37h05f1152_2
pyrsistent 0.15.4 py37h7b6447c_0
pysocks 1.7.1 py37_0 conda-forge
pytest 5.3.2 py37_0
pytest-runner 5.2 py_0
python 3.7.5 h0371630_0
python-dateutil 2.8.0 py37_0
python-utils 2.3.0 py37_0
pytz 2019.3 py_0 conda-forge
pyzmq 18.1.0 py37he6710b0_0
qt 5.9.7 h5867ecd_1
qtawesome 0.6.0 py_0 conda-forge
qtconsole 4.5.5 py_0 conda-forge
qtpy 1.9.0 py_0 conda-forge
rasterio 1.1.1 pypi_0 pypi
rasterstats 0.13.1 pypi_0 pypi
readline 7.0 h7b6447c_5
requests 2.22.0 py37_0 conda-forge
rope 0.14.0 py_0 conda-forge
rtree 0.8.3 py37_0
scipy 1.3.1 py37h7c811a0_0
seaborn 0.9.0 py37_0
secretstorage 3.1.1 py37_0 conda-forge
send2trash 1.5.0 py37_0
setuptools 41.6.0 py37_0 conda-forge
shapely 1.6.4 py37h86c5351_0
simplejson 3.17.0 pypi_0 pypi
sip 4.19.8 py37hf484d3e_0
six 1.12.0 py37_0
snowballstemmer 2.0.0 py_0 conda-forge
snuggs 1.4.7 pypi_0 pypi
sphinx 2.2.1 py_0 conda-forge
sphinxcontrib-applehelp 1.0.1 py_0 conda-forge
sphinxcontrib-devhelp 1.0.1 py_0 conda-forge
sphinxcontrib-htmlhelp 1.0.2 py_0 conda-forge
sphinxcontrib-jsmath 1.0.1 py_0 conda-forge
sphinxcontrib-qthelp 1.0.2 py_0 conda-forge
sphinxcontrib-serializinghtml 1.1.3 py_0 conda-forge
spyder 3.3.6 py37_0 conda-forge
spyder-kernels 0.5.2 py37_0 conda-forge
sqlalchemy 1.3.10 py37h7b6447c_0
sqlite 3.30.1 h7b6447c_0
statsmodels 0.10.1 py37hdd07704_0
terminado 0.8.2 py37_0 conda-forge
testpath 0.4.2 py37_0
tk 8.6.8 hbc83047_0
toolz 0.10.0 py_0 conda-forge
tornado 6.0.3 py37h7b6447c_0
traitlets 4.3.3 py37_0 conda-forge
urllib3 1.24.2 py37_0 conda-forge
vincent 0.4.4 py_1 conda-forge
wcwidth 0.1.7 py37_0
webencodings 0.5.1 py37_1
wheel 0.33.6 py37_0 conda-forge
widgetsnbextension 3.5.1 py37_0 conda-forge
wrapt 1.11.2 py37h7b6447c_0
wurlitzer 1.0.3 py37_0 conda-forge
xerces-c 3.2.2 h780794e_0
xz 5.2.4 h14c3975_4
zeromq 4.3.1 he6710b0_3
zipp 0.6.0 py_0 conda-forge
zlib 1.2.11 h7b6447c_3
zstd 1.3.7 h0b5b093_0
你没有包含四个元素的列表,你有一个字符串。
要解决此问题,请拆分字符串以在断言之前创建一个列表,例如 bb = bb.split(',')
。