Skip to content

Instantly share code, notes, and snippets.

@SrNetoChan
SrNetoChan / set_alias_for_all_qgis_layers.py
Created May 17, 2024 11:09
Script to set Alias on all fields on all layers vector layers of a QGIS Project
def set_alias(layer):
'''
Configure the alias for all fields of a vector layer
Use the field name replacing the underscore by spaces and set it to Title Case
'''
if layer.type() != QgsMapLayer.VectorLayer:
return
layer_fields = layer.fields()
for f in layer_fields:
@SrNetoChan
SrNetoChan / alterar_formularios_recart.py
Last active March 22, 2023 11:40
Alterar formularios de Camadas recart para serem mais faceis de editar
def field_readonly(layer, fieldname, option = True):
'''
Tornar o campo de uma camada vectorial nao editavel
'''
if layer.type() != QgsMapLayer.VectorLayer:
return
fields = layer.fields()
field_idx = fields.indexOf(fieldname)
if field_idx >= 0:
form_config = layer.editFormConfig()
@SrNetoChan
SrNetoChan / list_gdal_commands_qgis.py
Created May 9, 2022 10:27
List GDAL commands names and algorithms in QGIS
# List GDAL commands names and algorithms in QGIS
algorithms = QgsApplication.processingRegistry().algorithms()
gdal_alg = [alg for alg in algorithms if alg.provider().name() == 'GDAL']
gdal_commands = {}
for alg in gdal_alg:
if not alg.commandName() in gdal_commands:
gdal_commands[alg.commandName()] = []
gdal_commands[alg.commandName()].append(alg.displayName())
@SrNetoChan
SrNetoChan / code_snippets.py
Last active December 5, 2021 02:23
Shared PyQGIS Course Clipboard
n = 12
n2 = 5
print(n, n2)
@SrNetoChan
SrNetoChan / count_qgis_algorithms.py
Last active March 17, 2019 15:43
Get the a list of available QGIS processing providers and the number of algorithms
p_reg = QgsApplication.processingRegistry()
algorithms = p_reg.algorithms()
providers = p_reg.providers()
print('N. providers = {}'.format(len(providers)))
for provider in providers:
p_algorithms = provider.algorithms()
print('{} --> {}'.format(provider.name(),len(p_algorithms)))
@SrNetoChan
SrNetoChan / dms2dec.py
Last active October 30, 2015 16:49 — forked from tomwhipple/dms2dec.py
convert DMS coordinates to decimal in Python
#!/env/python
# coding=utf8
"""
Converting Degrees, Minutes, Seconds formatted coordinate strings to decimal.
Formula:
DEC = (DEG + (MIN * 1/60) + (SEC * 1/60 * 1/60))
Assumes S/W are negative.