Skip to content

Instantly share code, notes, and snippets.

View breinbaas's full-sized avatar

Rob van Putten breinbaas

View GitHub Profile

Godot - Python interaction

I need to call some specific Python code which is not easy to implement as Godot code and came up with this solution. Note that the essence of the script is that the Python code generates a dictionary with the required information and prints this as a JSON formatted string. Godot calls the script and receives the output and uses the internal JSON functionality to convert the string to a Godot JSON object. Also note that the Python script gets called from the python version that is set in the environment specific for this Python code (python-venv).

Not too difficult actually!

Python code

import sys
from leveelogic.helpers import case_insensitive_glob
from leveelogic.deltares.dstability import DStability
# Dit script leest alle grondsoorten uit een directory met stix bestanden
# en maakt een csv bestand van de grondsoorten en de helling. Dit is nodig
# voor de leggerprofielen omdat we moeten weten welke grondsoort naam
# bij welke helling hoort
# Locatie van de stix bestanden
STIX_PATH = "Z:\\Python\\leveelogic\\tests\\testdata\\stix"
@breinbaas
breinbaas / qgis_hwbp_score_filter.py
Last active February 15, 2024 12:25
QGIS Processing Toolbox script om snel selecties te maken in HWBP faalmechanismen en categorieen
# note, code is not clean yet so it will have some unused imports
# it expects a vectorlayer with columns like STPH, STBI, etc
# and the scores as -, Iv, IIv, IIIv, IVv, Vv, VIv, VIIv
# if will not be useful if your data is formatted differently
# but maybe then it is an inspiration for creating your own filters ;-)
#
# Rob van Putten | breinbaasnl@gmail.com | feb 2024
#
"""
@breinbaas
breinbaas / add_tree_excavation.py
Created August 16, 2023 07:18
Basic code to add a tree as an excavation in D-Stability using the adjusted geolib version
from typing import List, Tuple
import logging
from pydantic import BaseModel
from pathlib import Path
import subprocess
import shutil
from shapely.geometry import Polygon, LineString
from shapely.ops import unary_union, orient
from geolib.models.dstability import DStabilityModel
from pathlib import Path
import subprocess
PATH_TO_DSTABILITY_CONSOLES = "D:\\Apps\\D-GEO Suite\\Consoles\\DStabilityConsole"
def case_insensitive_glob(filepath: str, fileextension: str) -> List[Path]:
p = Path(filepath)
result = []
for filename in p.glob("**/*"):
if str(filename.suffix).lower() == fileextension.lower():
from typing import List
def line_to_id(line: str) -> str:
"""Extract the id from the line
We expect the id to be between '', the rest of the line should not contain the ' character
Note that we do an extra check to see if there are no spaces in the id
Args:
"""
Script documentation
Get all BRO cpt's from the current ArcGis Map extent. Add the script to your toolbox.
And make sure to add three parameters;
Output Path [Folder]: where to write the cpts to
Start Date [Date]: start date CPT (NOT before 01-01-2015)
End Data [Date]: end date CPT
from typing import Union, Optional
from pathlib import Path
import sys
# 'Hack' to add the geolib path so Python can find the adjusted geolib code
PATH_TO_ADJUSTED_GEOLIB = r"D:\Documents\Development\Github\GEOLib"
if not PATH_TO_ADJUSTED_GEOLIB in sys.path:
sys.path.append(PATH_TO_ADJUSTED_GEOLIB)
import geolib as gl
import sys
from pydantic import BaseModel
from pathlib import Path
from typing import Union
# 'Hack' to add the geolib path so Python can find the adjusted geolib code
PATH_TO_ADJUSTED_GEOLIB = r"D:\Documents\Development\Github\GEOLib"
if not PATH_TO_ADJUSTED_GEOLIB in sys.path:
sys.path.append(PATH_TO_ADJUSTED_GEOLIB)

Piping code

This code implements the piping rules according to Dutch WBI standard 2017, update 2021-05-28. See this manual page

I have checked it with an existing Piping Excel sheet but feel free to test some more and give me feedback (breinbaasnl@gmail.com)

The code (scroll down to see some test samples)

Please don't mind the Dutch / English mixups.. some words are easier in Dutch (well.. for me that is ;-)