Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrea Giudiceandrea agiudiceandrea

View GitHub Profile
@agiudiceandrea
agiudiceandrea / bearing
Last active Oct 10, 2021
Expression to calculate bearing true-north based (loxodromic) between first and second point from current layer with UTM coordinates
View bearing
-- by Andrea Giudiceandrea licensed under CC-BY-SA 4.0 license
degrees(
azimuth(geometry(get_feature_by_id(@layer, 1)), geometry(get_feature_by_id(@layer, 2))) -
-- the grid convergence from https://gis.stackexchange.com/a/394982/107272 by Houska
with_variable('LL', transform( geometry(get_feature_by_id(@layer, 1)),layer_property(@layer,'crs'),'EPSG:4326'),
with_variable('displacedLL',translate(@LL,0,0.001),
azimuth(geometry(get_feature_by_id(@layer, 1)),transform(@displacedLL,'EPSG:4326',layer_property(@layer,'crs')))
))
)
View convertToGeoTIFFs.py
"""
***************************************************************************
convertToGeoTIFFs.py
---------------------
Date : 29/09/2021
Copyright : (C) 2021 by Andrea Giudiceandrea
Email : andreaerdna at libero dot it
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
View createGeoTIFF.py
"""
***************************************************************************
createGeoTIFF.py
---------------------
Date : September 2021
Copyright : (C) 2021 by Andrea Giudiceandrea
Email : andreaerdna at libero dot it
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
View AddLineSubnetField.py
# -*- coding: utf-8 -*-
"""
***************************************************************************
* *
* This code is licensed by Andrea Giudiceandrea under CC-BY-SA license *
* https://creativecommons.org/licenses/by-sa/3.0/ as a derivative work *
* of the code originally published by Jochen Schwarze, under the same *
* license, at https://gis.stackexchange.com/a/198329/107272 *
* *
View raggio_cerchio.py
from qgis.core import *
from qgis.gui import *
@qgsfunction(args='auto', group='Custom')
def raggio_cerchio(qPt1, qPt2, qPt3, feature, parent):
"""
Calcola il raggio del cerchio passante per tre punti.
"""
pt1 = QgsPoint(qPt1.asPoint())
pt2 = QgsPoint(qPt2.asPoint())
View crs_import_errors_list.txt
Could not execute: INSERT INTO tbl_srs(srs_id, description,projection_acronym,ellipsoid_acronym,parameters,srid,auth_name,auth_id,is_geo,deprecated) VALUES (63321, 'Timbalai 1948 / RSO Sarawak LSD (m)','omerc',NULL,'+proj=omerc +no_uoff +lat_0=4 +lonc=115 +alpha=53.3158204722222 +gamma=53.1301023611111 +k=0.99984 +x_0=2000000 +y_0=5000000 +ellps=evrstSS +towgs84=-679,669,-48,0,0,0,0 +units=m +no_defs',520003321,'EPSG','29874',0,0) [NOT NULL constraint failed: tbl_srs.ellipsoid_acronym/NOT NULL constraint failed: tbl_srs.ellipsoid_acronym]
Could not execute: INSERT INTO tbl_srs(srs_id, description,projection_acronym,ellipsoid_acronym,parameters,srid,auth_name,auth_id,is_geo,deprecated) VALUES (63322, 'ETRS89','longlat',NULL,'+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs',520003322,'EPSG','9286',1,0) [NOT NULL constraint failed: tbl_srs.ellipsoid_acronym/NOT NULL constraint failed: tbl_srs.ellipsoid_acronym]
Could not execute: INSERT INTO tbl_srs(srs_id, description,projection_acronym,ellipsoid_acr
@agiudiceandrea
agiudiceandrea / qgis-grass.bat
Created Apr 20, 2021
qgis-grass.bat per MSI installer
View qgis-grass.bat
@ECHO OFF
SET DRV_LTR=%cd%
SET OSGEO4W_ROOT=%DRV_LTR%\qgis
PATH %PATH%;%OSGEO4W_ROOT%\apps\qgis\bin;%OSGEO4W_ROOT%\apps;%OSGEO4W_ROOT%\bin;%OSGEO4W_ROOT%\apps\grass
IF "%1" == "" (start "QGIS" /B %OSGEO4W_ROOT%\bin\qgis.bat --profiles-path %DRV_LTR%\qgisconfig) ELSE (start "QGIS" /B %OSGEO4W_ROOT%\bin\qgis.bat --profiles-path %DRV_LTR%\qgisconfig --project %1)
@agiudiceandrea
agiudiceandrea / qgis.bat
Created Apr 20, 2021
qgis.bat modificato per MSI installer
View qgis.bat
@echo off
call "%~dp0\o4w_env.bat"
if not exist "%OSGEO4W_ROOT%\apps\qgis\bin\qgisgrass7.dll" goto nograss
set savedpath=%PATH%
call "%OSGEO4W_ROOT%\apps\grass\grass78\etc\env.bat"
path %OSGEO4W_ROOT%\apps\grass\grass78\lib;%OSGEO4W_ROOT%\apps\grass\grass78\bin;%savedpath%
:nograss
SET PYTHONHOME=%OSGEO4W_ROOT%\apps\Python39
SET PYTHONPATH=%PYTHONHOME%;%PYTHONHOME%\Scripts
View order_legend_flip.py
# See https://gis.stackexchange.com/questions/385525/qgis-how-to-invert-the-values-in-a-layout-legend
def invertLegendOrder():
layer = iface.activeLayer()
view_model = iface.layerTreeView().layerTreeModel()
toc_layer = view_model.rootGroup().findLayer(layer)
cat_count = view_model.legendRootRowCount(toc_layer)
order_property = toc_layer.customProperty('legend/node-order')
# print(order_property)
View test_geodesic_3.4.5-9.py
QGIS 3.4.5-9-Madeira
GEOS 3.7.0-CAPI-1.11.0
PROJ 5.2.0
SpatiaLite 4.3.0
from processing.tools import spatialite
db = spatialite.GeoDB(QgsDataSourceUri('dbname=\'C:/Users/Andrea/test.sqlite\' table=\'test\'(geometry) sql='))
cur=db.con.cursor()
db._exec_sql(cur, sql='select spatialite_version();')