Terrain Tile¶
This module defines the quantized_mesh_tile.terrain.TerrainTile
.
More information about the format specification can be found here:
https://github.com/AnalyticalGraphicsInc/quantized-mesh
Reference¶
-
class
quantized_mesh_tile.terrain.
TerrainTile
(*args, **kwargs)[source]¶ Bases:
future.types.newobject.newobject
The main class to read and write a terrain tile.
Constructor arguments:
west
The longitude at the western edge of the tile. Default is -1.0.east
The longitude at the eastern edge of the tile. Default is 1.0.south
The latitude at the southern edge of the tile. Default is -1.0.north
The latitude at the northern edge of the tile. Default is 1.0.topology
The topology of the mesh which but be an instance ofquantized_mesh_tile.topology.TerrainTopology
. Default is None.watermask
- A water mask list (Optional). Adds rendering water effect. The water mask list is either one byte, [0] for land and [255] for water, either a list of 256*256 values ranging from 0 to 255. Values in the mask are defined from north-to-south and west-to-east. Per default no watermask is applied. Note that the water mask effect depends on the texture of the raster layer drapped over your terrain. Default is [].
Usage examples:
from quantized_mesh_tile.terrain import TerrainTile from quantized_mesh_tile.topology import TerrainTopology from quantized_mesh_tile.global_geodetic import GlobalGeodetic # The tile coordinates x = 533 y = 383 z = 9 geodetic = GlobalGeodetic(True) [west, south, east, north] = geodetic.TileBounds(x, y, z) # Read a terrain tile (unzipped) tile = TerrainTile(west=west, south=south, east=east, north=north) tile.fromFile('mytile.terrain') # Write a terrain tile locally from scratch (lon/lat/height) wkts = [ 'POLYGON Z ((7.3828125 44.6484375 303.3, ' + '7.3828125 45.0 320.2, ' + '7.5585937 44.82421875 310.2, ' + '7.3828125 44.6484375 303.3))', 'POLYGON Z ((7.3828125 44.6484375 303.3, ' + '7.734375 44.6484375 350.3, ' + '7.5585937 44.82421875 310.2, ' + '7.3828125 44.6484375 303.3))', 'POLYGON Z ((7.734375 44.6484375 350.3, ' + '7.734375 45.0 330.3, ' + '7.5585937 44.82421875 310.2, ' + '7.734375 44.6484375 350.3))', 'POLYGON Z ((7.734375 45.0 330.3, ' + '7.5585937 44.82421875 310.2, ' + '7.3828125 45.0 320.2, ' + '7.734375 45.0 330.3))' ] topology = TerrainTopology(geometries=wkts) tile = TerrainTile(topology=topology) tile.toFile('mytile.terrain')
-
BYTESPLIT
= 65636¶
-
EdgeIndices16
= {'eastIndices': 'H', 'eastVertexCount': 'I', 'northIndices': 'H', 'northVertexCount': 'I', 'southIndices': 'H', 'southVertexCount': 'I', 'westIndices': 'H', 'westVertexCount': 'I'}¶
-
EdgeIndices32
= {'eastIndices': 'I', 'eastVertexCount': 'I', 'northIndices': 'I', 'northVertexCount': 'I', 'southIndices': 'I', 'southVertexCount': 'I', 'westIndices': 'I', 'westVertexCount': 'I'}¶
-
ExtensionHeader
= {'extensionId': 'B', 'extensionLength': 'I'}¶
-
MAX
= 32767.0¶
-
MIN
= 0.0¶
-
OctEncodedVertexNormals
= {'xy': 'B'}¶
-
WaterMask
= {'xy': 'B'}¶
-
_dequantizeHeight
(h)[source]¶ Private helper method to convert quantized tile (h) values to real world height values :param h: the quantized height value :return: the height in ground units (meter)
-
static
_iterUnpackAndDecodeLight
(f, extensionLength, structType)[source]¶ A private method to iteratively unpack light vector.
-
static
_iterUnpackAndDecodeVertices
(f, vertexCount, structType)[source]¶ A private method to itertatively unpack and decode indices.
-
static
_iterUnpackIndices
(f, indicesCount, structType)[source]¶ A private method to iteratively unpack indices
-
static
_iterUnpackWatermaskRow
(f, extensionLength, structType)[source]¶ A private method to iteratively unpack watermask rows
-
fromBytesIO
(f, hasLighting=False, hasWatermask=False)[source]¶ A method to read a terrain tile content.
Arguments:
f
An instance of io.BytesIO containing the terrain data. (Required)hasLighting
Indicate if the tile contains lighting information. Default isFalse
.hasWatermask
Indicate if the tile contains watermask information. Default isFalse
.
-
fromFile
(filePath, hasLighting=False, hasWatermask=False, gzipped=False)[source]¶ A method to read a terrain tile file. It is assumed that the tile unzipped.
Arguments:
filePath
An absolute or relative path to a quantized-mesh terrain tile. (Required)hasLighting
Indicate if the tile contains lighting information. Default isFalse
.hasWatermask
Indicate if the tile contains watermask information. Default isFalse
.gzipped
Indicate if the tile content is gzipped. Default isFalse
.
-
fromTerrainTopology
(topology, bounds=None)[source]¶ A method to prepare a terrain tile data structure.
Arguments:
topology
The topology of the mesh which must be an instance ofquantized_mesh_tile.topology.TerrainTopology
. (Required)bounds
The bounds of a the terrain tile. (west, south, east, north) If not defined, the bounds defined during initialization will be used. If no bounds are provided, then the bounds are extracted from the topology object.
-
getTrianglesCoordinates
()[source]¶ A method to retrieve triplet of coordinates representing the triangles in lon,lat,height.
-
getVerticesCoordinates
()[source]¶ A method to retrieve the coordinates of the vertices in lon,lat,height.
-
indexData16
= {'indices': 'H', 'triangleCount': 'I'}¶
-
indexData32
= {'indices': 'I', 'triangleCount': 'I'}¶
-
quantizedMeshHeader
= {'boundingSphereCenterX': 'd', 'boundingSphereCenterY': 'd', 'boundingSphereCenterZ': 'd', 'boundingSphereRadius': 'd', 'centerX': 'd', 'centerY': 'd', 'centerZ': 'd', 'horizonOcclusionPointX': 'd', 'horizonOcclusionPointY': 'd', 'horizonOcclusionPointZ': 'd', 'maximumHeight': 'f', 'minimumHeight': 'f'}¶
-
toBytesIO
(gzipped=False)[source]¶ A method to write the terrain tile data to a file-like object (a string buffer).
Arguments:
gzipped
Indicate if the content should be gzipped. Default isFalse
.
-
toFile
(filePath, gzipped=False)[source]¶ A method to write the terrain tile data to a physical file.
Argument:
filePath
An absolute or relative path to write the terrain tile. (Required)gzipped
Indicate if the content should be gzipped. Default isFalse
.
-
vertexData
= {'heightVertexCount': 'H', 'uVertexCount': 'H', 'vVertexCount': 'H', 'vertexCount': 'I'}¶