Skip to content
Archive of posts filed under the Python category.

ACS 5yr Viz Processing

A systematic way to choose, extract and visualize data from the massive American Community Survey 5 Year census product is a challenge. I have written python code to ingest raw inputs into tables, and a small relational engine to handle the verbose naming. An extraction and visualization process is underway… something like the following: 0) […]

Calling Bluff

Two years ago a hard disk arrived on the desk of a colleague, from persons claiming to have some kind of parcel data “for every state in the US.” Naturally, being very skeptical and at the same time, just a bit eager to show off open source tools on linux, I whipped up a script […]

ST_DWithin on a Grid

As part of a larger inquiry, I wanted to know how ST_DWithin() behaved on a regular grid – that is, what is the relationship of the input radius, and the number of grid cells that could be selected in the result. The manual implies that it is an intersects relationship not a contains relationship, and […]

gdal_retile retooled

Recently the task of combining and tiling some large GeoTIFFs came up.. so began an investigation of adding threading support to gdal_retile.py Unfortunately, it is widely known that python is not the best environment for multithreaded work, due to the global interpreter lock (GIL). However, while building threading support for some routine postgis tasks recently, […]

PostGIS subtraction

Threading in python and calling out to PostGIS in each thread can work well. Here is an example of using python’s Queue and threading.Thread to break up a large spatial workload into pieces. It turns out that many spatial data problems are naturally parallelizable, and this is one of them. Per the PostGIS manual, subtraction […]

One More Graph, SQL to R

import psycopg2 conn = psycopg2.connect( “dbname=example_db” ) curs = conn.cursor() tSQL = ”’ select emp_gden_min, res_units_gden_min, emp_gden_max, res_units_gden_max from p_translation_table; ”’ curs.execute( tSQL ) resT = curs.fetchall() from rpy2.robjects.packages import importr grdevices = importr( ‘grDevices’ ) grdevices.pdf(file=’/home/shared/aab.pdf’) r_plot_str = ”’ plot(c(0,1000),c(0,2000),type=”n”,log=”xy”,xlim=c(0.1,1000),ylim=c(0.1,2000), xlab=”employment”, ylab=”residence”) ”’ rpy2.robjects.r( r_plot_str ) tC = 0 for n in resT:   tStr2 […]