Skip to content

Instantly share code, notes, and snippets.

@refactor
Last active January 27, 2019 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save refactor/614d79911296cf42ca7d021536676ae2 to your computer and use it in GitHub Desktop.
Save refactor/614d79911296cf42ca7d021536676ae2 to your computer and use it in GitHub Desktop.
test GDALAutoCreateWarpedVRT
#include <cpl_conv.h>
#include <ogr_srs_api.h>
#include <gdalwarper.h>
/*
* https://www.gdal.org/warptut.html
*/
int main()
{
GDALAllRegister();
// Open input and output files.
GDALDatasetH hSrcDS = GDALOpenShared( "cq-dem.tif", GA_ReadOnly );
OGRSpatialReferenceH dstSRS = OSRNewSpatialReference(NULL);
OSRImportFromEPSG(dstSRS, 3857);
char *pszDstWKT = NULL;
OSRExportToWkt(dstSRS, &pszDstWKT);
OSRDestroySpatialReference(dstSRS);
printf("pass...\r\n%s\r\n", pszDstWKT);
GDALDatasetH hDstDS = GDALAutoCreateWarpedVRT(hSrcDS,
GDALGetProjectionRef(hSrcDS), pszDstWKT,
GRA_NearestNeighbour,
0.0,
NULL);
// save as xml file, just for edit the VRT as a xml file,
GDALDriverH hDriver = GDALGetDatasetDriver(hDstDS);
GDALDatasetH hOutDS = GDALCreateCopy(hDriver, "my-dem.vrt", hDstDS,
FALSE, NULL, NULL, NULL);
GDALClose(hOutDS);
// do the work with hDstDS, as the warp VRT dataset,
// ...
CPLFree(pszDstWKT);
GDALClose( hDstDS );
GDALClose( hSrcDS );
return 0;
}
@refactor
Copy link
Author

refactor commented Jan 20, 2019

gcc gdal-config --cflags warp_test.c gdal-config --libs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment