Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View breinbaas's full-sized avatar

Rob van Putten breinbaas

View GitHub Profile
@breinbaas
breinbaas / ahn4.py
Last active April 22, 2022 06:54
Sample of using the ArcGIS REST API for AHN4 DTM height data
import urllib.request
from tifffile import imread # pip install tifffile==2022.4.8 or add to requirements.txt
import numpy as np
class Tile:
def __init__(self):
self.xmin = 0
self.xmax = 0
self.ymin = 0
@breinbaas
breinbaas / Poetry reminders
Created May 3, 2022 06:48
Poetry reminders
## set poetry to add the virtuals envs in the project directory which is easier for vscode setup
poetry config --local virtualenvs.in-project true

ask for confirmation

c = confirm("Are you sure?")
  if c:
    ...

ask for confirmation with own buttons and outcome

use the following line in requirements.txt

--index-url https://gitlab-ci-token:<MY_TOKEN>@gitlab.com/api/v4/projects/<PROJECT_ID>/packages/pypi/simple

  • <MY_TOKEN> should be the token that you generate on gitlab | preferences | access tokens , you only need the api scope to be activated for that token
  • <PROJECT_ID> should be the id (numeric) of the project and can be found on the home page of the repo directly under the project name

once you setup this line you can now add packages that are part of that repo

leveelogic

Example script of testing, linting and deploying a python package to a private gitlab repo

Note the following info

  • PROJECT_ID, can be found on the main repo page under the title
  • GITLAB_TOKEN, can be created under PREFERENCES | ACCESS TOKENS, create one with the api scope

In this CICD script we only run the tests etc on commits to the main branch.

import requests
import xml.etree.ElementTree as ET
# this is the url for the search request to find cpts based on some query parameters
# in this case the registrationPeriod and the given area
url = "https://publiek.broservices.nl/sr/cpt/v1/characteristics/searches?requestReference=request"
# setup the query params (literal copy of the bro example in the docs)
my_obj = {
"registrationPeriod": {"beginDate": "2017-01-01", "endDate": "2021-01-01"},

XML to GEF

I don't like the xml format but unfortunately some people thought it would be a great idea to use that as a CPT exchange format. Fortunately for us some people wrote code to read those xml files and I have used their code to write a XML to GEF convertor. That code can be found here. I've tested it on some xml files but since I don't have many of them there will probably be some possible errors. For the files that I've tested everything is just fine.

Check out these repo's that are actively working on XML readers;

Note that this code will only copy the most important parts of the cpt and not the full cpt information!

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 ;-)

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)
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