Last active
July 10, 2019 17:20
-
-
Save slarosa/f032b50833ff6aaabc95843d9287dcce to your computer and use it in GitHub Desktop.
Action for QGIS to show a stored image in a sqlite db
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from qgis.PyQt.QtCore import Qt | |
from qgis.PyQt.QtGui import QLabel, QImage, QPixmap | |
from qgis.utils import iface | |
import sqlite3 | |
UNIQUE_FIELD = "unique_field_name" | |
BLOB_FIELD = "picture_field_name" | |
FIELD_VALUE = '[%unique_field_name%]' | |
vl = iface.activeLayer() | |
pr = vl.dataProvider() | |
db = pr.dataSourceUri().split(' ')[0].replace('dbname=','').replace("'","") | |
conn = sqlite3.connect(db) | |
sql = "SELECT {0} FROM {1} WHERE {2}={3}".format(BLOB_FIELD, vl.name(), | |
UNIQUE_FIELD, FIELD_VALUE) | |
c = conn.cursor() | |
c.execute(sql) | |
rows = c.fetchone() | |
c.close() | |
conn.close() | |
qimg = QImage.fromData(rows[0]) | |
pixmap = QPixmap.fromImage(qimg) | |
label = QLabel() | |
h = label.height() | |
w = label.width() | |
label.setPixmap(pixmap.scaled(w,h,Qt.KeepAspectRatio)) | |
label.show() |
What would be the catch for a postgresql database?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I need some help with viewing Exif photos in QGIS.
Facts
I loaded some JPs with GPS exif data to a SQLITE db.
I performed all actions as required.
I created an ACTION and added te code provided here.
Every thing goes ok and I can see my photos were they a suppsed to be
So far every thing fine.
Now,
The SQLITE loads a theme named "Exifphoto"
If I rename the theme and click on the action icon I receive an error code and fail to open the JPG
Ugh
Is there a way to work this arround.
You may have already notice I am new in this matter and am still green
Thanks