Skip to content

Instantly share code, notes, and snippets.

View thbaumann's full-sized avatar

Thomas Baumann @work thbaumann

View GitHub Profile
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",
# for testing in QGIS console
style_name = 'Druckstufen'
layer=iface.activeLayer()
stylemanager = layer.styleManager()
current_style = stylemanager.currentStyle()
#print(curr_style)
# stil nur wechseln wenn nicht schon aktuell eingestellt
if style_name != current_style:
stylemanager.setCurrentStyle(style_name)
Kategorisierter Stil per PyQGIS: größtenteils basierend auf: https://gis.stackexchange.com/a/382742/67477
# Code für die QGIS Konsole:
styling_layer = iface.activeLayer() # Hinweis: im Plugin self.iface.activeLayer()
spalten_name = 'DRUCKSTUFE'
rampen_name = 'Greens'
field_index = styling_layer.fields().indexFromName(spalten_name)