This page contains the documentation for the InaSAFE is_keyword_io module.
Contact : ole.moller.nielsen@gmail.com
Note
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
Class for doing keyword read/write operations. It abstracts away differences between using SAFE to get keywords from a .keywords file and this plugins implemenation of keyword caching in a local sqlite db used for supporting keywords for remote datasources.
Find out if keywords should be read/written to file or our keywords db.
Given an sqlite3 connection, close it.
Helper to copy the keywords file from a source dataset to a destination dataset.
e.g.:
copyKeywords('foo.shp', 'bar.shp')
Will result in the foo.keywords file being copied to bar.keyword.
Optional argument extraKeywords is a dictionary with additional keywords that will be added to the destination file e.g:
copyKeywords('foo.shp', 'bar.shp', {'resolution': 0.01})
Helper to get the default path for the keywords file (which is <plugin dir>/keywords.db)
Delete keywords for a URI in the keywords database. A hash will be constructed from the supplied uri and a lookup made in a local SQLITE database for the keywords. If there is an existing record for the hash, the entire record will be erased.
See also
writeKeywordsForUri, readKeywordsForUri
Args:
- theUri - a str representing a layer uri as parameter. .e.g. ‘dbname=’osm’ host=localhost port=5432 user=’foo’ password=’bar’ sslmode=disable key=’id’ srid=4326
Get a cursor for the active connection. The cursor can be used to execute arbitrary queries against the database. This method also checks that the keywords table exists in the schema, and if not, it creates it.
Given a datasource, return its hash.
Open an sqlite connection to the keywords database. By default the keywords database will be used in the plugin dir, unless an explicit path has been set using setKeywordDbPath, or overridden in QSettings. If the db does not exist it will be created.
Get metadata from the keywords file associated with a non local layer (e.g. postgresql connection).
A hash will be constructed from the supplied uri and a lookup made in a local SQLITE database for the keywords. If there is an existing record it will be returned, if not and error will be thrown.
See also
writeKeywordsForUri,deleteKeywordsForUri
Args:
- theUri - a str representing a layer uri as parameter. .e.g. ‘dbname=’osm’ host=localhost port=5432 user=’foo’ password=’bar’ sslmode=disable key=’id’ srid=4326
- keyword - optional - the metadata keyword to retrieve e.g. ‘title’
Read keywords for a datasource and return them as a dictionary. This is a wrapper method that will ‘do the right thing’ to fetch keywords for the given datasource. In particular, if the datasource is remote (e.g. a database connection) it will fetch the keywords from the keywords store.
Set the path for the keyword database (sqlite) that should be used to search for keywords for non local datasets.
Helper to set the active path for the keywords. Called at init time, you can override this path by calling setKeywordDbPath.
Write keywords for a datasource. This is a wrapper method that will ‘do the right thing’ to store keywords for the given datasource. In particular, if the datasource is remote (e.g. a database connection) it will write the keywords from the keywords store.
Write keywords for a URI into the keywords database. All the keywords for the uri should be written in a single operation. A hash will be constructed from the supplied uri and a lookup made in a local SQLITE database for the keywords. If there is an existing record it will be updated, if not, a new one will be created.
See also
readKeywordFromUri, deleteKeywordsForUri
Args:
- theUri - a str representing a layer uri as parameter. .e.g. ‘dbname=’osm’ host=localhost port=5432 user=’foo’ password=’bar’ sslmode=disable key=’id’ srid=4326
- keywords - mandatory - the metadata keyword to retrieve e.g. ‘title’