Skip to content

Instantly share code, notes, and snippets.

View SzieberthAdam's full-sized avatar
🏠
Working from home

SZIEBERTH Ádám SzieberthAdam

🏠
Working from home
View GitHub Profile
@SzieberthAdam
SzieberthAdam / pyqgis_layerfields.py
Last active January 19, 2016 10:44
PyQGIS: Get fields of layer
# QgsFields() of QgsVectorLayer()
# fields = layer.fields() # from QGIS 1.12+
fields = layer.pendingFields() # and below...
# list QgsField() from QgsFields()
fieldlist = fields.toList()
# list of layer fieldnames
[f.name() for f in fieldlist]
@SzieberthAdam
SzieberthAdam / pyqgis_crs.py
Last active January 19, 2016 10:45
PyQGIS: CRS (Coordinate Reference System / Projection)
# project
project_crs = qgis.utils.iface.mapCanvas().mapRenderer().destinationCrs()
qgis.utils.iface.mapCanvas().mapRenderer().setDestinationCrs(new_project_crs)
@SzieberthAdam
SzieberthAdam / qgis_custom_label_autocentroid.txt
Created January 19, 2016 14:30
QGIS: Label to centroid when position is not explicitely set
# It is assumed that the layer has both "labelX" and a "labelY" attributes set as real number fields.
# Labels / Placement / Data Defined / Coordinate / X:
CASE WHEN "labelX" IS NULL THEN toreal(regexp_substr(geom_to_wkt(centroid($geometry)), '(-?\\d+\\.?\\d*) -?\\d+\\.?\\d*')) ELSE "labelX" END
# Labels / Placement / Data Defined / Coordinate / Y:
CASE WHEN "labelY" IS NULL THEN toreal(regexp_substr(geom_to_wkt(centroid($geometry)), '-?\\d+\\.?\\d* (-?\\d+\\.?\\d*)')) ELSE "labelY" END
# Labels / Placement / Data Defined / Alignment / horizontal:
'Center'
@SzieberthAdam
SzieberthAdam / vispres.py
Last active May 31, 2021 15:34
Python QGIS (PyQGIS) visibility preset manipulation functions
def activate_visibility_preset(preset_name, *, project=None, coll=None):
"""Activates a visibility preset by its name.
Return a boolean indicating success."""
# https://github.com/qgis/QGIS/blob/f044c95fd8927d86967ce8af3930bdc7523095fa/src/app/qgsmapthemes.cpp#L138
if project is None:
project = qgis.core.QgsProject.instance()
if coll is None:
coll = project.mapThemeCollection()
if not coll.hasMapTheme(preset_name):
return False
@SzieberthAdam
SzieberthAdam / st_extend.sql
Created January 29, 2018 08:37
PostGIS function to extend a linestring
CREATE OR REPLACE FUNCTION st_extend (
geom geometry,
head_rate double precision,
head_constant double precision,
tail_rate double precision,
tail_constant double precision)
RETURNS geometry AS
$BODY$
-- Extends a linestring.
-- First segment get extended by length * head_rate + head_constant.
@SzieberthAdam
SzieberthAdam / papa.txt
Last active September 11, 2023 17:23
Papa
A gyógyszer tanított meg arra, hogy beteg legyek.
Az idő lejár; a cserebogár marad sárga cserebogár.