CHAPTER 5 3D STL PART FROM SURFER GRID DEM...

11
95 CHAPTER 5 3D STL PART FROM SURFER GRID DEM DATA ____________________________________________________ The Surfer Grid is another widely used DEM file format and found to be suitable for the direct conversion to faceted formats. The chapter begins with an introduction to Surfer Grid file format. Surfer Grid format is different from the DEM ASCII XYZ and USGS DEM formats. A methodology has been developed to obtain 3D STL part directly from Surfer Grid DEM format and discussed in the chapter. Subsequently, conversion of many sample Surfer Grid DEM files into STL format has been discussed to check the accuracy and correctness of the results of the C program. The JPEG images of the sample STL parts loaded into Pro/ENGINEER have also been included in the chapter for visualization purpose. In the end, the direct conversion of large DEM data from real world has been discussed. 5.1 Surfer Grid File Format Surfer Grid is a widely used GIS file format. It is extensively used by surface gridding and contouring programs in earth sciences. A Surfer Grid data format is shown below in Figure 5.1. DSAA ncolumns mrows xmin xmax ymin ymax zmin zmax el11 el12 el13 el1n el21 el22 el23 el2n . . . . elm1 elm2 elm3 elmn Figure 5.1: A sample Surfer Grid file The file format consists of a header followed by a grid of elevation values [Sheriff (2014), OceanTeacher (2014)]. The first line in the header contains a data format identifier

Transcript of CHAPTER 5 3D STL PART FROM SURFER GRID DEM...

95

CHAPTER 5

3D STL PART FROM SURFER GRID DEM DATA

____________________________________________________ The Surfer Grid is another widely used DEM file format and found to be suitable for the

direct conversion to faceted formats. The chapter begins with an introduction to Surfer

Grid file format. Surfer Grid format is different from the DEM ASCII XYZ and USGS

DEM formats. A methodology has been developed to obtain 3D STL part directly from

Surfer Grid DEM format and discussed in the chapter. Subsequently, conversion of many

sample Surfer Grid DEM files into STL format has been discussed to check the accuracy

and correctness of the results of the C program. The JPEG images of the sample STL

parts loaded into Pro/ENGINEER have also been included in the chapter for visualization

purpose. In the end, the direct conversion of large DEM data from real world has been

discussed.

5.1 Surfer Grid File Format

Surfer Grid is a widely used GIS file format. It is extensively used by surface gridding

and contouring programs in earth sciences. A Surfer Grid data format is shown below in

Figure 5.1.

DSAA ncolumns mrows xmin xmax ymin ymax zmin zmax el11 el12 el13 … el1n el21 el22 el23 … el2n . . . . elm1 elm2 elm3 … elmn

Figure 5.1: A sample Surfer Grid file

The file format consists of a header followed by a grid of elevation values [Sheriff (2014),

OceanTeacher (2014)]. The first line in the header contains a data format identifier

96

DSAA, which stands for Data in Surfer Grid ASCII format. In the next line, ncolumns

and mrows represent the number of columns and rows of points in the grid respectively.

In the third line xmin and xmax represent the minimum and maximum values of the x-

coordinates respectively in the grid. Similarly fourth line represents the minimum and

maximum values of the y-coordinates. And fifth line represents the minimum and

maximum values of the z-coordinates in the grid. After the header, there is a grid of

elevation data values (el11, el12 etc.). The cells in grid are regularly spaced in the x-

direction as well as in the y-direction. The cell-size in the x-direction is calculated as

(xmax - xmin)/(ncolumns-1) and in y-directions as (ymax – ymin)/(nrows-1). This is

different from DEM ASCII XYZ format where the cell-size is explicitly given in the

header.

The DEM ASCII XYZ format gives NODATA_value in the header. It corresponds to a

missing data in the grid. In Surfer Grid format, NODATA_value is not explicitly specified

in the header. Surfer Grid format is interpreted for missing data as follows. Any value

beyond the range of minimum and maximum elevation values is considered as missing

data. For example, a very high elevation value 1.6025E+038 in meters in the data for a

terrain on the earth is considered as a missing data. Geospatial Designs and Global

Mapper also discuss the Surfer Grid data format [Geospatial (2014), Blue Marbles

(2014)].

5.2 Methodology to Obtain 3D STL Part

There are missing data in the elevation grid due to the inherent inaccuracies in remote

sensing or surveying methods to obtain the data. It also depends upon ground planimetric

reference system used such as UTM, geographic or state plane coordinate system. A

quadrangle of neat lines or a block has profiles with unequal number of elevation values.

In order to find the missing data values in the Surfer Grid file, the C program scans all the

cells in grid. A constant NODATA_value with a large negative integer value is declared.

Those cells in the grid which have elevation values beyond the range of minimum and

maximum values are assigned NODATA_value. This assignment is similar to

NODATA_value already present in DEM ASCII XYZ data.

The minimum elevation value is directly available in Surfer Grid format as discussed

earlier. Therefore, this value need not be computed for calculating the base of the STL

97

part as done for DEM ASCII XYZ data. The base of the STL part is computed by

