startTime=AbsoluteTime[];

Dataset Thinner for SLAM

This code is copyright © 2009 by Vincent S. Cronin.  It may not be read, duplicated or used without his permission.

Begun July 16, 2009

Introduction

The purpose of this notebook is to minimize a large DEM dataset so that it can more efficiently be processed in SLAM

Put the datafile on a diet

Import the DEM data from a DAT file

The file pathway to the DEM file must be specified.

initialDataFile=Import["/Users/vince_cronin/Desktop/10mTahoeDEM.dat"];

User chooses the reduction factor

redFactor=10;

Read and interpret the DEM header information

Read the header information.

initialHeaderData=Table[initialDataFile[[i,j]],{i,6},{j,2}]

"ncols" is the number of columns;  label in position [[1,1]] and value in [[1,2]]

initialncols=initialHeaderData[[1,2]]

ncols=IntegerPart[initialncols/redFactor]+1

"nrows" is the number of rows;  label in position [[2,1]] and value in [[2,2]]

initialnrows=initialHeaderData[[2,2]]

nrows=IntegerPart[initialnrows/redFactor]

"xllcorner" is the UTM zone 11 "x" coordinate, in meters, of the lower left corner of the DEM;  label in position [[3,1]] and value in [[3,2]].

xllcorner=initialHeaderData[[3,2]]

"gridSpacing" a.k.a. "cellsize" is the distance between grid nodes in the DEM file, in meters;  label in position [[5,1]] and value in [[5,2]]
   Note that the code below uses the variable name "gridSpacing" rather than "cellsize."

cellsize=initialHeaderData[[5,2]]

"yllcorner" is the UTM zone 11 "y" coordinate, in meters, of the lower left corner of the DEM;  label in position [[4,1]] and value in [[4,2]]

initialyllcorner=initialHeaderData[[4,2]]

yllcorner=(initialyllcorner+((initialnrows-1)*cellsize))-(IntegerPart[initialnrows/redFactor]*(redFactor*cellsize))

"nodata_value" is the value used in the data file to indicate that there is no data in a specific location in the data file;  label in position [[6,1]] and value in [[6,2]]

nodataValue=initialHeaderData[[6,2]]

The "gridspacing" is the distance between grid nodes in the DEM file, as we are going to work with the file.

gridSpacing=redFactor*cellsize;

The original data matrix is stripped of its original header.

fatDEMdata=Drop[initialDataFile,6];

maxval=Max[fatDEMdata]

maxElev=IntegerPart[0.3048*maxval]

The original data matrix is reduced by the factor selected by the user.  If the user selects a "redFactor" of 2, then every other row and column is deleted.  A "redFactor" of 3 means that two rows and two columns are deleted between each row and column that is retained.

tempDEMmatrix=Take[fatDEMdata,{1,-1,redFactor},{1,-1,redFactor}];

thinDEMdata=IntegerPart[0.3048*tempDEMmatrix];

thinDim=Dimensions[thinDEMdata]

The original header data is changed to reflect the lower spatial density of the data

headerData={{initialHeaderData[[1,1]],thinDim[[2]]},{initialHeaderData[[2,1]],thinDim[[1]]},{initialHeaderData[[3,1]],xllcorner},{initialHeaderData[[4,1]],yllcorner},{initialHeaderData[[5,1]],gridSpacing},{initialHeaderData[[6,1]],0.3048*initialHeaderData[[6,2]]}}

A new datafile and header are created.

mergedData=Join[headerData,thinDEMdata];

The thinned-out dataset is exported

Export["/Users/vince_cronin/Desktop/100mTahoeDEM.txt", mergedData];

initialHeaderData//MatrixForm

tempHeader=Table[mergedData[[i,j]],{i,6},{j,2}];

tempHeader//MatrixForm

How long did this program take to run, in minutes?

minutesForProcessing=(AbsoluteTime[]-startTime)/60