Skip to content

Instantly share code, notes, and snippets.

View moosetraveller's full-sized avatar

Thomas Zuberbühler moosetraveller

View GitHub Profile
@moosetraveller
moosetraveller / cheat-sheet-arcgis-js-api.md
Created August 12, 2021 22:59
ArcGIS for JavaScript Cheat Sheet

Add Tooltip to Feature in GraphicsLayer

Note: Works with ArcGIS for JavaScript 3.35, should work with 4.x

let layer = new GraphicsLayer();

layer.on("graphic-node-add", (event) => {

  const title = document.createElementNS("http://www.w3.org/2000/svg", "title");
  
  const isRestaurant = event.graphic.attributes.isRestaurant;
@moosetraveller
moosetraveller / fetch.md
Last active February 28, 2022 18:19
Using fetch with async/await

Cheat Sheet of Thomas Zuberbuehler :)

Retrieve GET

async function retrieveUser(firstName) {

    const response = await fetch(url + "?" + new URLSearchParams({
        firstName: firstName,
    });
 
@moosetraveller
moosetraveller / convert_pdf.py
Last active September 22, 2021 22:34
Convert a PDF File to Images
"""
Converts PDF pages to images.
```python
pip install PyMuPDF
pip install PySimpleGUI
```
:See also:
https://pymupdf.readthedocs.io/en/latest/faq.html
@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"
],
@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 / 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 / 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 / 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 / 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 / rmarkdown-open-link.md
Last active February 23, 2022 02:23
How to globally open Links in new tabs