[gdal-dev] create ntif file with NITF_IGEOLO field set
Amadeus WM
amadeus84 at verizon.net
Fri Feb 24 21:44:10 PST 2023
Hello everyone,
I'm new to GDAL and I'm trying to figure out how to create a NITF file
given the raw data, that also has the NITF_IGEOLO field set. With a
little help from chatGPT I came up with the c++ program below (it has
to be in c++). It writes the file, but it does not contain the
NITF_IGEOLO field. I do set it in the code with
GDALDataset::SetMetadataItem() and it does appear to be set in the
metadata. It just does not show up in the output file, when I inspect
it with gdalinfo -mdd all.
Can anyone help please? Thank you!
Here is the code
//
// g++ -g -Wall -o nitf nitf.cpp -lgdal
//
#include <gdal/gdal.h>
#include <gdal/gdal_priv.h>
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char* argv[])
{
const size_t rows=512, cols=512;
uint16_t data[rows*cols];
GDALAllRegister();
GDALDriver* driver=GetGDALDriverManager()->GetDriverByName("NITF");
GDALDataset* dataset=driver->Create("out.ntf", rows, cols, 1, GDT_UInt16, 0);
// We want to add and set NITF_IGEOLO
dataset->SetMetadataItem("NITF_IGEOLO", "1234");
// It does get set in the metadata
auto md=dataset->GetMetadata();
for (size_t i=0; md[i]!=nullptr; i++)
cout << md[i] << endl;
// but does not get written to file
GDALRasterBand* band=dataset->GetRasterBand(1);
if (band->RasterIO(GF_Write, 0, 0, rows, cols, (void*)data, rows, cols, GDT_UInt16, 0, 0)==CE_Failure)
throw "Error";
GDALClose((GDALDatasetH)dataset);
return 0;
}
More information about the gdal-dev
mailing list