-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_gcp.c
61 lines (48 loc) · 1.78 KB
/
get_gcp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "gdal.h"
#include "cpl_conv.h" /* for CPLMalloc() */
#include "ogr_core.h"
#include "ogr_srs_api.h"
/*Compile like: gcc $(gdal-config --cflags) -o get_gcp get_gcp.c $(gdal-config --libs)*/
int main(int argc, char **argv)
{
GDALDatasetH hDataset;
GDALAllRegister();
hDataset = GDALOpen( argv[1], GA_ReadOnly );
if( hDataset != NULL )
{
int a;
GDAL_GCP* gcp_list;
OGRSpatialReferenceH gcp_hSRS, output_hSRS;
OGRCoordinateTransformationH trans;
char * gcp_proj, *proj4_proj;
gcp_list = GDALGetGCPs(hDataset);
/* Get GCP projection.. */
gcp_proj = (char *)GDALGetGCPProjection(hDataset);
/* Get Projection .. */
gcp_hSRS = OSRNewSpatialReference(NULL);
output_hSRS = OSRNewSpatialReference(NULL);
OSRSetWellKnownGeogCS(output_hSRS, "WGS84");
OSRImportFromWkt(gcp_hSRS,&gcp_proj);
OSRExportToProj4(gcp_hSRS,&proj4_proj);
trans=OCTNewCoordinateTransformation(gcp_hSRS,output_hSRS);
/*Something like: "--- \n- a: 2\n b: 4\n- 2\n- 3\n- 4\n" */
printf("--- \n");
for (a=0; a<GDALGetGCPCount(hDataset); a++ ) {
printf("- x: %g\n", gcp_list[a].dfGCPPixel);
printf(" y: %g\n", gcp_list[a].dfGCPLine);
printf(" gx: %15.5f\n", gcp_list[a].dfGCPX);
printf(" gy: %15.5f\n", gcp_list[a].dfGCPY);
printf(" name: '%s'\n", gcp_list[a].pszId);
printf(" info: '%s'\n", gcp_list[a].pszInfo);
printf(" id: %d\n", a);
printf(" proj: \'%s\'\n", GDALGetGCPProjection(hDataset));
printf(" proj4: \'%s\'\n", proj4_proj);
OCTTransform(trans,1, &(gcp_list[a].dfGCPX), &(gcp_list[a].dfGCPY), NULL);
printf(" lon: %15.5f\n", gcp_list[a].dfGCPX);
printf(" lat: %15.5f\n", gcp_list[a].dfGCPY);
};
}
else {
fprintf(stderr, "ERROR: could not open \"%s\"\n", argv[1]);
}
}