# elevation_nasa

[![Crates.io](https://img.shields.io/crates/v/elevation_nasa.svg)](https://crates.io/crates/elevation_nasa)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

CLI tool for downloading NASA Earthdata SRTM elevation tiles.

## Overview

This is a command-line interface for downloading and converting SRTM (Shuttle Radar Topography Mission) elevation tiles from NASA's LP DAAC server.

## Installation

### From Crates.io

```bash
cargo install elevation_nasa
```

### From Source

```bash
cd elevation_nasa
git clone https://github.com/your-repo/elevation_nasa.git
cd elevation_nasa
cargo install --path .
```

## Usage

### Authentication

You need a NASA Earthdata bearer token:

1. Create account: https://urs.earthdata.nasa.gov/
2. Generate token: https://urs.earthdata.nasa.gov/users/find_or_create_token
3. Set environment variable: `export EARTHDATA_TOKEN=<token>`

### Commands

#### `download` - Download a single tile

```bash
elevation_nasa download [OPTIONS] <TILE> <DEST>
```

Arguments:
- `<TILE>` - SRTM tile name (e.g., N45W074)
- `<DEST>` - Destination directory

Options:
- `--token <TOKEN>` - NASA Earthdata token (defaults to EARTHDATA_TOKEN env)

Example:
```bash
elevation_nasa download N45W074 /path/to/dest
```

#### `bounds` - Download all tiles for a bounding box

```bash
elevation_nasa bounds [OPTIONS] <MIN_LAT> <MIN_LON> <MAX_LAT> <MAX_LON> <DEST>
```

Arguments:
- `<MIN_LAT>` - Minimum latitude (southern bound)
- `<MIN_LON>` - Minimum longitude (western bound)
- `<MAX_LAT>` - Maximum latitude (northern bound)
- `<MAX_LON>` - Maximum longitude (eastern bound)
- `<DEST>` - Destination directory

Options:
- `--token <TOKEN>` - NASA Earthdata token

Example:
```bash
elevation_nasa bounds 45 -74 46 -73 /path/to/dest
```

#### `path` - Ensure DEM file exists

```bash
elevation_nasa path [OPTIONS] <DEM_PATH>
```

Arguments:
- `<DEM_PATH>` - Path to the DEM file

Options:
- `--token <TOKEN>` - NASA Earthdata token

Example:
```bash
elevation_nasa path /path/to/missing/file.tif
```

#### `list` - List tiles for a bounding box

```bash
elevation_nasa list <MIN_LAT> <MIN_LON> <MAX_LAT> <MAX_LON>
```

Arguments:
- `<MIN_LAT>` - Minimum latitude
- `<MIN_LON>` - Minimum longitude
- `<MAX_LAT>` - Maximum latitude
- `<MAX_LON>` - Maximum longitude

Example:
```bash
elevation_nasa list 45 -74 46 -73
```

## Logging

Use the `RUST_LOG` environment variable to control logging:

```bash
# Default (info level)
elevation_nasa download N45W074 /path/to/dest

# Debug level
RUST_LOG=debug elevation_nasa download N45W074 /path/to/dest
```

## Tile Naming

SRTM tiles are named by their southwest corner:
- `N45W074` = latitude 45°N, longitude 74°W
- Covers area from (45, -74) to (46, -73)
- `S12E003` = latitude 12°S, longitude 3°E

## Related

- [elevation_nasa_core](https://crates.io/crates/elevation_nasa_core) - Core library
- [NASA Earthdata](https://earthdata.nasa.gov/)
- [SRTM Mission](https://www2.jpl.nasa.gov/srtm/)

## License

MIT License - see [LICENSE](LICENSE) file for details.
