[Geotiff] Copy projection between GeoTIFFs
jeskynar
jeskynar at hotmail.com
Wed Nov 12 07:52:10 EST 2008
warmerdam at pobox.com wrote:
> The listgeo and geotifcp cannot be used to reset the geotiff information
> "in place" as things stand though this can be accomplished using the API
> with some care. GDAL does this for instance.
Do you mean there is a GDAL utility or something in the API?
> It would be relatively easy to modify geotifcp to have a "reset geo tags
> from metadata file, but do nothing else" option or perhaps write a small
> new utility called "applygeo". However, I'm not likely to do so.
Below is my attempt an applygeo.c, but I haven't used the libgeotiff API
"with some care" because it doesn't appear to do anything! And if I add
a call to TIFFRewriteDirectory before XTIFFClose it crashes (assertion
tif_flags&0x80000 failed). Any ideas?
/* applygeo.c */
#include
#include
#include "geotiff.h"
#include "xtiffio.h"
static int
InstallGeoTIFF(const char *geofile, const char *tiffile)
{
TIFF *tif = (TIFF*)0; /* TIFF-level descriptor */
GTIF *gtif=(GTIF*)0; /* GeoKey-level descriptor */
FILE *fp;
tif = XTIFFOpen(tiffile, "r+");
if (!tif)
{
perror(tiffile);
fprintf(stderr, "Cannot open TIFF file %s (does not exist or not a valid TIFF file)\n", tiffile);
return(-1);
}
gtif = GTIFNew(tif);
if (!gtif)
{
fprintf(stderr, "Internal error (GTIFNew)\n");
return(-2);
}
/* Read GeoTIFF projection information from geofile */
fp = fopen(geofile, "r");
if( fp == NULL )
{
perror( geofile );
fprintf(stderr, "Cannot open projection definition file %s\n", geofile);
return(-3);
}
if (!GTIFImport(gtif, 0, fp))
{
fprintf(stderr,"Projection definition file is not valid (%s)\n", geofile);
return(-4);
}
fclose(fp);
/* Install GeoTIFF keys into the TIFF file */
GTIFWriteKeys(gtif);
/* Clean up */
GTIFFree(gtif);
/*TIFFRewriteDirectory(tif);*/
XTIFFClose(tif);
return(0);
}
int
main(int argc, char *argv[])
{
char *usage = "usage: %s file.geo file.tiff\n"
"geo\tfile containing projection (eg. from listgeo)\n"
"tiff\tTIFF file into which the projection is written\n";
char *prog;
char *geofile;
char *tiffile;
int rc;
prog = argv[0];
geofile = argv[1];
tiffile = argv[2];
if (!geofile || !tiffile)
{
fprintf(stderr, usage, prog);
exit(1);
}
rc = InstallGeoTIFF(geofile, tiffile);
if (rc)
{
fprintf(stderr, "%s: error %d applying projection from %s into TIFF %s\n", prog, rc, geofile, tiffile);
exit(2);
}
return(0);
}
_________________________________________________________________
Windows Live Hotmail now works up to 70% faster.
http://windowslive.com/Explore/Hotmail?ocid=TXT_TAGLM_WL_hotmail_acq_faster_112008
More information about the Geotiff
mailing list