subtracting the required wall height from the minimum elevation value. The intervals in

the x and y-directions are different and are computed from the values in the header.

The first row of elevation values that follows the header of the file represents the southern

edge of the grid as opposed to DEM ASCII XYZ data where it is the northern edge

[Sheriff (2014)]. This is another major deviation from DEM ASCII XYZ format.

Figure 5.2: Triangles in the STL part for two consecutive rows

The input Surfer Grid data file is read by the C program. The elevation values are read in

a 2D matrix and the above differences are taken care of. The data is translated in a manner

similar to DEM ASCII XYZ data. A 3D STL part of a terrain is made by making triangles

for two consecutive rows or columns at a time, as discussed in Chapter 3. In case the STL

part is built by proceeding along the x-direction, the triangles are built for two consecutive

rows as shown in Figure 5.2. For two consecutive rows, the triangles on the top represent

the surface of the terrain. The left wall, the right wall and the base are made. The front

and rear walls are made only for the portions needed.

Figure 5.3 shows the triangles made for two consecutive columns when the STL part is

built by proceeding in the y-direction. If the Surfer Grid represents 2D solids separated by

rows, the part is built by proceeding in the x-direction after removing singularities. In case

it represents 2D solids separated by columns, the part is built by proceeding in the y-

direction. If the data has a gap inside and the user input is affirmative for interpolation,

the data is interpolated and the part is built in the x-direction. If the user does not want to

interpolate then an STL part cannot be built in the case of a gap. An STL surface is made

in this case. This can have visual value and user may like to run the program again with

interpolation.

98

Figure 5.3: Triangles in the STL part for two consecutive columns

5.3 Results and Discussion

The C program was run for sample DEM data. The first sample was a Surfer Grid of a

cube as shown in Figure 5.4, called Sample 1.

DSAA 2 2 0.0 30.0 0.0 30.0 60.0 60.0 60.0 60.0 60.0 60.0

Figure 5.4: Surfer Grid file of a cube in Sample 1

The data has two columns and two rows. The cell size is 30. The minimum and maximum

elevation values are 60. The STL part is made with a wall height of 30. This gives a cube

of sides 30 and having central diagonal with opposite ends at (0, 0, 30) and (30, 30, 60).

This Surfer Grid file is successfully converted to STL file as shown in Figure 5.5. The

STL part is then loaded into Pro/ENGINEER for visualization purpose. The JPEG image

of the same is shown in Figure 5.6. The cube has 6 faces. Each face is made with two

triangular facets in the STL file. Therefore, there should be 12 facets in the STL file.

solid output facet normal 0.000 -1.000 0.000 outer loop vertex 0.00 0.00 30000.00 vertex 30000.00 0.00 30000.00 vertex 0.00 0.00 60000.00

99

endloop endfacet facet normal 0.000 -1.000 0.000 outer loop vertex 30000.00 0.00 30000.00 vertex 30000.00 0.00 60000.00 vertex 0.00 0.00 60000.00 endloop endfacet facet normal 0.000 0.000 1.000 outer loop vertex 0.00 30000.00 60000.00 vertex 0.00 0.00 60000.00 vertex 30000.00 30000.00 60000.00 endloop endfacet facet normal 0.000 0.000 1.000 outer loop vertex 0.00 0.00 60000.00 vertex 30000.00 0.00 60000.00 vertex 30000.00 30000.00 60000.00 endloop endfacet facet normal -1.000 0.000 0.000 outer loop vertex 0.00 30000.00 30000.00 vertex 0.00 0.00 30000.00 vertex 0.00 30000.00 60000.00 endloop endfacet facet normal -1.000 0.000 0.000 outer loop vertex 0.00 0.00 30000.00 vertex 0.00 0.00 60000.00 vertex 0.00 30000.00 60000.00 endloop endfacet facet normal 1.000 0.000 0.000 outer loop vertex 30000.00 30000.00 60000.00 vertex 30000.00 0.00 60000.00 vertex 30000.00 30000.00 30000.00 endloop endfacet facet normal 1.000 0.000 0.000 outer loop vertex 30000.00 0.00 60000.00 vertex 30000.00 0.00 30000.00 vertex 30000.00 30000.00 30000.00 endloop endfacet

100

facet normal 0.000 0.000 -1.000 outer loop vertex 30000.00 30000.00 30000.00 vertex 30000.00 0.00 30000.00 vertex 0.00 30000.00 30000.00 endloop endfacet facet normal 0.000 0.000 -1.000 outer loop vertex 30000.00 0.00 30000.00 vertex 0.00 0.00 30000.00 vertex 0.00 30000.00 30000.00 endloop endfacet facet normal 0.000 1.000 0.000 outer loop vertex 30000.00 30000.00 30000.00 vertex 0.00 30000.00 30000.00 vertex 30000.00 30000.00 60000.00 endloop endfacet facet normal 0.000 1.000 0.000 outer loop vertex 0.00 30000.00 30000.00 vertex 0.00 30000.00 60000.00 vertex 30000.00 30000.00 60000.00 endloop endfacet endsolid

Figure 5.5: STL file of Sample 1 Surfer Grid

