MCD from Tiger

Thanks to Jim Hinthorne at CWU for answering my question about
extracting MCDs from TIGER data. The solution was to use awk (and
substr) to find which MCD left and right fields differed--if they
differed, then this line is a boundary. Extract the TLIDs (TIGER Line
Id's) for these lines and use the tlid=file option for v.in.tig.basic.

Now, if anyone knows of a way to relate MCD (township) records in
TIGER/Geographic Names Files to Type P records, please share. I'm
still pouring through Chapter 6 of the TIGER stuff, but for now I've
got all these pretty polygons but no labels.

Thank ye,
Darrell
--
James Darrell McCauley, PhD http://soils.ecn.purdue.edu/~mccauley/
Dept of Agricultural Engineering mccauley@ecn.purdue.edu
Purdue University new-> tel: 317.494.1198 fax: 317.496.1115

James Darrell McCauley (mccauley@ecn.purdue.edu) writes to grassu-list
on 5 March 1995:

Now, if anyone knows of a way to relate MCD (township) records in
TIGER/Geographic Names Files to Type P records, please share. I'm
still pouring through Chapter 6 of the TIGER stuff, but for now I've
got all these pretty polygons but no labels.

after some hacking, I was able to solve my own problem (it's not
efficient or pretty--the faint-of-heart may leave the room now).

Results are in the format:

         <easting>|<northing>|#FIPS-55-code "Geographic Name"

This script converts LL to UTM and would thus need
to be modified if you are working in LL.

Appended, for the archives, is my approach.

Darrell

#!/bin/sh
# I call this little diddy "s.in.tig.mcd.labels"
#
# This is a quick hack to import label points for MCDs polygons as a
# GRASS sites list from TIGER data. There may be problems where the
# label point lies ON a polygon node and not INTERNAL to the polygon.
# See page 27 of the tiger.RIM tutorial
#
# If someone wants to add bells-n-whistles necessary to make this
# a bona fide GRASS Shell Script, be my guest.
#
# It's not pretty, but...
#
# Author:
# James Darrell McCauley, PhD http://soils.ecn.purdue.edu/~mccauley/
# Dept of Agricultural Engineering mccauley@ecn.purdue.edu
# Purdue University tel: 317.494.1198 fax: 317.496.1115
#
# Date: 4 March 1995
#
# These variables need to be set. the first four are tiger files
# and the last is the sites file.
# e.g. typeone=/cdrom/tiger/18/085/tgr18085.f51
#
typeone=tgr18085.f51
typei=tgr18085.f5i
typep=tgr18085.f5p
name=../tgr92s18.nam
sites=koscuisko.mcd

# note: if your system doesn't have printf, use 'echo -n'
PRINT=printf

$PRINT "[Finding MCD boundaries in Record Type 1..."
awk '{if (substr($0,141,5) != substr($0,146,5)) \
     printf "%d %d %d\n", substr($0,141,5),substr($0,146,5),substr($0,6,10);}'\
$typeone | sort | uniq | \
awk 'BEGIN{pa=pa=0;} {if ($1!=pa && $2!=pb) print $0; pa=$1; pb=$2; }' |\
awk '{print $1,$3,"L"; print $2,$3, "R"}' | sort | \
awk 'BEGIN{pa=pa=0;} {if ($1 != 0) if ($1!=pa && $2!=pb) print $0; \
      pa=$1; pb=$2;}' \
| awk '{print $2,$1,$3}' | sort > /tmp/phase1
echo "done]"
#
# results in TLID MCD B (either "L" or "R")
#
$PRINT "[Finding Polygon Identification Numbers in Record Type I..."
awk '{printf "%d %d %d\n", \
     substr($0,6,10),substr($0,27,10),substr($0,42,10)}' \
$typei | sort | join - /tmp/phase1 | \
awk '{if ($5=="L") print $2,$4; else print $3,$4}' | sort > /tmp/phasei
echo "done]"
#
# results in POLYID MCD
#
$PRINT "[Finding Label Coordinates in Record Type P..."
awk '{printf "%d %d %s\n",substr($0,16,10),substr($0,26,10),substr($0,37,8)}' \
$typep | sort | join - /tmp/phasei | \
awk '{printf "%f %f %d\n",$2/1000000.,$3/1000000.,$4}' | \
m.ll2u -z sph=clark66 | s.in.ascii tmpa$$
echo "done]"
#
# results in sites list with MCD as third column
#
# all that's left is to join this with the TIGER/Geographic Names
#
$PRINT "[Relating coordinates to FIPS 55-3 names of MCDs..."
s.out.ascii -d tmpa$$ | awk '{print $3,$1,$2}' | sort > /tmp/s
awk '{if (substr($0,1,7)=="0318085") print substr($0,8,5),substr($0,13,40)}' \
$name | join - /tmp/s | \
awk '{printf "%s %s #%s ",$(NF-1),$NF,$1; for(i=2;i<=NF-2;++i) \
printf "%s ", $i; printf "\n";}' | s.in.ascii $sites
echo "done]"
/bin/rm $LOCATION/site_lists/tmpa$$ /tmp/s /tmp/phasei /tmp/phase1
echo "Results are in "$sites
exit 0