Skip to content

Instantly share code, notes, and snippets.

View arthur-e's full-sized avatar

K. Arthur Endsley arthur-e

View GitHub Profile
@arthur-e
arthur-e / graham_hull.py
Last active April 7, 2024 17:19 — forked from tixxit/hull.py
Graham's scan convex hull algorithm, updated for Python 3.x
def convex_hull_graham(points):
'''
Returns points on convex hull in CCW order according to Graham's scan algorithm.
By Tom Switzer <thomas.switzer@gmail.com>.
'''
TURN_LEFT, TURN_RIGHT, TURN_NONE = (1, -1, 0)
def cmp(a, b):
return (a > b) - (a < b)
@arthur-e
arthur-e / geodesic.py
Created August 22, 2013 21:28
A basic example of creating a geotrajectory visualization in KML, with a great circle drawn between two points of interest. Requires geodesic.py, a script that provides a function "tweensegs."
import math
def tweensegs(longitude1, latitude1, longitude2, latitude2, num_of_segments):
ptlon1 = longitude1
ptlat1 = latitude1
ptlon2 = longitude2
ptlat2 = latitude2
numberofsegments = num_of_segments
onelessthansegments = numberofsegments - 1
@arthur-e
arthur-e / GeoJSON_TopoJSON.md
Created January 18, 2014 20:14
Installation and use of topojson and geojson command line interfaces for simplifying OGC geometries

Installation

# Requires Node.js and NPM
sudo npm install -g topojson

# Install the geojson-cli
sudo npm install -g geojson

Tasks

@arthur-e
arthur-e / notes.md
Last active March 2, 2022 07:19
Ubuntu for GIS Installation and Setup

Post-Installation Fixes and Setup

# Install compilers and linking tools; other tools
sudo apt-get install g++ swig curl build-essential python-all-dev

# Install package manager
sudo apt-get install synaptic

# Install Unity customization tool

sudo apt-get install unity-tweak-tool

@arthur-e
arthur-e / LEDAPS_build_from_source.sh
Created May 6, 2015 15:57
A walkthrough for building LEDAPS 2.2.0 and its dependencies from source on Ubuntu GNU/Linux 14.04
USERNAME=heyyouguys
# NOTE: Could not determine which jpeg library should be installed; it's probably installed by default
sudo apt-get install libtiff5 libtiff5-dev libgeotiff2 libgeotiff-dev libxml2 libxml2-dev
# http://www.hdfgroup.org/release4/obtainsrc.html
sudo mkdir /usr/local/hdf4 && sudo chown $USERNAME /usr/local/hdf4 && cd /usr/local/hdf4
wget http://www.hdfgroup.org/ftp/HDF/HDF_Current/src/hdf-4.2.11.tar.gz
tar -xzvf hdf-4.2.11.tar.gz
cd hdf-4.2.11

Overview

In general, it seems there are roughly five (5) ways to get "file data" (e.g. a GeoTIFF) out of a PostGIS geoprocessing workflow:

  • Export just the raster field as an ASCII grid
  • Connect to the database using a desktop client (e.g. QGIS) [1]
  • Use a procedural language (like PLPGSQL or PLPYthon) [2]
  • Use the COPY declaration to get a hex dump out and convert it to a binary file
  • Fill a 2D NumPy array with a byte array and serialize it to a binary file using GDAL or psycopg2 [3, 4]
  • Use ST_AsTiff() or the more general ST_AsGDALRaster() to get a byte array, which can be written to a binary file
@arthur-e
arthur-e / Django_CSV_Loader.py
Created February 17, 2014 16:41
An example Django command (through the django-admin.py or manage.py interface) for loading in generic CSV data; a design pattern that should apply well to just about any delimited data.
import csv
from django.core.management.base import BaseCommand, CommandError
from django.core.exceptions import ValidationError, ObjectDoesNotExist
from django.db.models.fields import FieldDoesNotExist
from scour_server.nbi.models import Bridge
class Command(BaseCommand):
args = '<path>'
help = ''
@arthur-e
arthur-e / temperature.py
Created May 18, 2017 19:10
An example Python script for the Software Carpentry Python lesson (https://github.com/arthur-e/swc-workshop/tree/master/python-climate)
'''
Reports the min and max July temperatures for each file
that matches the given filename pattern.
'''
import csv
import os
import sys
import glob
@arthur-e
arthur-e / install-tilemill-latest.sh
Created October 5, 2012 13:27 — forked from springmeyer/install-tilemill-latest.sh
Install bleeding edge TileMill, Node.js, and Mapnik
# Clear out any old ppa's that might conflict
sudo rm /etc/apt/sources.list.d/*mapnik*
sudo rm /etc/apt/sources.list.d/*developmentseed*
sudo rm /etc/apt/sources.list.d/*chris-lea*
# Add new ppa's
echo 'yes' | sudo apt-add-repository ppa:chris-lea/node.js
echo 'yes' | sudo apt-add-repository ppa:mapnik/nightly-trunk
# Update
@arthur-e
arthur-e / raster_learning.py
Created March 10, 2017 21:06
An example Python script of using scikit-learn to learn water from non-water pixels
'''
A module for machine learning on Landsat data; implemented and tested,
specifically, for learning water areas on an image. Performance so far:
Gaussian naive Bayes (where validation data chosen by the hydro mask):
Mean precision: Not water=0.9997, Water=0.3090
Mean recall: Not water=0.9787, Water=0.9763
Gaussian naive Bayes (where validation data inspected in Google Earth):
Mean precision: Not water=0.9675, Water=1.0000