File Format Conversion

Converting a USGS National Elevation Dataset (NED) file to LandSerf format

In this example, the original file is stored in ArcGIS 'Binary Interleaved Layers' (BIL) format as downloaded from seamless.usgs.gov.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Converts a ArcGIS Binary Interleaved File (.bil) to LandSerf format
version(1.0);

# Change the directory and filename to correspond to your file location.
baseDir = "c:/Program Files/LandSerf/data/";

# Open the BIL file.
dem = open(baseDir & "lincolnNED.bil");

# Add the metadata to the DEM.
edit(dem,"title","Lincoln DEM");
edit(dem,"projection","LatLong");
edit(dem,"ellipsoid","wgs 84");
colouredit(dem,"land3");

# Save the edited raster as a LandSerf file.
save(dem, baseDir & "landscriptExamples/LincolnNED.srf");

Creating text files representing objects and their metadata

The function saveAsText() can be used as a general purpose function for saving any raster or vector map as a series of text files. These files contain all the spatial data as well as associated metadata such as attribute tables, colour tables and projection information.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Saves a raster and vector map and all their metadata as a collection of text files.
version(1.0);

# Change the directory and filename to correspond to your file location.
baseDir = "c:/Program Files/LandSerf/data/landscriptExamples/";

# Convert a raster and a vector map.
saveAsText("dem","raster");
saveAsText("shapes","vector");


# --------
# Function to save a spatial object as a set of text files.
function saveAsText(baseName, type)
{
    spObj = null();

    if (compare(type,"raster")==0);
    {
        spObj = open(baseDir&baseName&".srf");
        save(spObj,baseDir&baseName&"_ascii.txt","ArcGridText");
    }
    if (compare(type,"vector")==0);
    {
        spObj = open(baseDir&baseName&".vec");
        save(spObj,baseDir&baseName&"_ascii.txt","TextVector");
    }
    
    if ((compare(type,"raster")==0) or (compare(type,"vector")==0));
    {
        save(spObj,baseDir&baseName&"_ascii.ctb","Colourtable");
        save(spObj,baseDir&baseName&"_ascii.atr","Attributes");
        metadata = "Title:\t\t"&info(spObj,"title")&"\n"&
                   "Projection:\t"&info(spObj,"projection")&"\n"&
                   "Notes:\t\t"&info(spObj,"notes");
        echo(metadata,baseDir&baseName&"_metadata.txt");
    }
}