[Qgis-user] Globally Unique Indentifier (GUID) in QGIS

Alexander Bruy alexander.bruy at gmail.com
Fri May 6 03:09:15 PDT 2011


Hi,

here is script to fill vector layer fields with GUIDs. It can be
executed from QGIS Python console

import uuid

layer=qgis.utils.iface.activeLayer() # get active layer
fieldNum=layer.fieldNameIndex("UID") # get field that should be filled
with GUIDs

layer.startEditing()     # start editing
feat = QgsFeature()
layer.select()
while layer.nextFeature(feat):  # iterate over features
	layer.changeAttributeValue(feat.id(), fieldNum, str(uuid.uuid4())) #
fill field with GUID
layer.commitChanges() # save edits

Hope this helps

2011/5/6 Błażej Zamojski <blazej.zamojski at rdos.krakow.pl>:
> Thanks,
> not really GUID solution but useful. Maybe GUID should be implemented in the
> future?
>
> Regards
> Blazej Zamojski
>
> -----Original Message-----
> From: Robert Szczepanek [mailto:robert at szczepanek.pl]
> Sent: Thursday, May 05, 2011 12:44 PM
> To: Błażej Zamojski
> Cc: qgis-user at lists.osgeo.org
> Subject: [SPAM] Re: [Qgis-user] Globally Unique Indentifier (GUID) in QGIS
>
> Hi Blazej,
>
> Fast but not "true GUID" solution:
> - open attribute table
> - start editing
> - run 'field calculator' icon (kalkulator pól)
> - GUID as name for new field
> - $rownum in expressions area
>
> You are welcome to polish forum [1], as your QGIS interface is probably
> in polish.
>
> regards,
> Robert
>
> [1] http://forum.quantum-gis.pl/
>
> W dniu 05.05.2011 11:26, Błażej Zamojski pisze:
>> Hi
>> Is there a way to add a GUID type data field in attribute table for a
>> shapefile?
>>
>> Regards
>> Blazej Zamojski
>>
>> _______________________________________________
>> Qgis-user mailing list
>> Qgis-user at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/qgis-user
>>
>
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-user
>



-- 
Alexander Bruy



More information about the Qgis-user mailing list