[Qgis-user] Editing dbf attributes via Python Console
Alex Mandel
tech_dev at wildintellect.com
Sun Nov 2 17:46:08 PST 2008
maning sambale wrote:
> Here's my python console challenge for QGIS.
>
> I need to edit the dbf attributes of a GRASS vector in QGIS. I
> usually load grass vectors in QGIS (via GRASS plugin).
> For editing attributes of the vector dbf, I use openoffice dbase. The
> process goes like this:
>
> 1. Interactively select the vector polygons using the "select feature".
> 2. Display the attribute table.
> 3. Edit the selected attributes in OpenOffice
> 4. Save dbf file in Openoffice.
> 5. After a couple of edits, re-start QGIS. (I does not automatically
> "refresh" when the attributes were saved in OOO)
>
> Now for the challenge I want to be able to do this with Python
> Console. Basically I select the polygons with the "Select feature"
> And use the console to change the dbf attributes of the selected feature.
>
> Any tips?
It would be much easier if you used the sqlite backend for GRASS.
Then in python there are any number of sqlite connectors(ADODB,pysqlite)
and a nifty firefox plugin.
1st way:
Select a feature, based on the feature id run a select query and return
the values of that to a box. When done changing values in your edit
boxes hit save. The save command runs an Update Query on the changed
fields of your selected attribute. Or a delete followed by insert query.
2nd way:
Use something like SQL Alchemy to treat each selected feature as an
object and change the value of the property on exit from each text box.
The best approach is to start by writing a PyQt app that allows you to
see results from an sqlite table and edit. Once you do that integrate it
with QGIS using visual map ques like a select feature to pass the select
to the PyQt app.
Alex
More information about the Qgis-user
mailing list