I have a code where I would like to be able to use both GeoPandas and PyQGIS. However, it seems that including GeoPandas is causing issues in the output of PyQGIS.
import geopandas import os import sys # Add to Python Path sys.path.append('/Applications/QGis.app/Contents/Resources/python/') sys.path.append('/Applications/QGis.app/Contents/Resources/python/plugins') # Initialize QGIS from qgis.core import * from qgis.gui import * qgs = QgsApplication(, False) QgsApplication.setPrefixPath("/Applications/QGIS.app/Contents/MacOS", True) qgs.initQgis() # Setup Processing from PyQt4 import QtCore, QtGui import processing # create dummy iface class DummyInterface(object): def __init__(self): self.destCrs = None def __getattr__(self, *args, **kwargs): def dummy(*args, **kwargs): return DummyInterface() return dummy def __iter__(self): return self def next(self): raise StopIteration def layers(self): # simulate iface.legendInterface().layers() return QgsMapLayerRegistry.instance().mapLayers().values() iface = DummyInterface() # initalise processing plugin with dummy iface object plugin = processing.classFactory(iface) # Set paths os.chdir('path/to/example') districts = 'School Districts/geo_export_cdfc9016-ca65-4c45-8423-7acc709a42a2.shp' blocks = '2010 Census Blocks/geo_export_ae8a0155-ccdc-4a7b-a42e-6707282035cc.shp' district32 = 'School Districts/district32.shp' outfile = 'clipped_blocks.shp' # Select school district 32 and save as new file districts = QgsVectorLayer(districts,'districts',"ogr") query = '"school_dis"=32' selection = districts.getFeatures(QgsFeatureRequest().setFilterExpression(query)) districts.setSelectedFeatures([k.id() for k in selection]) _writer = QgsVectorFileWriter.writeAsVectorFormat(districts,district32,"utf-8",None,"ESRI Shapefile",True) # Clip blocks with school district 32 processing.runalg("qgis:clip",blocks,district32,outfile) qgs.exitQgis()
It seems that simply by importing GeoPandas, it messes up the QGIS processing algorithms. This keeps happening in my code. No errors are thrown, and it's sort of random which processes work and which ones don't. I've had issues with "qgis:clip" and "qgis:dissolve", but other ones like "qgis:deleteduplicategeometries" and "grass7:v.clean" seem to work fine.
Is there an issue with the way I've setup the PyQGIS processing or are these two just fundamentally incompatible? Ideally I'd like to be able to use them in the same code as sometimes it's easier to do a task in GeoPandas than PyQGIS and vice versa.
I am running this on a Mac (OS ver. 10.13) with QGIS 2.18.15, Python 2.17.14 and GeoPandas 0.3.0.