Skip to content

Instantly share code, notes, and snippets.

View moosetraveller's full-sized avatar

Thomas Zuberbühler moosetraveller

View GitHub Profile
@moosetraveller
moosetraveller / antimeridian-polygon-split.py
Last active June 25, 2024 09:59
QGIS Processing Tool splitting Polygons along Antimeridian
"""
The following QGIS tool corrects polygons that are overlapping
the antimeridian by creating multipolygons with two parts on
both sides of the antimeridian.
Limitations:
- The geometry must be WGS 84 (EPSG:4326).
- Polygons must not have holes.
Dependencies:
@moosetraveller
moosetraveller / leaflet-map-wfs-airports.html
Created March 6, 2022 17:42
Leaflet Map using WFS and GeoServer
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Leaflet Map using WFS and GeoServer</title>
<script src="https://unpkg.com/rxjs@^7/dist/bundles/rxjs.umd.min.js"></script>
@moosetraveller
moosetraveller / qgis-map-to-tiff.md
Last active March 3, 2022 01:55
Convert QGIS Map to TIFF File

Convert QGIS Map to TIFF File

Using QgsMapRendererParallelJob

  1. Iterate over shape files in INPUT_FOLDER
  2. Apply style file
  3. Generate TIFF file using QgsMapRendererParallelJob
import os
@moosetraveller
moosetraveller / rmarkdown-open-link.md
Last active February 23, 2022 02:23
How to globally open Links in new tabs
@moosetraveller
moosetraveller / delete-shapefile.md
Created February 5, 2022 17:53
Delete Shapefile with Python

You can use arcpy.management.Delete:

import arcpy

shapefile = r"D:\projects\playground\python\stackgis\data\test.shp"

if arcpy.Exists(shapefile):
    arcpy.management.Delete(shapefile)
@moosetraveller
moosetraveller / calendar_to_csv.py
Created November 16, 2021 15:35
Get Appointments from Outlook
import pandas as pd # pip install pandas
import win32com.client # pip install pywin32
import datetime as dt
def get_calendar(begin, end):
""" Source: https://pythoninoffice.com/get-outlook-calendar-meeting-data-using-python """
outlook = win32com.client.Dispatch('Outlook.Application').GetNamespace('MAPI')
calendar = outlook.getDefaultFolder(9).Items
calendar.IncludeRecurrences = True
@moosetraveller
moosetraveller / python_path.py
Last active August 4, 2022 10:44
Get Python Path to Executable within the QGIS Python Console
# using sys.path
# see also https://github.com/qgis/QGIS/issues/45646#issuecomment-950339443
import os
import sys
import subprocess
def find_python():
if sys.platform != "win32":
@moosetraveller
moosetraveller / first-day-of-previous-month.md
Last active March 6, 2025 11:10
How to get the first day of the previous month using Python?

How to get the first day of the previous month using Python?

Using datetime

from datetime import date

d = date(2019, 1, 8)  # date.today()

month, year = (d.month-1, d.year) if d.month != 1 else (12, d.year-1)

last_month = d.replace(day=1, month=month, year=year)
@moosetraveller
moosetraveller / trips.md
Last active October 14, 2021 00:41
Create Lines from a CSV File

Environment

Using Miniconda (without ArcGIS Pro)

  • Download and install Miniconda3 (https://docs.conda.io/en/latest/miniconda.html)
  • Create a new Conda environment with conda create --name gis
  • Activate Conda environment with conda activate gis
  • Install required Python packages with conda install shapely pandas geopandas
  • Use this Conda environment in your development environment

Using ArcGIS Pro Conda Environment

  1. Open ArcGIS Pro
@moosetraveller
moosetraveller / settings.json
Created October 11, 2021 00:14
VSCode Terminal Settings with Activated Python Environment
{
"terminal.integrated.profiles.windows": {
"CMD with activated Python env": {
"path": [
"${env:windir}\\System32\\cmd.exe"
],
"args": [
"/k",
"env\\Scripts\\activate"
],