Downloading the NACO A/FD

NACO publishes terminal area charts and the Airport Facility Directory (A/FD—also known as the green book) and has an online version of the PDFs. The only obvious way to access them is through a map interface. The interface works fine for the terminal area charts but is broken for the A/FD. It’s been broken for years and they don’t seem to have the expertise to fix it. The code is a bit convoluted and it’s on my list of things to decipher and fix. However, in the mean time I’ve provided a table by state to access the PDFs. It is located on the Touring Machine site at this link. The page provides links to the PDFs that are located on the NACO site. The NACO site uses an XML file to determine the page in the AF/D for each airport. Since XML is a very structured format, it is fairly straightforward to parse the file and convert it to useable HTML. The exact methods I’m using are specific to this file but the general process works on any XML file.

The first step in the process is to read the XML file. The address is http://naco.faa.gov/afd/afd_17DEC2009.xml, where the date changes every 56 days. Your browser won’t display the xml, but if you view the source and save it you can begin working with it. The first couple of times through I used BBEdit to convert the XML to HTML tables. There aren’t too many steps, but it makes sense to automate the process. Any program that supports regular expressions could be used and I chose sed because I’m familiar with it. Make sure that the CR/LF setting is changed to Unix or Mac if you aren’t working on a Windows machine. Character encoding should probably be set to Western (ISO Latin 1), since that’s how it was originally encoded.

#### Script to convert NACO A/FD to HTML tables
## Remove the first five lines of XML and creator information
1,5d

## The opening and closing tags aren't needed
/.*airports>/d

## Make each state a header tag
s/<location state="/<h1>/

## Set up the table for each state
s/">/<\/h1>\
<table width="100%" border="1"><tr><th>Airport Name<\/th><th>
City Name<\/th><th>ID<\/th><th>Navaid<\/th><th>pdf<\/th><\/tr>/

## Location is the demarcation for each state.
## Close the table and put an End of State line for splitting
s/<\/location>/<\/table>\
EOS/g

## Open and close the row for each airport or navaid
s/<airport>/<tr>/
s/<\/airport>/<\/tr>/

## Replace each of the following with td> to open and close the columns
s/aptname>/td>/g
s/aptcity>/td>/g
s/aptid>/td>/g
s/navidname>/td>/g

##The pdf tags are replaced with a link
s/<pdf>/<td><a href="http:\/\/naco.faa.gov\/pdfs\//
s/<\/pdf>/">pdf<\/a><\/td>/

## Change Tabs to spaces
s/  /  /g

Run this code on the raw XML file and then split it at the EOS line. I use a script to do it.

#!/bin/bash
FILENAME=NACO_17DEC2009_
INDEX=1
while read
do
 if [[ "$REPLY" = "EOS" ]]
 then
  (( INDEX++ ))
 else
  echo "$REPLY" >> /Users/username/Desktop/DEC/$FILENAME$INDEX
 fi
done

You could modify it to take an argument but I just feed the input file to it.

./SplitNaco.sh < afd_17DEC2009.xml.html

You can download the scripts from here.

One thought on “Downloading the NACO A/FD”

  1. Excellent! I’m developing an Android flight planning app and this is going to come in handy big time!

    One question: how did you figure out where their XML file was kept? I couldn’t find it referenced anywhere on the NACO site. I need to find a similar listing of TPP PDFs and can’t seem to find the appropriate XML file on their servers.

    [I found this XML file by looking at the page source code. An XML file is not referenced in the source of the d-TPP page. They definitely have a different method for displaying the results, since they actually display on my Mac.

    You might be able to figure out how to display the PDFs by looking at their name. e.g. http://avn.faa.gov/d-tpp/1002/06141R1.PDF refers to the chart header AL-6141 Rw1., http://avn.faa.gov/d-tpp/1002/00070RZ15.PDF refers to AL-70 GPS Z Rwy 15 – JS]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.