ETech 2009 Record

From The Top

apt-get update
  apt-get install postgresql-8.3-postgis libapache2-mod-python python-gdal
  apt-get install python-mapnik osm2pgsql python-setuptools tilecache gdal-bin
  apt-get install less zip unzip screen vim imagemagick
  easy_install nik2img
  mkdir /var/www/etech && ln -s /var/www/etech  ~/etech

Section One: Shapefiles

cd ~/etech && mkdir -p 01-shapefiles/start 01-shapefiles/end && cd 01-shapefiles/start
  curl -O
  ogr2ogr -t_srs "+proj=latlong +datum=WGS84 +no_defs" states.shp fe_2007_us_state.shp

New end of /etc/postgresql/8.3/main/pg_hba.conf:

# Database administrative login by UNIX sockets
  local   all         postgres                          trust
  # "local" is for Unix domain socket connections only
  local   all         all                               trust
  # IPv4 local connections:
  host    all         all          trust
  # IPv6 local connections:
  host    all         all         ::1/128               trust
  # everyone everywhere
  host    all         all             trust

New listen addresses in /etc/postgresql/8.3/main/postgresql.conf:

listen_addresses = '*'                  # what IP address(es) to listen on;
                                          # comma-separated list of addresses;
                                          # defaults to 'localhost', '*' = all

Steps, for them:

  1. Open in QGIS, poke around and see
  2. -m style.xml -e "-130,26,-60,50" -o map-latlong.png
  3. edit style.xml, add spherical mercator projection
  4. -m style.xml -e "-130,26,-60,50" -o map-mercator.png
  5. Add line symbolizer to style.xml, futz with colors

Section Two: PostGIS

cd ~/etech && mkdir -p 02-postgis/start 02-postgis/end && cd 02-postgis/start
  cd /usr/share/postgresql-8.3-postgis && createdb -U postgres etech_02_start && createlang -U postgres plpgsql etech_02_start && psql -U postgres etech_02_start < lwpostgis.sql
  cd /usr/share/postgresql-8.3-postgis && createdb -U postgres etech_02_end && createlang -U postgres plpgsql etech_02_end && psql -U postgres etech_02_end < lwpostgis.sql
  cd ~/etech/02-postgis/start && cp -v ../../01-shapefiles/end/states.* ./

Steps, for them:

  1. shp2sql -D -d -I states.shp states > states.sql
  2. psql -U postgres etech_02_start < states.sql
  3. View postGIS data in QGIS
  4. Modify style.xml from previous example to use PostGIS instead
  5. Modify style.xml to highlight CA with a filter
  6. Render zoomed into CA: -m style.xml -e "-125.5,31.7,-113.3,42.6" -s 500,500 -o map.png

Section Three: OSM Data

cd ~/etech && mkdir -p 03-osm/start 03-osm/end && cd 03-osm/start
  cd /usr/share/postgresql-8.3-postgis && createdb -U postgres etech_03_start && createlang -U postgres plpgsql etech_03_start && psql -U postgres etech_03_start < lwpostgis.sql
  cd /usr/share/postgresql-8.3-postgis && createdb -U postgres etech_03_end && createlang -U postgres plpgsql etech_03_end && psql -U postgres etech_03_end < lwpostgis.sql
  cd ~/etech/03-osm/start # && cp -v ../../02-postgis/end/style.xml ./
  osm2pgsql --create --latlong -U postgres -d etech_03_end sanjose.osm.xml # for later

Steps, for them:

  1. osm2pgsql --create --latlong -U postgres -d etech_03_start sanjose.osm.xml
  2. Modify style.xml by adding data source with all planet_osm_line
  3. Render zoomed into CA: -m style.xml -e "-125.5,31.7,-113.3,42.6" -s 500,500 -o map.png
  4. Render zoomed into San Jose: -m style.xml -e "-121.945,37.312,-121.886,37.355" -s 500,500 -o map-sanjose.png
  5. Mess around with road casings, until it begins to look good.
  6. Add separate layers for motorways to show how draw order works

Section Four: GDAL

cd ~/etech && mkdir -p 04-gdal/start 04-gdal/end && cd 04-gdal/start

For them:

  1. Download start/sanjose1961a-small.jpg, if you have an image editor look at x, y coords and compare to
  2. Make the virtual raster:
    gdal_translate -a_srs "+proj=latlong +datum=WGS84 +no_defs" \
      -gcp 1012 7172 -121.992359 37.262953 \
      -gcp 5122 7147 -121.808896 37.2636876 \
      -gcp 2779 1556 -121.91408 37.46358387 \
      -gcp 5328 1856 -121.799412 37.4526486 \
      -gcp 3532 4491 -121.879920959 37.35862842 \
      -of VRT sanjose1961a.jpg sanjose1961a.vrt
  3. Inspect the XML of the virtual raster
  4. Get extent from nik2img with -v flag: -v -m style.xml -e "-121.945,37.312,-121.886,37.355" -s 500,500 -o map-sanjose.png
  5. Project the VRT into a mercator GeoTIFF:
    gdalwarp -t_srs "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs" -of GTiff sanjose1961a.vrt sanjose1961a.tif
  6. Crank out a sample of the GDAL image for just downtown, using map extent from most recent nik2img:
    gdalwarp -te -13574855.3048 4482411.40257 -13568287.4548 4488979.25253 -ts 500 500 sanjose1961a.tif map-small.tif && convert map-small.tif map-small.jpg
  7. Add the new GeoTIFF to style.xml (between states and roads) after getting its bounds from gdalinfo:
    <Layer srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids´┐╝=@null +no_defs">
      <Parameter name="type">raster</Parameter>
      <Parameter name="file">sanjose1961a.tif</Parameter>
      <Parameter name="lox">-13585226.492</Parameter>
      <Parameter name="loy">4469036.036</Parameter>
      <Parameter name="hix">-13549981.670</Parameter>
      <Parameter name="hiy">4511736.878</Parameter>
  8. Re-render San Jose and CA with new raster layer included: -v -m style.xml -e "-121.945,37.312,-121.886,37.355" -s 500,500 -o map-sanjose.png -v -m style.xml -e "-125.5,31.7,-113.3,42.6" -s 500,500 -o map-raster-cali.png
  9. Modify tilecache.cfg with new layer
  10. Modify style.xml with green for freeways, roads like "%th St" to show other Mapnik features.
  11. map.html slippy map with Google API.