Skip to content

Instantly share code, notes, and snippets.

View phargogh's full-sized avatar

James Douglass phargogh

View GitHub Profile
@phargogh
phargogh / writeblockindex.py
Created March 12, 2020 19:49
Write raster block/tile indexes to a new raster
import os
import logging
logging.basicConfig(level=logging.DEBUG)
import pygeoprocessing
from osgeo import gdal
import numpy
def doit():
@phargogh
phargogh / cython-updates.patch
Created March 10, 2020 23:38
Getting linetracing to work with cython
diff --git a/setup.py b/setup.py
index 46be1b36..67b5a1df 100644
--- a/setup.py
+++ b/setup.py
@@ -96,6 +96,8 @@ setup(
Extension(
name="natcap.invest.sdr.sdr_core",
sources=['src/natcap/invest/sdr/sdr_core.pyx'],
+ define_macros=[('CYTHON_TRACE', '1')],
+ compiler_directives={'linetrace': True},
@phargogh
phargogh / zip.ps1
Created March 10, 2020 17:40
Powershell shim for replicating zip -r
# A wrapper around the powershell equivalent of zipping functionality.
# This script takes 3 parameters:
# --> whether to recurse (this is ignored, but we have to take it anyways for compatibility)
# --> The target archive path
# --> The folder to zip.
#
param (
[Parameter(Mandatory=$false, ValueFromPipeline=$false, ParameterSetName='r')]
[switch]
$recurse,
@phargogh
phargogh / invest-autotest.yml
Created February 27, 2020 17:52
GitHub Actions YML to run the InVEST autotest suite
name: Run InVEST Autotest
steps:
windows-invest-autotest:
name: Run InVEST-autotest (windows)
needs: build-windows-binaries
runs-on: windows-latest
env:
PYTHON_VERSION: 3.7
PYTHON_ARCH: x64
steps:
@phargogh
phargogh / branchfind.sh
Created February 13, 2020 18:21
Script to merge multiple heads on closed mercurial branches
#!/bin/bash
# NOTE: This version of this script was adapted from
# https://gist.github.com/FernFerret/3178035, with a few minor revisions
# for efficiency and clarity of output.
# This simple script will look at all named branches in a given repository
# and print out any branch that contains multiple open heads. This is useful
# to see if your repository is clean or if someone has pushed multiple
# anonymous branches.
@phargogh
phargogh / README.rst
Created February 11, 2020 02:33
Mercurial (hg) commands I usually need and regularly forget

Which files changed on my feature branch?:

hg status --rev .:develop

Which commits belong to a named branch?:

hg log -r "branch(<branchname>) and 0:"

What heads exist on the current repository that have not been merged into the develop branch?:

@phargogh
phargogh / man2pdf.sh
Created February 5, 2020 03:16
Convert a manpage to PDF
#!/bin/bash
#
# Convert a program's manpage to PDF.
# Assumes that the program has a manpage for it and that ps2pdf14 is installed (part of a latex package).
#
# Example usage:
# $ ./man2pdf bash
${1?"Usage: $0 PROGRAMNAME"}
man -t $1 | ps2pdf14 - $1_manpage.pdf
@phargogh
phargogh / README.txt
Created February 5, 2020 03:13
Create an aspatial geopackage table
In the latest version of watershed delineation, a single watershed
seed may be associated with many features of interest. For this reason,
we need to be able to associate the attributes of the features of interest
with each of the seeds derived from the features.
The GeoPackage driver (https://www.gdal.org/drv_geopackage.html) supports
'aspatial' tables in GDAL>2.0, and 'attribute' data types in GDAL>2.2.
The two prototypes needed are:
* How do we make an aspatial table in GDAL 2?
@phargogh
phargogh / diffgdalinfo.sh
Created February 5, 2020 03:11
Compare the output of two gdalinfo calls via diff
#! /bin/bash
diff <(gdalinfo $1) <(gdalinfo $2)
@phargogh
phargogh / fix_geometry.py
Created February 5, 2020 03:10
Demo: Fixing invalid geometries
# encoding=UTF-8
"""fix_geometry.py"""
def doit(original_geometry):
if not original_geometry.IsValid():
if 'POLYGON' in original_geometry.GetGeometryName():
# Geometries that are only self-intersecting can be fixed by
# Buffering by 0.
buffered_geom = original_geometry.Buffer(0)