Changeset 12388

Show
Ignore:
Timestamp:
10/12/07 21:44:13 (1 year ago)
Author:
warmerdam
Message:

Fix handling of gmljp2 files with srsName only on Envelope (#1906)
Fix handling of urn:x-ogc (use importFromURN() method). Add GMLJP2OVERRIDE
configuration option mechanism to set custom GMLJP2 from a file.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/gdal/gcore/gdaljp2metadata.cpp

    r10645 r12388  
    629629 
    630630/* -------------------------------------------------------------------- */ 
     631/*      If we still don't have an srsName, check for it on the          */ 
     632/*      boundedBy Envelope.  Some products                              */ 
     633/*      (ie. EuropeRasterTile23.jpx) use this as the only srsName       */ 
     634/*      delivery vehicle.                                               */ 
     635/* -------------------------------------------------------------------- */ 
     636    if( pszSRSName == NULL ) 
     637    { 
     638        pszSRSName =  
     639            CPLGetXMLValue( psXML, 
     640                            "=FeatureCollection.boundedBy.Envelope.srsName", 
     641                            NULL ); 
     642    } 
     643 
     644/* -------------------------------------------------------------------- */ 
    631645/*      If we have gotten a geotransform, then try to interprete the    */ 
    632646/*      srsName.                                                        */ 
     
    635649        && (pszProjection == NULL || strlen(pszProjection) == 0) ) 
    636650    { 
     651        OGRSpatialReference oSRS; 
     652 
    637653        if( EQUALN(pszSRSName,"epsg:",5) ) 
    638654        { 
    639             OGRSpatialReference oSRS; 
    640655            if( oSRS.SetFromUserInput( pszSRSName ) == OGRERR_NONE ) 
    641656                oSRS.exportToWkt( &pszProjection ); 
    642657        } 
    643         else if( EQUALN(pszSRSName,"urn:ogc:def:crs:EPSG::",22) ) 
    644         { 
    645             OGRSpatialReference oSRS; 
    646             if( oSRS.importFromEPSG( atoi(pszSRSName + 22) ) == OGRERR_NONE ) 
    647                 oSRS.exportToWkt( &pszProjection ); 
    648         } 
    649         else if( EQUALN(pszSRSName,"urn:ogc:def:crs:EPSG:",21) ) 
    650         { 
    651             const char *pszCode = pszSRSName+21; 
    652             while( *pszCode != ':' && *pszCode != '\0' ) 
    653                 pszCode++; 
    654  
    655             OGRSpatialReference oSRS; 
    656             if( oSRS.importFromEPSG( atoi(pszCode+1) ) == OGRERR_NONE ) 
    657                 oSRS.exportToWkt( &pszProjection ); 
     658        else if( EQUALN(pszSRSName,"urn:",4)  
     659                 && strstr(pszSRSName,":def:") != NULL 
     660                 && oSRS.importFromURN(pszSRSName) == OGRERR_NONE ) 
     661        { 
     662            oSRS.exportToWkt( &pszProjection ); 
    658663        } 
    659664        else if( !GMLSRSLookup( pszSRSName ) ) 
     
    752757 
    753758{ 
     759/* -------------------------------------------------------------------- */ 
     760/*      This is a backdoor to let us embed a literal gmljp2 chunk       */ 
     761/*      supplied by the user as an external file.  This is mostly       */ 
     762/*      for preparing test files with exotic contents.                  */ 
     763/* -------------------------------------------------------------------- */ 
     764    if( CPLGetConfigOption( "GMLJP2OVERRIDE", NULL ) != NULL ) 
     765    { 
     766        FILE *fp = VSIFOpenL( CPLGetConfigOption( "GMLJP2OVERRIDE",""), "r" ); 
     767        char *pszGML = NULL; 
     768 
     769        if( fp == NULL ) 
     770        { 
     771            CPLError( CE_Failure, CPLE_AppDefined,  
     772                      "Unable to open GMLJP2OVERRIDE file." ); 
     773            return NULL; 
     774        } 
     775         
     776        VSIFSeekL( fp, 0, SEEK_END ); 
     777        int nLength = (int) VSIFTellL( fp ); 
     778        pszGML = (char *) CPLCalloc(1,nLength+1); 
     779        VSIFSeekL( fp, 0, SEEK_SET ); 
     780        VSIFReadL( pszGML, 1, nLength, fp ); 
     781        VSIFCloseL( fp ); 
     782 
     783        GDALJP2Box *apoGMLBoxes[2]; 
     784 
     785        apoGMLBoxes[0] = GDALJP2Box::CreateLblBox( "gml.data" ); 
     786        apoGMLBoxes[1] =  
     787            GDALJP2Box::CreateLabelledXMLAssoc( "gml.root-instance",  
     788                                                pszGML ); 
     789 
     790        GDALJP2Box *poGMLData = GDALJP2Box::CreateAsocBox( 2, apoGMLBoxes); 
     791         
     792        delete apoGMLBoxes[0]; 
     793        delete apoGMLBoxes[1]; 
     794 
     795        CPLFree( pszGML ); 
     796         
     797        return poGMLData; 
     798    } 
     799 
    754800/* -------------------------------------------------------------------- */ 
    755801/*      Try do determine a PCS or GCS code we can use.                  */