Bug report #18199

QGIS dev version: error when using geopandas and osmnx

Added by Maxime Dufour over 2 years ago. Updated over 2 years ago.

Status:Open
Priority:Normal
Assignee:-
Category:Python bindings / sipify
Affected QGIS version:3.0.0 Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:26090

Description

I've installed several external Python modules in the QGIS Python environement (I use the last nightly build of QGIS dev) including geopandas and osmnx.
My code is working properly from the windows command line (using QGIS version of python 3.6) but when using the QSGIS python command line I keep having an error that I can't understand. Here is a simplified version of it using geopandas and osmnx:

Console Python
Utilisez iface pour accéder à l'interface de l'API QGIS ou tapez help(iface) pour plus d'informations

import matplotlib
matplotlib.use('agg') # just to avoid osmnx to change matplotlib backend to tkinter which seems touchy in QGIS Python
import matplotlib.pyplot as plt
import geopandas as gpd
polygonShape = gpd.read_file("D:\\software\\OSGeo4W64\\apps\\qgis-dev\\python\\plugins\\dhcoptimzier\\data\\antwerp.shp") # I joined the file which is very simple

print(polygonShape)
district geometry
0 antwerp POLYGON ((4.394025849609361 51.21877037018072,...

import osmnx as ox
graph = ox.graph_from_polygon(polygonShape['geometry'][0], network_type='all')

Traceback (most recent call last):
File "D:\software\OSGeo4W64\apps\Python36\lib\code.py", line 91, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "D:\software\OSGeo4W64\apps\Python36\lib\site-packages\osmnx\core.py", line 1680, in graph_from_polygon
G_buffered = truncate_graph_polygon(G_buffered, polygon_buffered, retain_all=True, truncate_by_edge=truncate_by_edge)
File "D:\software\OSGeo4W64\apps\Python36\lib\site-packages\osmnx\core.py", line 1125, in truncate_graph_polygon
points_within_geometry = intersect_index_quadrats(gdf_nodes, polygon, quadrat_width=quadrat_width, min_num=min_num, buffer_amount=buffer_amount)
File "D:\software\OSGeo4W64\apps\Python36\lib\site-packages\osmnx\core.py", line 1043, in intersect_index_quadrats
multipoly = quadrat_cut_geometry(geometry, quadrat_width=quadrat_width, buffer_amount=buffer_amount, min_num=min_num)
File "D:\software\OSGeo4W64\apps\Python36\lib\site-packages\osmnx\core.py", line 1007, in quadrat_cut_geometry
lines_buffered = [line.buffer(buffer_size) for line in lines]
File "D:\software\OSGeo4W64\apps\Python36\lib\site-packages\osmnx\core.py", line 1007, in <listcomp>
lines_buffered = [line.buffer(buffer_size) for line in lines]
File "D:\software\OSGeo4W64\apps\Python36\lib\site-packages\shapely\geometry\base.py", line 584, in buffer
return geom_factory(self.impl['buffer'](self, distance, res))
File "D:\software\OSGeo4W64\apps\Python36\lib\site-packages\shapely\topology.py", line 78, in call
return self.fn(this._geom, *args)
OSError: exception: access violation writing 0x00007FF9A3E58A30

I don't get where the memory access violation comes from (I've tried to run as administrator as well).
Here is my pip freeze for my QGIS Python:
alabaster==0.7.10
Babel==2.5.3
certifi==2018.1.18
chardet==3.0.4
click==6.7
click-plugins==1.0.3
cligj==0.4.0
colorama==0.3.9
cycler==0.10.0
decorator==4.2.1
descartes==1.1.0
docutils==0.14
Fiona==1.7.11
future==0.16.0
GDAL==2.2.2
geopandas==0.3.0
geopy==1.11.0
httplib2==0.10.2
idna==2.6
imagesize==1.0.0
ipython-genutils==0.2.0
Jinja2==2.9.4
joblib==0.11
jsonschema==2.6.0
jupyter-core==4.4.0
MarkupSafe==0.23
matplotlib==2.1.1
mock==2.0.0
munch==2.2.0
nbformat==4.4.0
networkx==2.1
nose2==0.6.5
numpy==1.14.1
osmnx==0.6
OWSLib==0.14.0
packaging==16.8
pandas==0.22.0
pb-tool==3.0.6
pbr==1.10.0
pipdeptree==0.10.1
plotly==2.4.1
psycopg2==2.7.3.2
PuLP==1.6.8
Pygments==2.2.0
pyparsing==2.2.0
pyproj==1.9.5.1
python-dateutil==2.6.1
pytz==2018.3
PyYAML==3.12
requests==2.18.4
Rtree==0.8.3
Shapely==1.6.4.post1
six==1.11.0
snowballstemmer==1.2.1
Sphinx==1.7.0
sphinxcontrib-websupport==1.0.1
traitlets==4.3.2
urllib3==1.22

Thanks in advance !

Maxime

data.7z - shapefile imported by geopandas (623 Bytes) Maxime Dufour, 2018-02-23 06:25 PM

History

#1 Updated by Nyall Dawson over 2 years ago

This was likely fixed with a recent change in osgeo4w python package. Please retest.

#2 Updated by Giovanni Manghi over 2 years ago

  • Regression? set to No
  • Crashes QGIS or corrupts data set to No
  • Affected QGIS version set to 3.0.0
  • Status changed from Open to Feedback
  • Category changed from Any to Python bindings / sipify
  • Project changed from QGIS Redmine (QGIS bug tracker) to QGIS Application
  • Easy fix? set to No

#3 Updated by Maxime Dufour over 2 years ago

Thank you a lot for your answers!
I was using the last OSGEO4w nightly build on Friday, what more up to date version should I use ?

Kind regards,
Maxime

#4 Updated by Nyall Dawson over 2 years ago

Try the final 3.0 release

#5 Updated by Maxime Dufour over 2 years ago

I just tried with QGIS 3.0 and I still have the issue. I read the shapefile using geopandas and then try to use it to import openstreetmap information using osmnx as stated above.
When calling osmnx directly to retrieve data from a city name and not from a shapefile, the data retrieval works. I think that the issue is with geopandas (which works outside of QGIS).

#6 Updated by Maxime Dufour over 2 years ago

Hi,

Do you have any insight on the cause or a possible workaround for me ?
Even a system call would be good enough for me while waiting for a fix it but it doesn't seem to be working either.

Thanks in advance,

Maxime

#7 Updated by Maxime Dufour over 2 years ago

  • Status changed from Feedback to Open

Also available in: Atom PDF