> ## Documentation Index
> Fetch the complete documentation index at: https://docs.generalrobotics.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# HeightMap

> A class to represent a height map, typically derived from LiDAR or depth data

```python theme={null}
from grid_types import HeightMap
```

A class to represent a height map, typically derived from LiDAR or depth data.

## Fields

<ResponseField name="data" type="np.ndarray">
  A 2D numpy array where each cell contains a height value. The shape is (height, width).
</ResponseField>

<ResponseField name="resolution" type="float">
  The size of each cell in meters. For example, a resolution of 0.1 means each cell is 0.1m x 0.1m.
</ResponseField>

<ResponseField name="origin" type="Position">
  The 3D world coordinates (x, y, z) of the corner of the cell (0,0) in the height map data.
</ResponseField>

## Constructor

```python Signature theme={null}
HeightMap(data: np.ndarray, resolution: float, origin: Position)
```

## Methods

### `from_dict()`

```python Signature theme={null}
from_dict(data: dict) -> HeightMap
```

Deserialize from dictionary

### `get_world_coordinates()`

```python Signature theme={null}
get_world_coordinates() -> Tuple[np.ndarray, np.ndarray, np.ndarray]
```

Calculates the 3D world coordinates of each cell in the height map.

The (i, j)-th cell in the `data` array corresponds to a physical location.
This method computes the X, Y, and Z coordinates for all cells.
X and Y are grids representing the planar coordinates.
Z is the height data itself.

**Returns:**

Tuple\[np.ndarray, np.ndarray, np.ndarray]: A tuple containing three 2D arrays:

* X\_coords: World X coordinates of each cell center.
* Y\_coords: World Y coordinates of each cell center.
* Z\_coords: World Z coordinates (heights) of each cell (self.data).

### `to_dict()`

```python Signature theme={null}
to_dict() -> dict
```

Serialize to dictionary for JSON transfer

## Example

```python theme={null}
import numpy as np
# Assuming Position is in the same module context
from grid_types import Position
data = np.array([[1.0, 1.1, 1.2],
                 [1.3, 1.4, 1.5]], dtype=np.float32)
resolution = 0.5  # Each cell is 0.5m x 0.5m
origin = Position(x_val=10.0, y_val=20.0, z_val=0.0) # Map starts at (10, 20, 0)
height_map = HeightMap(data=data, resolution=resolution, origin=origin)
print(height_map.data.shape)
print(height_map.resolution)
print(height_map.origin)
```


## Related topics

- [zoedepth](/models/cortex/zoedepth.md)
- [Sensors](/simulation/isaac/sensors.md)
- [da3metric](/models/cortex/da3metric.md)
- [fast-foundationstereo](/models/cortex/fast-foundationstereo.md)
- [foundationstereo](/models/cortex/foundationstereo.md)
