Due: Monday April 7, 2003

Homework 4

  1. PROBLEM We want you to display the TIGER Lines for any County (e.g., Manhattan or Brooklyn). Here are the instructions: h4.pdf.
    There are also some notes on graphics here that you may find useful: drawImage.pdf.
  2. IMPLEMENTATION NOTES AND HINTS:
    -- There are two tasks called (a) and (b) in the homework specs. I will try to summarize the two tasks here.
    -- Here is another way to describe Task (a): you want to create a Postgres table called RT12 containing the information in RT1 and RT2 files of a single county. Here is the table you need:
    	     => CREATE TABLE RT12 (
    	            Tlid	INT,
    		    StartPt	POINT,
    		    EndPt	POINT,
    		    Details	POLYGON,	-- Kludge, it should be PATH
    		    BBox	BOX);		-- BBox is optional
    	
    Note that POINT, POLYGON and BOX are Postgres datatypes. We use POLYGON and not PATH because RTree index works on POLYGON but not PATH. A POINT is really a pair of (LONGITUDE, LATITUDE) integers as found in the TIGER data set. But note that internally, Postgres stores a point as a pair of floats (but that is fine with us). Below we discuss how to create RT12.
    -- Here is another way to describe Task (b): It has two steps called (b1) and (b2).
    -- Step (b1) amounts to retrieving from the RT12 Table a set of paths (corresponding to Tlid's), and drawing them in an image buffer called "bI". The substeps include (a) get a graphics object "g_bI" from bI, (b) create a GeneralPath called "p" for each Tiger line, and (c) call "g_bI.draw(p)" to draw p.
    -- Step (b2) amounts to transfering part of the image on "bI" to your panel. To do this, you override your paint (or paintComponent) method of your panel, If "g2" is the graphics object of your paint method, you will call one of the variants of "g2.drawImage((Image)bI, int, int,..., ImageObserver)" as described in the accompanying handouts.
    -- Perhaps the simplest way to load RT12 is to exploit a property of the RT2 files. Namely, the records corresponding to each TLID are stored in consecutive rows AND in the correct sequential order in the RT2 file. You can easily write a Reader.java program to load up the RT12 with the paths directly. [NOTE: This was discussed in class on April 14, so I will expand on that discussion here.] There are 3 steps:
    (I) Create by hand the table RT12 as outlined above.
    (II) Use our Reader program to load into RT12 the attributes Tlid, StartPt, EndPt.
    (III) Now write another version of Reader (call this DetailReader.java) which inserts the Detail POLYGON for each Tlid.
    How does DetailReader work? Well, it needs to read ahead in a line by line fashion, and as long as the Tlid is the same, it will keep building up the current Detail POLYGON. When this is complete, you insert this Detail POLYGON into the database (i.e., you UPDATE the row of RT12 corresponding to the current Tlid).
    -- NOTE: Another general solution would be to load RT1 and RT2 into Postgres, then use SELECT FROM a ``LEFT JOIN'' of RT1 and RT2 USING Tlid, and using the GROUP BY Clause, and ORDER BY Clause. But the problem here is that Postgres does not know how to append paths (or polygons), so you need to write your own Java Program for this. Hence it is not so attractive.
    -- Again, how do you enter a Lon/Lat pair as POINT into Postgres? Suppose the TIGER data gives you a Lon/Lat pair of strings, "-73901234" and "+40801234". Then, in forming your query, the point can be represented by the following string "(-73901234, 40801234)". Namely, you (1) eliminate any leading "+" sign from the Lon/Lat strings (but "-" sign should be left alone), and (2) make them into a point enclosed by a pair of parenthesis but separated by a comma. Postgresql will accept this as a POINT.
  3. INSTRUCTIONS FOR SUBMITTING THIS HOMEWORK:
    -- Send me an email with the SUBJECT "hw4" and with a tar file as attachment. Your tar file should contain (1) ALL java programs that are needed to run your code, (2) ALL data files (unless it is the TIGER files) and (3) a Makefile (similar to the one in hw1). I want to be able to type "make" or "make XXX" and immediately test your code. You should give sequential targets (XXX=one, two, etc). Remember that each target can have several equivalent names (e.g., "make one" could be equivalent to "make TigerLoader").
    -- Be sure to cc your email to EACH member of the team. This helps me when I send my response to the whole team.
    -- Please be sure that all your programs are minimally commented, and can compile before you submit.