Using information from here, I am trying to load a result of a SQL Python selection into a Geopandas geodataframe. I know pyspatialite is not longer maintained, so have tried using the dbapi2 module from sqlite3. When I run the line:

df = gpd.GeoDataFrame.from_postgis("SELECT name, Hex(ST_AsBinary(geometry, 27700)) as geom FROM table;", conn, geom_col='geom')

I get an error: no such function: ST_AsBinary. I thought that that was a basic Python command. Am I missing something?

  • Probably it is not a Python problem. It looks like your PostGIS doesn't recognize the ST_AsBinary function. What version of PostGIS do you use? – Michel Stuyts Jun 6 '19 at 13:40
  • 1
    For some reason the spatialite extension has not been loaded successfully and therefore you miss ST_AsBinary and other spatialite functions gaia-gis.it/stored-procs-win-test/spatialite-sql-latest.html. – user30184 Jun 6 '19 at 13:45
  • I ran c.execute("SELECT InitSpatialMetaData(1);") and then it worked – Perfalcon Jun 6 '19 at 16:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.