這裏是C++從Java的處理的GeoTIFF文件字節組在Linux上使用JNI的完整的例子:
#include <jni.h>
#include "gdal_priv.h"
#include "cpl_string.h"
#include "cpl_conv.h"
#include "gdalwarper.h"
#include "cpl_vsi.h"
JNIEXPORT void JNICALL Java_com_box_processing_GEOTransform_run(JNIEnv *env, jobject obj, jbyteArray array) {
GDALAllRegister();
jboolean isCopy;
jbyte* buf = env->GetByteArrayElements(array, &isCopy);
jsize lengthOfArray = env->GetArrayLength(array);
const char *pszFormat = "GTiff";
GDALDriver *poDriver;
poDriver = GetGDALDriverManager()->GetDriverByName(pszFormat);
VSILFILE* fpMem = VSIFileFromMemBuffer ("/vsimem/temp.tif", (GByte*) buf, (vsi_l_offset) lengthOfArray, FALSE);
VSIFCloseL(fpMem);
GDALDataset *poSrcDS = (GDALDataset *) GDALOpen("/vsimem/temp.tif", GA_ReadOnly);
GDALDataset *poDstDS;
const char *pszSrcWKT = NULL;
pszSrcWKT=GDALGetProjectionRef(poSrcDS);
double error_threshold = 0.125;
GDALResampleAlg resampling = GRA_Cubic;
char* pszDstWKT = NULL;
GDALDataset * tmpDS = (GDALDataset*)(GDALDataset*)GDALAutoCreateWarpedVRT(poSrcDS, pszSrcWKT, pszDstWKT, resampling, error_threshold, NULL);
poDstDS = poDriver->CreateCopy("/some/folder/example1.tif", (GDALDataset*)tmpDS, FALSE, NULL, NULL, NULL);
GDALClose((GDALDatasetH) poDstDS);
GDALClose((GDALDatasetH) poSrcDS);
VSIUnlink("/vsimem/temp.tif");
}
我知道如何使它在python,我剛纔問了C++,但我我會找到答案,謝謝 –