Created
August 25, 2011 18:21
-
-
Save btc/1171361 to your computer and use it in GitHub Desktop.
this code works
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// GDAL_WARPTEST.cpp : Defines the entry point for the console application. | |
#include "stdafx.h" | |
#include "gdal_priv.h" | |
#include <iostream> | |
using namespace std; | |
//#include "cpl_conv.h" // for CPLMalloc() | |
//#include <stdio.h> | |
int _tmain(int argc, _TCHAR* argv[]) | |
{ | |
GDALDataset* raster; // declare the GDALDataset we will create | |
GDALAllRegister(); // Attempts to register all known drivers, required to recognize bmp file | |
const char* filenameImg = "img/cea.tif"; // identifies the file we want to open | |
raster = (GDALDataset*) GDALOpen(filenameImg, GA_ReadOnly); // opens file | |
if (raster == NULL) | |
{ | |
cout << "Something went wrong!\n"; | |
} | |
else cout << "Image opened successfully!\n"; | |
int rasterXSize = raster->GetRasterXSize(); | |
int rasterYSize = raster->GetRasterYSize() ; | |
cout << "x size is " << rasterXSize << "\n"; | |
cout << "y size is " << rasterYSize << "\n"; | |
int pixelX = rasterXSize + 1; | |
while (pixelX > rasterXSize || pixelX < 0) { | |
cout << "Enter pixel X coordinate: "; | |
scanf("%d", &pixelX); | |
getc(stdin); | |
if (pixelX > rasterXSize) cout << "X coordinate must be less than X size of image\n"; | |
} | |
cout << "Pixel X = " << pixelX << "\n"; | |
int pixelY = rasterYSize + 1; | |
while (pixelY > rasterYSize || pixelY < 0) { | |
cout << "Enter pixel Y coordinate: "; | |
scanf("%d", &pixelY); | |
getc(stdin); | |
if (pixelY > rasterYSize) cout << "Y coordinate must be less than Y size of image\n"; | |
} | |
cout << "Pixel Y = " << pixelY << "\n"; | |
float lati; | |
float longi; | |
cout << "Latitude: "; | |
scanf("%f", &lati); | |
getc(stdin); | |
cout << "Latitude = " << lati << "\n"; | |
cout << "Longitude: "; | |
scanf("%f", &longi); | |
getc(stdin); | |
cout << "Longitude = " << longi << "\n"; | |
// create a GCP | |
GDAL_GCP firstGCP; | |
firstGCP.pszId = "1"; | |
firstGCP.pszInfo = ""; | |
firstGCP.dfGCPPixel = pixelX; | |
firstGCP.dfGCPLine = pixelY; | |
firstGCP.dfGCPX = lati; | |
firstGCP.dfGCPY = longi; | |
firstGCP.dfGCPZ = 0; | |
// Driver tests | |
const char* outputFilename = "img/output.tif"; | |
GDALDriver* driverName = GetGDALDriverManager()-> GetDriverByName("GTiff"); | |
GDALDataset* outputRaster = driverName->CreateCopy(outputFilename, raster, FALSE, | |
NULL, NULL, NULL); | |
if (outputRaster != NULL) GDALClose( (GDALDatasetH) outputRaster); | |
if (raster != NULL) GDALClose( (GDALDatasetH) raster); | |
getc(stdin); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
correct syntax is GDALDataset->methodName();