0

I am struggeling with the following issue:

While running my Python3.8.10 interpreter with Jupyter Notebook (setting A), I can successfully connect to my Postgis database and query the data while writing it to geopandas.GeoDataFrame. For that, I use the following snippet:

from sqlalchemy import create_engine
import geopandas as gpd

print(gpd.__version__)
>>> 0.12.2


# Connection settings
db_connection_url = "postgresql://%s:%s@%s:%s/%s"%(settings.database.user, settings.database.pw, 
                                                   settings.database.url, str(settings.database.port), 
                                                   settings.database.table)

# Get data
data = gpd.GeoDataFrame.from_postgis(sql="select * from curvature", con=create_engine(db_connection_url), geom_col='geometry',
crs="EPSG:25833")

However, when I switch from the Notebook implementation to the native Python file (setting B), I get the following error message:

File "C:\Users\ABC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\shapely\io.py", line 325, in from_wkb return lib.from_wkb(geometry, invalid_handler, **kwargs) shapely.errors.GEOSException: ParseException: Unknown WKB type 41

which cames from:

File "C:\Users\ABC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\geopandas\io\sql.py", line 87, in _df_to_geodf df[geom_col] = geoms = geoms.apply(load_geom)

I ensured that I use the same packages by comparingos.path. It points in both settings to:

'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\\lib\\stat.py'

To doublecheck my connection, I tried to query the data with the connection and store it in an pandas.DataFrame in setting B:

import pandas as pd

df = pd.read_sql_query('''SELECT * from curvature''', create_engine(db_connection_url))

with print(df.head(2)) I can access my data as expected:

   geometry                    id, name, type radius curvature
0  LINESTRING((47.XX 15.XX    130.0    130.0  XXX [0.0, ...  [inf, ...
1  LINESTRING((47.XX XX...  46624.0  46624.0  XXX [0.0, ...  [inf, ...

Has anyone observed the same behavior and has already solved this problem, as I can not find anything specific about WKB type 41.

Best Daniel

  • I would highly suspect an installation issue, maybe it is the right time for you to learn how to work with virtual environments which are typically a way to avoid such problems. – R_D Jun 06 '23 at 12:55
  • Thank you very much for your input @R_D. I tested setting B with a completely new and clean conda environment. I get the same error in setting B: shapely.errors.GEOSException: ParseException: Unknown WKB type 41. The same behavior holds also for the GeoPandas.read_postgis() function. The notebook-implemenbtation also works pretty fine with the new environment. – Kabrüggen Jun 07 '23 at 05:35
  • If you are certain both environments are identical, then I don't know. There are leads over the internet as to where should your WKB error comes from (omitting the "41"), but I have no clue why this would work in one case and not in the other. – R_D Jun 08 '23 at 05:28

0 Answers0