Importing USGS 7.5min SDTS DEM into GRASS GIS

The instructions below are out of date.  They are retained here for now to find out if they are needed for other purposes. New users are directed towards Moritz Lennert's Quickstart to GRASS 5 guide and the r.in.gdal command, instead.

---------------------------

This shows how to import USGS 7.5min SDTS DEM data into grass. It includes where to find those pesky SDTS programs and FIPS libraries for working with the USGS data sets. Another method of importing the USGS 7.5min SDTS DEM files is by using the r.in.gdal command followed by the r.in.ascii command.

1) Acquire the fips123 library for the sdts utilities

The fips123 library (~619k) is available from:

ftp://sdts.er.usgs.gov/pub/sdts/software/fips123/fips123.ver104.tar.gz

Extract and compile the fips123 library:

 tar xzvf fips123.ver104.tar.gz
cd fips123
make
Once the make is complete, you should have a fips123.a library in the fips123 directory. You should move the library and include files to a more suitable location:

 cp f123inc/*.h /usr/local/include/
cp fips123.a /usr/local/lib/libfips123.a

2) Acquire the sdts utilities

A multitude of utilities for converting the SDTS format data into formats more readily importable into grass are available (~38k) from:

ftp://ftp.blm.gov/pub/gis/sdts/dem/sdtscode.zip

Extract the utilities:

 unzip -L sdtscode.zip

Applying the patch listed in Appendix A to the sdtscode source will help with case sensitivity issues on filenames. The datasets from USGS use all uppercase filenames. These patches force the use of all uppercase filenames.

 patch < sdtscode.patch

Compile the utilities. Appendix B shows the Makefile I used.

 make
Once the make is complete, you should have several utility programs in this directory. You should copy the utilites to a directory in your path:

 cp demout sdts2dem sdts2sur sdtsgrid sdts2arc sdts2rcz sdts2xyz /usr/local/bin/

3) Acquire data from the USGS website

Browse available data at:

http://edcwww.cr.usgs.gov/doc/edchome/ndcdb/ndcdb.html

In this case, our quest for Washington, DC data leads us to the "Washington West, DC" quad:
7.5 Minute Digital Elevation Model Data for N38.94 W77.08 and the actual data set:

http://edcftp.cr.usgs.gov/pub/data/DEM/7.5min/W/washington_west_DC/30.2.1.1191443.tar.gz

Download the data to a temporary directory, and extract the data files:

tar zxvf 30.2.1.1191443.tar.gz

NOTE: the files are extracted into the current directory.

4) Preprocess the USGS data

Convert the data to an ascii format (nearly) suitable for importing:

sdts2arc 9304 washdc L0 | tee washdc.txt

9304 - the numeric prefix on all files in the data set
washdc - the base of our output filename (the filename will be washdc.grd)
L0 - (ell zero) is the "cell id", usually L0, follows the CE in nnnnCExx.DDF
| tee washdc.txt - save a copy of the program output to washdc.txt

The output of sdts2arc will show the latitude and longitude of the quad:

LAT/LONG of the 7.5 USGS Quad
SW 315655.156250 4304843.500000
NW 315979.093750 4318716.500000
NE 326804.687500 4318471.500000
SE 326500.250000 4304598.500000

These are really the UTM coordinates for the corners of the quad. This will be needed when setting up location information for the data. Full output from the sdts2arc run for Washington West, DC in Appendix C.

Filter the void values from the arc file:

sed -e 's/ 32770/ 0/g' washdc.grd > washdc2.grd

[NOTE: grass5.0 may handle void values differently]

The argument after the -e is:

quote-slash-space-three-two-seven-seven-zero-slash-space-zero-quote

Edit the header information from the file to include the grass ascii raster file header information. Remove the original header data. Use your favourite plain text editor. The header should contain the followinng data (explained below):

north: 4318716.500
south: 4304598.500
west: 315655.1562
east: 326804.6875
rows: 471
cols: 372

The values are obtained from the LAT/LONG of USGS Quad of sdts2arc output. NOTE: the coordinates are printed in long/lat order.

north is chosen as the larger lat of NW/NE corners
south is chosen as the smaller lat of SW/SE corners
west is chosen as the smaller long of SW/NW corners
east is chosen as the larger long of SE/NE corners
rows is the nrow parameter from the sdts2arc output
cols is the ncol parameter from the sdts2arc output

Save this file as washdc.ascii

5) Set up a new location in grass for the data

Start up grass and give it a new location name. When it asks for the parameters for your new location, use the following:

Coordinate System: 1 (UTM)

UTM Zone for Location: 18 [get this value from sdts2arc output]

One Line Description: WASHINGTON WEST, DC-MD-VA [anything appropriate]

Default Region: [pick values from LAT/LONG of USGS Quad of sdts2arc output, note that the coordinates are printed in long/lat order]

	North Edge: 4318716.500  [larger  lat  of NW/NE corners]
South Edge: 4304598.500 [smaller lat of SW/SE corners]
West Edge: 315655.1562 [smaller long of SW/NW corners]
East Edge: 326804.6875 [larger long of SE/NE corners]

Grid Resolution:
East-West: 30 [the xhrs value from the sdts2arc output]
North-South: 30 [the xhrs value from the sdts2arc output]

Ellispoid Name: wgs84 [not sure where this came from, but seems to work]

Tweak the DEFAULT_WIND created by grass:

change the e-w resol and n-s resol to 30 by editing the file

Propagate those changes into the WIND file:

 cp DEFAULT_WIND WIND

6) Import the elevation data as an ascii file and take a look

Importing as an ascii raster file is done as follows:

r.in.ascii input=washdc.ascii output=elev title=Elevation mult=1.0

To view the data:

d.mon start=x0 select=x0
d.rast map=elev -o
You should see a lovely rendering of Washington, DC, prominently featuring the Potomac River (heading to the NW), and Rock Creek (heading N)


Appendix A: sdtscode.patch - case sensitivity patches for sdtscode.zip utilities

diff -ubBp ./temp/sdts2sur.c sdtsutils/sdts2sur.c
--- ./temp/sdts2sur.c Sat Aug 27 17:07:56 1994
+++ sdtsutils/sdts2sur.c Wed Sep 22 18:19:12 1999
@@ -266,7 +266,7 @@ void dem_rc(int status)
{

strcpy (file_name,base_name);
- strcat (file_name,"ldef.ddf");
+ strcat (file_name,"LDEF.DDF");
if (! beg123file (file_name,'R',&int_level,&ice,ccs,&fpin))
{
printf ("\nCAN'T OPEN 'dem' LPEF FILE %s",file_name);
@@ -349,9 +349,9 @@ void degenlines(int status)
{
/* degenerate lines sored as points */
strcpy (file_name,base_name);
- strcat (file_name,"ne");
+ strcat (file_name,"NE");
strcat (file_name,cellid);
- strcat (file_name,".ddf");
+ strcat (file_name,".DDF");
p=0;
/* strcat (file_name,module);*/
if (! beg123file (file_name,'R',&int_level,&ice,ccs,&fpin))
@@ -843,9 +843,9 @@ void demnodes(int status)
}
*/
strcpy (file_name,base_name);
- strcat (file_name,"no");
+ strcat (file_name,"NO");
strcat (file_name,cellid);
- strcat (file_name,".ddf");
+ strcat (file_name,".DDF");
p = 0;
if (! beg123file (file_name,'R',&int_level,&ice,ccs,&fpin))
{
@@ -1029,9 +1029,9 @@ void demareas(int status)
{

strcpy (file_name,base_name);
- strcat (file_name,"na");
+ strcat (file_name,"NA");
strcat (file_name,cellid);
- strcat (file_name,".ddf");
+ strcat (file_name,".DDF");
/* strcat (file_name,module);*/
if (! beg123file (file_name,'R',&int_level,&ice,ccs,&fpin))
{
@@ -1211,7 +1211,7 @@ void demmbr(int status)
double fl;
/* int label ;*/
strcpy (file_name,base_name);
- strcat (file_name,"spdm.ddf");
+ strcat (file_name,"SPDM.DDF");
/* strcat (file_name,module);*/
if (! beg123file (file_name,'R',&int_level,&ice,ccs,&fpin))
{
@@ -1565,9 +1565,9 @@ void loadpoints(int status)
{
/* these are the degenerate lines */
strcpy (file_name,base_name);
- strcat (file_name,"ne");
+ strcat (file_name,"NE");
strcat (file_name,cellid);
- strcat (file_name,".ddf");
+ strcat (file_name,".DDF");
nxy = 0;
/* strcat (file_name,module);*/
if (! beg123file (file_name,'R',&int_level,&ice,ccs,&fpin))
@@ -1766,7 +1766,7 @@ void cells_out(int status)
strcpy (file_name,base_name);
strcat (file_name,"CE");
strcat (file_name,cellid);
- strcat (file_name,".ddf");
+ strcat (file_name,".DDF");
if (! beg123file (file_name,'R',&int_level,&ice,ccs,&fpin))
{
printf ("\nCAN'T OPEN CELL VALUES FILE %s...",file_name);

diff -ubBp ./temp/sdts2xyz.c sdtsutils/sdts2xyz.c --- ./temp/sdts2xyz.c Thu Apr 30 14:59:56 1998 +++ sdtsutils/sdts2xyz.c Wed Sep 22 10:34:18 1999 @@ -273,7 +273,7 @@ void dem_rc(int status) { strcpy (file_name,base_name); - strcat (file_name,"ldef.ddf"); + strcat (file_name,"LDEF.DDF"); if (! beg123file (file_name,'R',&int_level,&ice,ccs,&fpin)) { printf ("\nCAN'T OPEN 'dem' LPEF FILE %s",file_name); @@ -640,7 +640,7 @@ void dem_mbr(int status) double fl; /* int label ;*/ strcpy (file_name,base_name); - strcat (file_name,"spdm.ddf"); + strcat (file_name,"SPDM.DDF"); /* strcat (file_name,module);*/ if (! beg123file (file_name,'R',&int_level,&ice,ccs,&fpin)) { @@ -965,7 +965,7 @@ void cells_out(int status) strcpy (file_name,base_name); strcat (file_name,"CE"); strcat (file_name,cellid); - strcat (file_name,".ddf"); + strcat (file_name,".DDF"); if (! beg123file (file_name,'R',&int_level,&ice,ccs,&fpin)) { printf ("\nCAN'T OPEN CELL VALUES FILE %s...",file_name);


Appendix B: Makefile for sdtscode.zip utilities

all: demout sdts2dem sdts2sur sdtsgrid sdts2arc sdts2rcz sdts2xyz

%: %.c
gcc -o $@ $@.c -Wl,/usr/local/lib/libfips123.a


Appendix C: sdts2arc for Washington West, DC DEM elevation data

       Spatial Data Transfer Standard (SDTS)
SDTS to ARCINFO ASCII GRID Utility
SDTS2ARC BETA ver .003
Another gis translation tool from
Sol Katz(skatz@blm.gov), Mar 1998.

Title: WASHINGTON WEST, DC-MD-VA - 24000
Data ID: LAT:: 38.875 LONG:: -77 SCALE:: 24000
Data set creation date: 19980708

cell width: 30.000000
cell height: 30.000000
rsnm: UTM
zone: 18
nrow= 471, ncol= 372
Range: max= 423, min= 0, void= -32767, fill= -32766
LAT/LONG of the 7.5 USGS Quad
SW 315655.156250 4304843.500000
NW 315979.093750 4318716.500000
NE 326804.687500 4318471.500000
SE 326500.250000 4304598.500000
processing cells

END OF FILE

End of Program


Go back to GRASS GIS FAQ...
Last Modified: 24th Jan. 2004
Eric Mitchell