Figure 5.6: STL part of Sample 1 Surfer Grid loaded in Pro/ENGINEER

As can be seen, the STL file has 12 facets. The elevation values have been converted into

mm. The C program is written to give coordinates in mm. This is because the default unit

101

in the preprocessing software of ZPrinter in mm. It is also observed that the vertices of the

triangles are one of the vertices of the cube with central diagonal having opposite ends at

(0, 0, 30000) and (30000, 30000, 60000). Therefore, the data is converted accurately

without any loss in translation. The x-coordinates, y-coordinates and the elevation values

from the Surfer Grid file is directly used to make the vertices of the triangle. Therefore,

there is no data loss in conversion. The STL file obtained for a terrain model in cube form

also shows this.

Another sample of Surfer Grid with four elevation values, called Sample 2 was

considered for the direct conversion. The four elevation values are not equal. Figure 5.7

shows the STL part obtained from the conversion.

Figure 5.7: STL part of sample 2 Surfer Grid with four unequal elevation values loaded in Pro/ENGINEER

Figure 5.8 shows a sample Surfer Grid data with several no data values. It is called

Sample 3. The sample file with no data values was considered to verify the accuracy of

the C program. DSAA 6 6 0.0 150.0 0.0 150.0 42 55 1.70141E+038 1.70141E+038 55 53 53 46 1.70141E+038 1.70141E+038 55 44 44 53 43 48 52 52 1.70141E+038 1.70141E+038 44 47 43 45 1.70141E+038 1.70141E+038 1.70141E+038 1.70141E+038 52 43 1.70141E+038 1.70141E+038 1.70141E+038 1.70141E+038 53 42 1.70141E+038 1.70141E+038

Figure 5.8: Sample 3 Surfer Grid with many no data values

102

Figure 5.9 shows the STL part of sample 3 when loaded into Pro/ENGINEER. The shape

of the valid data values is correctly produced. It is verified from the STL file that the

elevation values directly go into the vertices of triangles. It should be noted while viewing

the STL part in Figure 5.9 that the first row of elevation values of Sample 3 Surfer Grid

data goes into the front of the STL part.

Figure 5.9: STL part of sample 3 Surfer Grid data loaded in Pro/ENGINEER

Figure 5.10 shows STL part of a sample Surfer Grid having gaps between valid elevation

values in the x-direction. It is called Sample 4. The C program correctly made the STL

part by proceeding in the y-direction. The STL part on viewing verifies that the

conversion is accurate. The dimensions were verified in the Pro/ENGINEER software by

enquiring. However, scales or dimensions could not be shown on Figure.

Figure 5.10: STL part of sample 4 Surfer Grid with gaps in the x-direction loaded in

Pro/ENGINEER

103

Figure 5.11: Sample 5 Surfer Grid with several no data values

Figure 5.11 shows another sample, called Sample 5 in Surfer Grid format. The data has 10

columns and 14 rows. The grid values lie in the range (min = 11.2, max = 19.4). There are

many no data values in the data. The data value which lies beyond the range (11.2, 19.4)

is a no data value. Therefore, 1.70141E+038 in the data is a no data value.

Figure 5.12 shows the STL part of the sample 5 Surfer Grid. The front face of the part

represents the first row having nine valid data values. The rear face of the STL part shows

the 14th row having five valid data values. Due to the presence of no data values, the base

of the 10 cols x 14 rows data is not a rectangle.

104

Figure 5.12: STL part of sample 5 Surfer Grid loaded in Pro/ENGINEER

The program was also run for Surfer Grid file of a real world region. The DEM data of the

Denver-west, Colorado, USA in Surfer Grid format was successfully converted into STL

format by the program. The DEM grid of the Denver-west contains 1201 columns and

1546 rows in it. The DEM file occupies about 15 MB space and considered to be a large

DEM file. The STL file consists of 3679812 triangular facets and occupies about 777 MB

space. The STL part was loaded into Pro/ENGINEER software to visualize it. The JPEG

image of the same is shown in Figure 5.13.

Figure 5.13: STL part of the Denver-west loaded in Pro/ENGINEER

105

5.4 Conclusions

Surfer Grid format is different from the DEM ASCII XYZ data as discussed in this

chapter. A methodology is developed to obtain the desired data such as cell_size and

NODATA_value in the grid. As other DEM data formats, Surfer Grid is also a surface

data. It does not have 3D information and is not a valid solid model in the terminology of

Computer-Aided Design. A valid solid model or a faceted model is needed to fabricate a

physical model of a terrain in AM machine. Finding the contiguous set of data, making

walls and base is quite an involved task. The methodology developed in this chapter

accomplished this task for Surfer Grid data format.

Functions in the C language have been written on the basis of the methodology. The

program successfully converted a surface data in Surfer Grid format directly into a 3D

STL part. The results of the C program are verified by small sample files. These STL

parts were loaded into Pro/ENGINEER for visualization purpose. The program has also

been tested for large real world Surfer Grid data. The STL files obtained by the program

can be downloaded to the AM machines after pre-processing for fabricating physical

models of the terrains.