1

I am a novice to Python and QGIS coding. I am facing an issue while showing the MySQL spatial data on QGIS canvas. Database connection details are below:

database name:- mysql
host :- localhost
port :- 3306
user :- root
password :- abcx
tablename:- Tablegis

I found a code on to connect the same:

uri="MySQL:mysql,host=localhost,port=3306,user=root,password=abcx|layername=Tablegis"
vlayer=QGSVectorLayer(uri, "Open_Table","ogr")
QgsMapLayerRegistry.instance().addMapLayer(vlayer)

This code doesn't show any warning or error but nothing shows on my canvas. When I am printing the vlayer shows the object reference. Tried hard nothing worked for me.

4
  • does the layer display if you add it manually using the menus Commented Jun 12, 2019 at 9:12
  • Nothing on the canvas but can you access the content of the attribute table ? Are you sure of the geographical content of your table ? Commented Jun 12, 2019 at 14:03
  • Yes Ian, when I am manually adding the MySQL table in QGIS it displays and can also see the attributes. Commented Jun 13, 2019 at 5:33
  • code is okay, i am just missing the update extent and zoom the canvas to objects of table. Commented Dec 31, 2019 at 9:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.