# Working on c++ with cesium-native from github

**URL:** <https://community.cesium.com/t/working-on-c-with-cesium-native-from-github/24858>\
**Category:** Cesium Native\
**Created:** [June 18, 2023, 1:53pm UTC](https://community.cesium.com/t/working-on-c-with-cesium-native-from-github/24858 "2023-06-18T13:53:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dor.p](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/dor.p/32/14000_2.png) [@dor.p](https://community.cesium.com/u/dor.p)\
**Post date:** [June 18, 2023, 1:53pm UTC](https://community.cesium.com/t/working-on-c-with-cesium-native-from-github/24858/1 "2023-06-18T13:53:06Z")

</div>

Hey,  
I’m trying to work with cesium-native repo for reading and getting data from DTED files.  
I didn’t manage to find the functions to do so.  
Is it even possible? Am I trying to do something impossible or I’m just missing something?  
is the cesium-native just a base for the other APIs or is it a usable library?  
Thanks for the help!

---

<div class="post-metadata">

**Author:** ![Ankhenaten](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/ankhenaten/32/15133_2.png) [@Ankhenaten](https://community.cesium.com/u/Ankhenaten)\
**Post date:** [July 30, 2023, 2:48am UTC](https://community.cesium.com/t/working-on-c-with-cesium-native-from-github/24858/2 "2023-07-30T02:48:59Z")

</div>

[https://chat.openai.com/?model=gpt-4-code-interpreter](https://chat.openai.com/?model=gpt-4-code-interpreter)

### 1. Setting up `cesium-native`

Before we can work with DTED data in `cesium-native`, we need to ensure `cesium-native` is set up correctly:

1. **Clone the Repository** :

bashCopy code

```auto
git clone https://github.com/CesiumGS/cesium-native.git

```

1. **Build the Project** : Navigate to the cloned directory and create a build directory:

bashCopy code

```auto
mkdir build && cd build

```

Configure and build the project with CMake:

bashCopy code

```auto
cmake ..
make -j4 # Adjust '4' to the number of CPU cores you want to use for the build.

```

### 2. Integrating a DTED Reader with `cesium-native`

`cesium-native` doesn’t have built-in support for DTED. You’d need to either:

- Use an existing DTED reading library.
- Write your own DTED parser.

For the sake of this guide, let’s assume you’re going with the first option.

**Find a DTED Reading Library** : There are several open-source libraries that can read DTED files. One such option is GDAL. Once you’ve chosen a library, integrate it into your `cesium-native` project. This might involve including the library’s headers, linking against its binaries, and adding any necessary initialization code.

### 3. Reading DTED Data

With your DTED reader integrated:

1. **Load the DTED File** : Use the DTED reading library to open and read your DTED file.
2. **Extract Elevation Data** : The primary data of interest in a DTED file is its elevation data. Extract this data into a format that you can work with in `cesium-native`. This will typically be a 2D array of elevation values.

### 4. Convert DTED Data to Desired Output

Depending on your needs, you might want to:

- **Convert to Quantized Mesh** : If you’re aiming to display the terrain in CesiumJS, you might want to convert the elevation data to the Quantized Mesh format, which is optimized for CesiumJS rendering.
- **Generate 3D Tiles** : Another option for CesiumJS is to convert the DTED data into 3D Tiles, which is a format optimized for streaming and rendering 3D data.

### 5. Displaying the Data in CesiumJS

Once you’ve processed the DTED data:

1. **Serve the Data** : If you’ve converted the data to Quantized Mesh or 3D Tiles, you’ll need to serve it from a web server or a specialized tile server.
2. **Load in CesiumJS** : In your CesiumJS application, add a new terrain provider pointing to your served DTED data.

### Caveats & Considerations

1. **Performance** : DTED files can be large, especially if you’re working with high-resolution data. Ensure that your processing pipeline is optimized, especially if you’re planning to process many files.
2. **Accuracy** : Ensure that the DTED reading library you choose is accurate and can handle any quirks or variations in the DTED format.
3. **Licensing** : Some DTED data might come with licensing restrictions. Ensure that you have the necessary permissions to use and distribute the data.

This is a high-level overview of the process. Each step can be quite involved, especially when it comes to integrating a new library with `cesium-native` or converting the DTED data into another format. If you run into specific issues or have questions about a particular step, please let me know!

When working with DTED data, the most recommended and widely-used library is GDAL (Geospatial Data Abstraction Library). GDAL provides the ability to read, write, and transform a wide variety of raster and vector geospatial datasets, including DTED.

Here’s a step-by-step guide to using GDAL to read DTED data:

### 1. Installing GDAL

**Using a Package Manager** : If you’re on a Linux system, you can often install GDAL using your package manager:

bashCopy code

```auto
# For Ubuntu/Debian:
sudo apt-get install libgdal-dev

# For Fedora:
sudo dnf install gdal-devel

# For CentOS:
sudo yum install gdal-devel

```

**From Source** : You can also [download](https://gdal.org/download.html) GDAL’s source and compile it yourself.

### 2. Integrating GDAL with `cesium-native`

Once you’ve installed GDAL, you’ll need to make sure your project knows where to find its headers and libraries:

- Add the GDAL include path to your project’s include directories.
- Link your project against the GDAL library.

### 3. Reading DTED Data with GDAL

Here’s a basic code snippet to read a DTED file using GDAL:

cppCopy code

```auto
#include "gdal_priv.h"

int main() {
    GDALAllRegister(); // Register all available file formats

    GDALDataset *dataset = (GDALDataset*) GDALOpen("path_to_your_dted_file.dt0", GA_ReadOnly);
    if(dataset == nullptr) {
        // Handle error
        return 1;
    }

    // Get the elevation band (usually the first band in a DTED file)
    GDALRasterBand *band = dataset->GetRasterBand(1);

    int width = band->GetXSize();
    int height = band->GetYSize();

    float *elevations = new float[width * height];
    band->RasterIO(GF_Read, 0, 0, width, height, elevations, width, height, GDT_Float32, 0, 0);

    // At this point, 'elevations' contains the elevation data from the DTED file.
    // Do something with the data...

    delete[] elevations;
    GDALClose(dataset);

    return 0;
}

```

This code opens a DTED file, reads its elevation data into an array, and then closes the file. You can then use this elevation data as needed in your application.

### 4. Additional Considerations

- **Error Handling** : The above code is a basic example and doesn’t include thorough error handling. In a real-world scenario, you’d want to check for errors at every step and handle them appropriately.
- **Coordinate Systems** : DTED data is typically in a geographic coordinate system (latitude and longitude). Depending on your needs, you might need to reproject the data to a different coordinate system.
- **Dependencies** : Ensure you’ve linked against all required GDAL dependencies when building your project.

This should give you a starting point to work with DTED data in your `cesium-native` project using GDAL. If you have further questions or run into issues, let me know!

---

<div class="post-metadata">

**Author:** ![Timothy\_Moore](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/timothy_moore/32/21579_2.png) [@Timothy\_Moore](https://community.cesium.com/u/Timothy_Moore)\
**Post date:** [July 31, 2023, 7:48am UTC](https://community.cesium.com/t/working-on-c-with-cesium-native-from-github/24858/3 "2023-07-31T07:48:06Z")

</div>

Step 4, a simple matter of programming… not. cesium-native does not write Quantized Mesh. There is a writer for 3D Tiles, but I hesitate to say that you can generate 3D Tiles as such.

---

<div class="post-metadata">

**Author:** ![arvind\_sharma](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/arvind_sharma/32/24556_2.png) [@arvind\_sharma](https://community.cesium.com/u/arvind_sharma)\
**Post date:** [July 4, 2024, 5:40am UTC](https://community.cesium.com/t/working-on-c-with-cesium-native-from-github/24858/4 "2024-07-04T05:40:21Z")

</div>

> [@dor.p](#):
>
> esium-native just a base for the other APIs or is it a usable libr

I am having a Windows application for Telecom domain which is written in C++ using Visual Studio and now the requirement has raised to implement 3D Maps in the application so I want guidance to know that which API of Cesium will best fit in this case and how can I get a manual guide to use that API in my C++ application ?
