I am new to QGIS and I am currently learning pyqgis. My problem is I tried to create a custom plugin to join csv and shapefile with 20,000+ features. I was successful in joining csv and shapefile via custom plugin that I created using this code.
from PyQt4.QtCore import *
import qgis
from qgis.core import QgsMapLayerRegistry, QgsVectorJoinInfo
for layer in QgsMapLayerRegistry.instance().mapLayers().values():
# Change to your shapefile name
if layer.name() == "MyShapefile":
qgis.utils.iface.setActiveLayer(layer)
shp = qgis.utils.iface.activeLayer()
for layer in QgsMapLayerRegistry.instance().mapLayers().values():
# Change to your csv name
if layer.name() == "MyDatabase":
qgis.utils.iface.setActiveLayer(layer)
csv = qgis.utils.iface.activeLayer()
# Set up join parameters
shpField='PIN'
csvField='UPIN'
joinObject = QgsVectorJoinInfo()
joinObject.joinLayerId = csv.id()
joinObject.joinFieldName = csvField
joinObject.targetFieldName = shpField
shp.addJoin(joinObject)
But when i try to open the attribute table it loads very slow and counting features by 8/10/15 at max. But when I join table using properties>join of shapefile and check the "cache data in virtual memory" my attributes loads perfectly fine even if I have 20,000 features.
My question is how can I make the loading of attribute table faster like in joining via properties>join using a custom plugin?
I am using QGIS 2.16