Skip to content

Instantly share code, notes, and snippets.

View thbaumann's full-sized avatar

Thomas Baumann @work thbaumann

View GitHub Profile
settings=QSettings()
test=settings.allKeys()
errorcounter=0
for i in test:
if(u'Projections/EPSG:25832/EPSG:31467_coordinateOp' in i):
if settings.value(i)!=u'+proj=pipeline +step +inv +proj=utm +zone=32 +ellps=GRS80 +step +inv +proj=hgridshift +grids=BWTA2017.gsb +step +proj=tmerc +lat_0=0 +lon_0=9 +k=1 +x_0=3500000 +y_0=0 +ellps=bessel':
errorcounter+=1
else:
settings.setValue('Projections/EPSG:25832/EPSG:31467_coordinateOp',u'+proj=pipeline +step +inv +proj=utm +zone=32 +ellps=GRS80 +step +inv +proj=hgridshift +grids=BWTA2017.gsb +step +proj=tmerc +lat_0=0 +lon_0=9 +k=1 +x_0=3500000 +y_0=0 +ellps=bessel')
@thbaumann
thbaumann / filerotator.py
Created April 1, 2020 12:28 — forked from RWJMurphy/filerotator.py
Python class and utility for file rotation. Configurable daily, weekly and monthly retention; can use hard links to save space; supports `argparse` config files.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: ft=python ts=4 sw=4 expandtab
#
# Copyright (c) 2013 Reed Kraft-Murphy <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@thbaumann
thbaumann / export_as_gpx.py
Created June 22, 2020 15:25
export selected features as gpx for use in qgis action
layer = QgsProject.instance().mapLayer('[% @layer_id %]')
from qgis.core import Qgis, QgsVectorFileWriter
exportpath="D:/loeschen/test.gpx"
error, error_string = QgsVectorFileWriter.writeAsVectorFormat( layer,
exportpath,
"UTF-8",
layer.crs(),
"GPX",
onlySelected=True)
@thbaumann
thbaumann / pipes.geojson
Last active June 26, 2020 11:55
pipes test data
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from qgis.core import *
from qgis.gui import *
@qgsfunction(args='auto', group='Custom')
def eindeutige_legende1( layername, feature, parent,context):
try:
project = QgsProject.instance()
ausgabe=None
legendenlayer = QgsExpressionContextUtils.projectScope(project).variable('eindeutig')
from qgis.core import *
from qgis.gui import *
import os.path
@qgsfunction(args='auto', group='Custom',usesgeometry=False)
def layername_aus_pfad(current_path, feature, parent):
"""
Layername aus dem Pfad ermitteln
current_path: an die Funktion uebergebener pfad, wie z.B. layer_by_path('D:\loeschen\gemarkungen.shp')
"""
path=os.path.normpath(current_path)
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)
# 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)
  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",
@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