1
1
/******************************************************************************
2
* $Id: gdaljp2metadata.cpp 17636 2009-09-12 23:19:18Z warmerdam $
2
* $Id: gdaljp2metadata.cpp 22678 2011-07-09 19:47:12Z rouault $
5
5
* Purpose: GDALJP2Metadata - Read GeoTIFF and/or GML georef info.
33
33
#include "ogr_spatialref.h"
34
34
#include "ogr_geometry.h"
35
35
#include "ogr_api.h"
36
#include "gt_wkt_srs_for_gdal.h"
37
CPL_CVSID("$Id: gdaljp2metadata.cpp 17636 2009-09-12 23:19:18Z warmerdam $");
38
CPL_CVSID("$Id: gdaljp2metadata.cpp 22678 2011-07-09 19:47:12Z rouault $");
39
40
static const unsigned char msi_uuid2[16] =
40
41
{0xb1,0x4b,0xf8,0xbd,0x08,0x3d,0x4b,0x43,
44
45
{ 0x96,0xA9,0xF1,0xF1,0xDC,0x98,0x40,0x2D,
45
46
0xA7,0xAE,0xD6,0x8E,0x34,0x45,0x18,0x09 };
48
CPLErr CPL_DLL GTIFMemBufFromWkt( const char *pszWKT,
49
const double *padfGeoTransform,
50
int nGCPCount, const GDAL_GCP *pasGCPList,
51
int *pnSize, unsigned char **ppabyBuffer );
52
CPLErr CPL_DLL GTIFWktFromMemBuf( int nSize, unsigned char *pabyBuffer,
53
char **ppszWKT, double *padfGeoTransform,
54
int *pnGCPCount, GDAL_GCP **ppasGCPList );
48
static const unsigned char xmp_uuid[16] =
49
{ 0xBE,0x7A,0xCF,0xCB,0x97,0xA9,0x42,0xE8,
50
0x9C,0x71,0x99,0x94,0x91,0xE3,0xAF,0xAC};
57
52
/************************************************************************/
58
53
/* GDALJP2Metadata() */
100
98
CPLFree( pabyGeoTIFFData );
101
99
CPLFree( pabyMSIGData );
102
100
CSLDestroy( papszGMLMetadata );
101
CSLDestroy( papszMetadata );
102
CPLFree( pszXMPMetadata );
105
105
/************************************************************************/
220
220
if( EQUAL(oBox.GetType(),"uuid")
221
221
&& memcmp( oBox.GetUUID(), msi_uuid2, 16 ) == 0 )
223
nGeoTIFFSize = (int) oBox.GetDataLength();
223
nGeoTIFFSize = (int) oBox.GetDataLength();
224
224
pabyGeoTIFFData = oBox.ReadBoxData();
230
230
if( EQUAL(oBox.GetType(),"uuid")
231
231
&& memcmp( oBox.GetUUID(), msig_uuid, 16 ) == 0 )
233
nMSIGSize = (int) oBox.GetDataLength();
233
nMSIGSize = (int) oBox.GetDataLength();
234
234
pabyMSIGData = oBox.ReadBoxData();
236
236
if( nMSIGSize < 70
245
245
/* -------------------------------------------------------------------- */
246
/* Collect XMP box. */
247
/* -------------------------------------------------------------------- */
248
if( EQUAL(oBox.GetType(),"uuid")
249
&& memcmp( oBox.GetUUID(), xmp_uuid, 16 ) == 0 &&
250
pszXMPMetadata == NULL )
252
pszXMPMetadata = (char*) oBox.ReadBoxData();
255
/* -------------------------------------------------------------------- */
246
256
/* Process asoc box looking for Labelled GML data. */
247
257
/* -------------------------------------------------------------------- */
248
258
if( EQUAL(oBox.GetType(),"asoc") )
276
286
CPLFree( pszXML );
289
/* -------------------------------------------------------------------- */
290
/* Check for a resd box in jp2h. */
291
/* -------------------------------------------------------------------- */
292
if( EQUAL(oBox.GetType(),"jp2h") )
294
GDALJP2Box oSubBox( fpVSIL );
296
for( oSubBox.ReadFirstChild( &oBox );
297
strlen(oSubBox.GetType()) > 0;
298
oSubBox.ReadNextChild( &oBox ) )
300
if( EQUAL(oSubBox.GetType(),"res ") )
302
GDALJP2Box oResBox( fpVSIL );
304
oResBox.ReadFirstChild( &oSubBox );
306
// we will use either the resd or resc box, which ever
307
// happens to be first. Should we prefer resd?
308
if( oResBox.GetDataLength() == 10 )
310
unsigned char *pabyResData = oResBox.ReadBoxData();
311
int nVertNum, nVertDen, nVertExp;
312
int nHorzNum, nHorzDen, nHorzExp;
314
nVertNum = pabyResData[0] * 256 + pabyResData[1];
315
nVertDen = pabyResData[2] * 256 + pabyResData[3];
316
nHorzNum = pabyResData[4] * 256 + pabyResData[5];
317
nHorzDen = pabyResData[6] * 256 + pabyResData[7];
318
nVertExp = pabyResData[8];
319
nHorzExp = pabyResData[9];
321
// compute in pixels/cm
323
(nVertNum/(double)nVertDen) * pow(10.0,nVertExp)/100;
325
(nHorzNum/(double)nHorzDen) * pow(10.0,nHorzExp)/100;
326
CPLString osFormatter;
328
papszMetadata = CSLSetNameValue(
330
"TIFFTAG_XRESOLUTION",
331
osFormatter.Printf("%g",dfHorzRes) );
333
papszMetadata = CSLSetNameValue(
335
"TIFFTAG_YRESOLUTION",
336
osFormatter.Printf("%g",dfVertRes) );
337
papszMetadata = CSLSetNameValue(
339
"TIFFTAG_RESOLUTIONUNIT",
342
CPLFree( pabyResData );
810
879
/* -------------------------------------------------------------------- */
811
880
if( CPLGetConfigOption( "GMLJP2OVERRIDE", NULL ) != NULL )
813
FILE *fp = VSIFOpenL( CPLGetConfigOption( "GMLJP2OVERRIDE",""), "r" );
882
VSILFILE *fp = VSIFOpenL( CPLGetConfigOption( "GMLJP2OVERRIDE",""), "r" );
814
883
char *pszGML = NULL;
936
1005
"<gml:FeatureCollection\n"
937
1006
" xmlns:gml=\"http://www.opengis.net/gml\"\n"
938
1007
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
939
" xsi:schemaLocation=\"http://www.opengeospatial.net/gml http://schemas.opengis.net/gml/3.1.1/profiles/gmlJP2Profile/1.0.0/gmlJP2Profile.xsd\">\n"
1008
" xsi:schemaLocation=\"http://www.opengis.net/gml http://schemas.opengis.net/gml/3.1.1/profiles/gmlJP2Profile/1.0.0/gmlJP2Profile.xsd\">\n"
940
1009
" <gml:boundedBy>\n"
941
1010
" <gml:Null>withheld</gml:Null>\n"
942
1011
" </gml:boundedBy>\n"