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 / 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

Apparently even a difference of the least precision of the upper left-hand corner causes an alignment error in PostGIS. Consider this example, where I am comparing a land cover raster subset by an MTBS raster and the MTBS raster itself (with the goal being to add the latter to the former, creating the "burned" land cover).

```
SELECT ST_MetaData(r1.rast)
  FROM
(SELECT rast
   FROM geowepp_burnedarea
  WHERE geowepp_burnedarea.rid = 2) r1
UNION
SELECT ST_MetaData(r2.rast)

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
# Credit goes to my colleague Tyler (http://tylerickson.blogspot.com/2011/09/installing-gdal-in-python-virtual.html)
ENVDIR=/usr/local/pythonenv/
ENVNAME=nasabaer-env
OWNER=arthur
# Install GEOS if necessary
# sudo apt-get libgeos-3.2.2 libgeos-dev
# Install GDAL on the system
@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

Introduction

Drivers

These are the exact names that OGR recognizes; in parentheses are the file extensions, not to be included in the driver name:

  • ESRI Shapefile (*.shp)
  • KML (*.kml)
  • AVCE00 (*.e00)
  • AVCBin
@arthur-e
arthur-e / Stats.js
Last active December 26, 2015 22:08 — forked from clauswitt/Stats.js
A JavaScript function ("class") that returns an object which can be used to calculate statistics on the the passed numeric Array.
/**
Returns an object which can be used to calculate statistics on the
the passed numeric Array.
*/
var Stats = function (arr) {
arr = arr || [];
// http://en.wikipedia.org/wiki/Mean#Arithmetic_mean_.28AM.29
this.arithmeticMean = function () {
var i, sum = 0;
@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

Managing the PostgreSQL Service

The service name is postgresql and it accepts the usual commands for a background service:

  • start
  • stop
  • restart
  • status
@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 = ''