Skip to content

Instantly share code, notes, and snippets.

View TheHelmut's full-sized avatar

Andreas TheHelmut

View GitHub Profile
@TheHelmut
TheHelmut / Shapefile_to_SOSI.ipynb
Created October 8, 2025 12:51
Converts shapefiles (use bounding boxes) to SOSI, e.g. for downloading from norgeibilder.no; use https://nbviewer.jupyter.org/ to view this file
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@TheHelmut
TheHelmut / 2_layer_intersection_big_files.py
Last active April 23, 2024 09:18
More efficient intersection check. First, it creates a list of overlapping bounding boxes and then loops over it to check for actual intersections, potentially leaving some features untouched which saves time. Should be easy to adapt to other tools as well.
# More efficient intersection check. First, it creates a list of overlapping bounding boxes and then loops over it to check for actual intersections, potentially leaving some features untouched which saves time
# How to use:
# - change name and name2 variables so that they represent the layers you want to check for intersection
# - create a new integer field in layer "name", give it a value of 0 and enter the name in the variable below
# Importing dependencies for outside the QGIS Python console
from qgis.PyQt.QtCore import (
QRectF,)
@TheHelmut
TheHelmut / Height_along_line.py
Last active March 20, 2024 10:08
Get stats along a line from a raster file, e.g. height along a running trail.
# Get stats for a raster along a line, e.g. height data along a hiking/running path.
# How to use: draw or import a line. Use the Points along geometry-tool to place points on the line.There is likely
# no benefit in putting the points closer together than the resolution of the height data raster. If you are asked to input the distance
# in degrees, you have to reproject the layer into a UTM-coordinate system. Then run the SAGA tool
# Add raster values to points (SAGA has to be activated under plugins).
from qgis.core import QgsProject
import math
# User input goes here
@TheHelmut
TheHelmut / arcpy_folder_to_curvature.py
Created March 18, 2024 09:04
ArcPy for ArcGIS Pro. Take a folder of .tif files and calculate profile and planform curvature for each and save them to new folders. You should change the folder paths in order for this to work for you.
# Description: Calculates the planform and profile curvature of a raster surface for a folder of .tif files.
# Requirements: Spatial Analyst Extension
# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *
import os
@TheHelmut
TheHelmut / Running_gpx_analyzer.R
Created October 31, 2023 12:58
This R script takes a folder of .gpx files and lets you calculate statistics about them, as well as create plots.
#if necessary run: install.packages("scales","ggplot2",xml2","terra","sf","dplyr","lubridate","geosphere")
library(xml2)
library(terra)
library(sf)
library(dplyr)
library(lubridate)
library(geosphere)
library(ggplot2)
library(scales)
@TheHelmut
TheHelmut / QGIS_transect_double_remover_rownums_v3.py
Created October 13, 2023 16:16
Polygon transect double and overlay remover v3
# Importing dependencies for outside the QGIS Python console
from qgis.PyQt.QtCore import (
QRectF,)
from qgis.core import (
QgsProject,
QgsLayerTreeModel,QgsVectorLayer,QgsApplication,
QgsDataSourceUri,
QgsDistanceArea, #for area calculation
QgsCategorizedSymbolRenderer,
QgsClassificationRange,
@TheHelmut
TheHelmut / QGIS_transect_double_remover_rownums.py
Created October 9, 2023 11:43
PyQGIS script to filter a layer based on spatial intersections. It keeps features that touch, one of those that equal each other, and those features that are disjoint from the rest of the layers features. It also transfers an ID over from one feature to another, if the feature was intersecting and did not have an ID.
# Importing dependencies for outside the QGIS Python console
from qgis.PyQt.QtCore import (
QRectF,)
from qgis.core import (
QgsProject,
QgsLayerTreeModel,QgsVectorLayer,QgsApplication,
QgsDataSourceUri,
QgsDistanceArea, #for area calculation
QgsCategorizedSymbolRenderer,
QgsClassificationRange,