Skip to content

Instantly share code, notes, and snippets.

View nickrsan's full-sized avatar

Nick Santos nickrsan

View GitHub Profile
@nickrsan
nickrsan / geopandas_in_the_browser.html
Last active June 1, 2023 12:51
A simple bit of code that uses PyScript and Piodide (under the hood) to run geopandas code in the browser. Not super interesting as is, but is a great starting point for further analysis and demos
<html>
<head>
<title>Mapping with PyScript</title>
<meta charset="utf-8">
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head>
<body>
<py-config>
@nickrsan
nickrsan / gcloud_storage_download.py
Created September 2, 2022 20:49
Download Items from Public Google Cloud Storage Bucket
import requests
import re
from pathlib import Path
def get_public_export_urls(bucket_name, prefix=""):
"""
Downloads items from a *public* Google Storage bucket without using a GCloud login. Filters only to files
with the specified prefix
:param bucket_name:
:param prefix: A prefix to use to filter items in the bucket - only URLs where the path matches this prefix will be returned - defaults to all files
@nickrsan
nickrsan / python_toolbox_parameters_as_dict.py
Created February 23, 2017 21:22
A Decorator for ArcGIS Python toolbox tools (their execute function) that makes the "parameters" parameter into a dictionary indexed by parameter name
"""
A Decorator for ArcGIS Python toolbox tools (their execute function) that makes the "parameters" parameter'
into a dictionary indexed by parameter name.
"""
from functools import wraps
def parameters_as_dict(f):
@wraps(f)
def wrapper(*args, **kwargs):
@nickrsan
nickrsan / cawater-links.md
Last active February 16, 2021 03:04 — forked from jdherman/cawater-links.md
links for california water data
@nickrsan
nickrsan / clone_hyperv_vm.ps1
Last active January 5, 2021 21:59
Clone Hyper-V VM to same server
$ProductionVMName = "DAP_Production"
$StagingVMName = "DAP_Staging"
$ExportFolder = "C:/HyperVExports" # I created a folder that removed all permissions for users - could add anyone with hyper-v permissions to a group with read/write here, along with System
$ExportToFolder = "$ExportFolder/$ProductionVMName/"
$ImportToFolder = "$ExportFolder/$StagingVMName/"
# caution, deletes existing exports in the next block. The try/catch doesn't work as intended. It was supposed to abandon it if it can't find the staging VMs, but proceeds through each step. Needs some work there.
try{
Get-VM -Name $StagingVMName # (not true, but this was the design): this will throw an exception if it doesn't exist, so the following lines in this block won't run
Stop-VM -Name $StagingVMName -TurnOff # Turn of the VM forcibly - it's fine if it gets corrupted - we're about to destroy it
@nickrsan
nickrsan / convert_mxd_to_aprx.py
Last active October 26, 2019 22:11
Converts all ArcMap documents (.mxd) in the script's folder into ArcGIS Pro Projects - requires amaptor (available via pip and at https://github.com/ucd-cws/amaptor). Has infrastructure to convert everything in a folder into the same project, but would need some retooling for it. Must be run from an ArcGIS Pro python environmental w/amaptor inst…
import os
import amaptor
base_folder = os.path.split(os.path.abspath(__file__))[0]
def make_project(item, base_folder=base_folder, skip_items=()):
"""
Makes the .mxd in item into an ArcGIS Pro project in the same folder with the same name
:param item: a full path to an ArcMap Document
# Calls the full pipeline needed to get a PDF with BibTex working
# pdfLaTeX->BibTeX->pdfLaTeX->pdfLaTeX
#
# Designed for use as a called script from TeXworks in the TeXLive distribution, but
# easily adapted for other workflows
# Make sure to set texlive_folder below!
# Adapted from https://tex.stackexchange.com/a/308727
import os
import sys
@nickrsan
nickrsan / get_papers.py
Created October 18, 2018 04:37
A script to pull papers from the CrossRef API (using package Habanero) and do frequency analysis on titles, authors, and institutions.
import os
from time import sleep
from csv import DictWriter, writer
import re
from habanero import Crossref # CrossRef API access
HABANERO_USERNAME = "" # provide an email address so they can contact you if your script misbehaves
ISSN = "" # ISSN of the journal to dump data for
BASE_FOLDER = os.path.dirname(os.path.abspath(__file__))
"""
Allows you to pass in a list of environments to get the values of, then pass it back in to reset.
Usage:
original_envs = store_environments(["workspace","mask"]) # gives back a dict with current environment values for workspace and mask
arcpy.env.workspace = my_workspace
arcpy.env.mask = my_raster
# some more code here to do some work with those environments
@nickrsan
nickrsan / error_check.py
Last active June 10, 2017 00:21
Error 999998 Test
"""
This script should cause error 999998 on ArcGIS 10.5 and ArcGIS Pro 1.4 if the mask environment is set using an invalid mask
and should succeed if no mask is set
"""
import tempfile
import numpy
import arcpy