Translating VMAP data

Recently, I was tasked with utilizing vector data supplied by NIMA in VMAP format for a project. If you have ever dealt with VMAP data (vector product format), as used by NIMA, you know that the format is not for the feint of heart. As a result, I decided to import the data into a PostgreSQL database and utilize PostGIS to easily query the data. As I could not find a simple tutorial online, and since there were some gotchas to look out for, I decided to put one here.

Without going too much into what VMAP data is, it consists of vast amounts of vector data spread over a large number of files organized into coverages and then further broken down to feature classes (e.g., coverage = "Vegatation", feature class="Orchards"). The base directory consists of a library folder, reference folder, and the library data in a file called "DHT" (no extension). Within the library folder, there is a hierarchy of files and directories for each coverage (e.g., the "veg" folder contains vegetation, with files containing feature classes like orchards, swamps, etc.). The files are pretty much unreadable without digging into the VMAP specification.

So how do you go about extracting this data? The easiest way is to download the excellent FWTools open source library. While FWTools contains a variety of subpackages, we are most interested in the GDAL/OGR to read the VPF format used in VMAP.

After installing the library, start the FWTools Shell. While FWTools can import data directly into PostgreSQL, I needed to move this data to a number of servers, so I decided to take the approach of going from VMAP to Shapefiles, and then Shapefiles to PostgreSQL SQL scripts. The command line function to do the first step of VMAP to Shapefile is to retrieve (1) the path of the VMAP library (the name of the "library" folder in the same level as the DHT file), (2) the path of the Shapefile you want to generate, (3) the name of the coverage, (4) the name of the feature class, and (5) the family of data (line, area, point, text).

Once you have this data, you need to use the OGR2OGR command line executable to extract and convert the feature class. The format is as follows: ogr2ogr "{shape file name and path}" "gltp:/vrf/{path to library}" {feature class}@{coverage}(*)_{family}. Of course you need an example for that, so
ogr2ogr "C:\MyPath\Shape.shp" "gltp:/vrf/C:/Projects/Ogr/Path/To/File/vmap/library" orchardsa@veg(*)_area
will extract the orchard data (areas only) from the file "C:\Projects\Ogr\Path\To\File\vmap\library\veg\orcharda.aft" .

Once you have the data in Shapefile format, you can use the PostgreSQL/PostGIS utility "shp2pgsql" to convert the data to a series of SQL scripts. This command line tool is available in the PostgreSQL bin directory. The format is
shp2pgsql -c -s 4326 "C:\MyPath\Shape.shp" public.orchard_data > "C:\MyPath\OrchardCreateScripts.sql".

Now that we have the SQL script at "C:\MyPath\OrchardCreateScripts.sql", we can import the data into the PostgreSQL database of our choosing using pgAdmin. In this case, it will create a table called public.orchard_data, but you can change this with the command line options (type "shp2pgsql /?" to see the options).