Installing PostGIS TIGER Geocoder

July 15th, 2012

Start and connect to a Ubuntu 12.04 vagrant instance.
$ sudo apt-get update && sudo apt-get upgrade
$ sudo apt-get install python-software-properties unzip
$ sudo apt-add-repository ppa:sharpie/for-science
$ sudo apt-add-repository ppa:sharpie/postgis-nightly
$ sudo apt-get update
$ sudo apt-get install postgresql-9.1-postgis
$ sudo apt-get install postgresql-contrib-9.1
$ http://www.postgis.org/download/postgis-2.0.2SVN.tar.gz
$ tar -zxvf postgis-2.0.2SVN.tar.gz
$ cd postgis-2.0.2SVN/extras/tiger_geocoder/tiger_2010

Set up an empty PostGIS database:
$ sudo su - postgres
$ createuser --superuser geocoder
$ createdb --owner=geocoder geocoder
$ psql geocoder
geocoder=# \password geocoder
geocoder=# CREATE EXTENSION postgis;
geocoder=# CREATE EXTENSION fuzzystrmatch;
geocoder=# ALTER DATABASE geocoder SET search_path=public, tiger;
geocoder=# \q
$ ./create_geocode.sh

Verify that address normalization works:
$ psql geocoder
geocoder=# SELECT pprint_addy(normalize_address('202 East Fremont Street, Las Vegas, Nevada 89101')) As pretty_address;
pretty_address
-----------------------------------
202 E Fremont St, Vegas, NV 89101
(1 row)

Generate a loader script:
psql geocoder -c "SELECT loader_generate_script(ARRAY['IL'], 'sh');" -A -o ILdata.sh

Run the loader script:
$ psql geocoder -c "SELECT loader_generate_script(ARRAY['IL'], 'sh');" -A -o ILdata.sh
$ chmod +x ./ILdata.sh

Edit the ILdata.sh file:
- Remove the first line that says “loader_generate_script”
- Change “export PGBIN=” to “export PGBIN=/usr/bin/”
- Change PGUSER and PGPASSWORD to “geocoder”
- Change all references to /temp to /tmp

Run the revised ILdata.sh file:
$ ./ILdata.sh

Fill in missing indexes:
$ psql geocoder -c "SELECT install_missing_indexes();"

Test that geocoding works:
geocoder=# SELECT g.rating, ST_X(g.geomout) As lon, ST_Y(g.geomout) As lat,
(addy).address As stno, (addy).streetname As street,
(addy).streettypeabbrev As styp, (addy).location As city, (addy).stateabbrev As st,(addy).zip
FROM geocode('100 Hinman Ave, Evanston, IL 60202') As g;

rating | lon | lat | stno | street | styp | city | st | zip
--------+-------------------+------------------+------+--------+------+----------+----+-------
9 | -87.6774282132404 | 42.033033193792 | 801 | Hinman | Ave | Evanston | IL | 60202
11 | -87.6760688731306 | 42.0493828931995 | 1801 | Hinman | Ave | Evanston | IL | 60201
(2 rows)

Source Links: http://trac.osgeo.org/postgis/wiki/UsersWikiPostGIS20Ubuntu1204, http://www.vagrantbox.es/, http://wiki.bitnami.org/Components/PostgreSQL/PostGIS_Quick_Start_Guide#How_can_I_install_Tiger_Geocoder.3f

Screen Rotation in a Dialog Themed Activity

September 1st, 2011

One of the apps I am writing uses an Activity that is themed with the @android:style/Theme.Dialog theme. This means that when the user enters the new dialog-themed activity the previous activity can still be seen in the background of the current activity. Not only can the user see the activity in the background but it still receives Activity lifecycle events before the Dialog-themed activity in front of it.

This has implications in screen rotation and other configuration changes: I had some code that starts my dialog-themed activity when a certain condition was met in the onResume() callback for the background activity. Every time I did a screen rotation the condition was met and created a new activity with a startActivity() call. This caused an activity/memory leak and some very confusing behavior.

I solved it by adding the FLAG_ACTIVITY_REORDER_TO_FRONT to the intent I used to start the activity. Now it will re-use the dialog-themed activity on screen rotation rather than trying to create a new one every time.

Android Sources

March 16th, 2011

There are several posts online about how to obtain the Android source code for viewing in Eclipse. This one is great, but it hasn’t been updated in a long time. As a result, I thought I’d take the time to build .zip files using the tools on that page for the more modern Android SDKs. Here are the .zips for your consumption:

All of these were built to be attached to the android.jar that exists in your Eclipse project, so you don’t need to unzip them at all, simply attach them to the JAR following the process on the page linked above.

mod_perl2 and Apache::AuthenNIS

April 18th, 2007

This has been a thorn in my side 3 times now while at work: how to get the aging Apache::AuthenNIS mod_perl module ported to work with mod_perl2 and Apache2. There is a slightly helpful thread here, but it didn’t fully help me. Eventually, I figured it: you have to port the module form within CPAN, then install it.

Here’s what I did:

  1. perl -MCPAN -e 'shell'
  2. get Apache::AuthenNIS
  3. look Apache::AuthenNIS
  4. Replace AuthenNIS.pm with Patched Apache::AuthenNIS.
  5. exit
  6. install Apache::AuthenNIS

From there, you follow the rest of the tutorial on Apache and NIS authentication here.

Hopefully this information is helpful to someone out there doing a Google search.