Skip to content

Instantly share code, notes, and snippets.

View thbaumann's full-sized avatar

Thomas Baumann @work thbaumann

View GitHub Profile
@thbaumann
thbaumann / qgis_userlogs.sql
Created October 22, 2024 14:48
QGIS user log table
-- Table: public.qgis_log_table
-- DROP TABLE IF EXISTS public.qgis_log_table;
CREATE TABLE IF NOT EXISTS public.qgis_log_table
(
log_id integer NOT NULL DEFAULT nextval('qgis_log_table_log_id_seq'::regclass),
"timestamp" timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
username character varying(255) COLLATE pg_catalog."default" NOT NULL,
message text COLLATE pg_catalog."default" NOT NULL,
@thbaumann
thbaumann / log_user_logs_to_postgres.py
Last active October 23, 2024 04:38
central logging of qgis logs of different users
from PyQt5.QtSql import QSqlDatabase, QSqlQuery
from PyQt5.QtCore import Qt, QTimer, QDateTime
from qgis.core import QgsApplication, Qgis
from qgis.utils import plugins
import os
import traceback
# Variable to hold the connection
message_log_connection = QgsApplication.messageLog()
spaltenname = 'name'
anzahl_spaltenzeichen = 8 # wieviele zeichen soll fuer die spaltenueberschrift verwendet werden. bsp 8
datentyp = QVariant.Double # datentyp der zu erzeugenden Spalten
vectorLayer = iface.activeLayer() # aktiver Layer
idx = vectorLayer.fields().indexOf(spaltenname)
values = vectorLayer.uniqueValues(idx)
#print(values)
provider = vectorLayer.dataProvider()
@thbaumann
thbaumann / test_temp.py
Last active September 26, 2022 15:19
test_temp
# Iterating over the input layer :
for m in municip.getFeatures():
inh_center = m['EWZ']
#
# central municipalites with 0 inhabitants must be excluded; the value of "center_pos" will be set to -1.
if inh_center == 0:
center_pos = -1
dict = {m.fieldNameIndex('center_pos'):center_pos}
municip.dataProvider().changeAttributeValues({m.id(): dict}) \
#
@thbaumann
thbaumann / grab_featureinfo_pyqgis.py
Last active February 9, 2022 12:09
basic example how to write getfeatureinfo response to selected features of a vectorlayer in QGIS / pyqgis
# coding: utf-8
from qgis.PyQt.QtCore import Qt
from qgis.gui import QgsMapTool
from qgis.utils import iface
class SendPointToolCoordinates(QgsMapTool):
""" Enable to return coordinates from clic in a layer.
"""
def __init__(self, canvas, layer):
@thbaumann
thbaumann / testlayer_qgis_oracle.sql
Created November 3, 2021 10:37
Testlayer QGIS Oracle
--DROP TABLE testlayer_polygone;
CREATE TABLE testlayer_polygone
(id NUMBER(20),
name VARCHAR2(15) NOT NULL,
geom "MDSYS"."SDO_GEOMETRY",
CONSTRAINT testlayer_polygone_pk PRIMARY KEY (id)
);
--select * from all_sdo_geom_metadata WHERE table_name = upper('testlayer_polygone');
@thbaumann
thbaumann / vscode_qgis_settings.json
Created May 23, 2021 18:31
vscode_qgis_settings.json
{
"telemetry.enableTelemetry": false,
"python.defaultInterpreterPath": "C:\\OSGeo4W64\\apps\\Python37\\python.exe",
"window.zoomLevel": 0,
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe",
"git.path": "Z:\\Programme\\Git\\bin\\git.exe",
"launch":
{
// Use IntelliSense to learn about possible attributes.
@thbaumann
thbaumann / minimum_distance.txt
Created March 19, 2021 13:16 — forked from pigreco/minimum_distance.txt
here is the expression used in the Default widget
if (
distance(
overlay_nearest(
layer:='poligono',
expression:= $geometry )[0], $geometry) <
distance(
overlay_nearest(
layer:='linea',
expression:= $geometry )[0], $geometry),overlay_nearest(
layer:='poligono',
@thbaumann
thbaumann / notes.MD
Created March 10, 2021 07:25 — forked from NicolaiLolansen/notes.MD
Debugging QGIS 3.x python plugins on Windows using VS Code
  1. Install ptvsd using the same Python interpreter Qgis uses. E.g. on Windows:
C:\OSGeo4W64\apps\Python37\python.exe -m pip install ptvsd==4.3.2 
  1. Add a debug configuration to launch.json:
{
    "name": "Python: Remote Attach",