I am developing a QGIS plugin and got currently stuck at setting the geometry of a feature based on coordinates.
I retrieve coordinates through an SQL query, create a feature and try to set the geometry.
#fetch sql query rec = dict_cur.fetchone() #create feature feature = QgsFeature() feature.setGeometry(QgsGeometry.fromPoint(QgsPoint(rec, rec)))
In the code above
rec holding the information about longitude and latitude. When requesting the type of
rec it comes back as
<class 'decimal.Decimal'> and I can cast it to float. However, that doesn't change anything.
When I try to set the coordinates for QgsPoint then I am getting the following error message:
feature.setGeometry(QgsGeometry.fromPoint(QgsPoint(rec, rec))) TypeError: 'NoneType' object has no attribute '__getitem__'
The error is directely related to QgsPoint. When I seperate QgsPoint and try to provide the coordinates I am getting the same error message.
That is for my plugin. If I use the same code in the Python console of QGIS then it works.
Python is in version 2.7.10 QGIS version is 2.8.2-Wien