I wrote a simple plugin to retrieve and synchronize points from remote MongoDb into a generated scratch layer with all the attributes every time the project open, edit and commit but the attribute naming bothering me for sometimes.
Scratch layer is in-memory layer that does not preserve the features upon exit. However I can save the project together with the layer.
Whenever I load the project, the attributes name of scratch layer gets appended with :(0,0)
. E.g. the attribute changed from city
to city:(0,0)
why?
Edit:
Apparently it will only happened if the attributes created using python.
How to produce:
layer = iface.activeLayer()
from PyQt4.QtCore import QVariant
field = QgsField("test", QVariant.String)
layer.dataProvider().addAttributes([field])
layer.updateFields()
- Create Temporary Scratch Layer
- Run the code above in Python Console
- Save the layer edit and project into a
.qgs
file. - Exit and reopen QGIS
- Reopen the saved project file
- Open the layer Properties > Fields
- The attribute name
test
will turns intotest:(0,0)
I am using QGIS 2.18.2
Edit2:
I found that QGIS does not preserve the data type string
into the project file when the field created using python. The project file .qgs
xml content under qgs > projectlayers > maplayer > datasource
is:
memory?geometry=None&field=test:(0,0)
but it should be:
memory?geometry=None&field=test:string(0,0)
test
as attribute name in Properties > Field. Do you edit the scratch layer before saving it or it's keeped withNULL
values?