Changeset 13874

Show
Ignore:
Timestamp:
02/25/08 13:34:26 (5 months ago)
Author:
warmerdam
Message:

improve coordinate system error handling, fix mercator scaling

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • spike/grib/gribdataset.cpp

    r13841 r13874  
    397397      case GS3_MERCATOR: 
    398398        oSRS.SetMercator(meta->gds.meshLat, meta->gds.orientLon, 
    399                          meta->gds.scaleLat1,  
    400                          0.0, 0.0); 
     399                         1.0, 0.0, 0.0); 
    401400        break; 
    402401      case GS3_POLAR: 
     
    438437                        NULL, 
    439438                        "Sphere", 
    440                         a, 0.0, 
    441                         "Greenwich", 0.0, 
    442                         NULL, 0.0); 
     439                        a, 0.0 ); 
    443440    } 
    444441    else 
     
    448445                        NULL, 
    449446                        "Spheroid imported from GRIB file", 
    450                         a, fInv, 
    451                         "Greenwich", 0.0, 
    452                         NULL, 0.0); 
     447                        a, fInv ); 
    453448    } 
    454449 
     
    470465        rPixelSizeY = geosExtentInMeters / meta->gds.Ny; 
    471466    } 
    472     else 
     467    else if( oSRS.IsProjected() ) 
    473468    { 
    474469        rMinX = meta->gds.lon1; // longitude in degrees, to be transformed to meters (or degrees in case of latlon) 
     
    479474            if (meta->gds.scan == GRIB2BIT_2) // Y is minY, GDAL wants maxY 
    480475                rMaxY += (meta->gds.Ny - 1) * meta->gds.Dy; // -1 because we GDAL needs the coordinates of the centre of the pixel 
     476            rPixelSizeX = meta->gds.Dx; 
     477            rPixelSizeY = meta->gds.Dy; 
     478        } 
     479        else 
     480        { 
     481            rMinX = 0.0; 
     482            rMaxY = 0.0; 
     483             
     484            rPixelSizeX = 1.0; 
     485            rPixelSizeY = -1.0; 
     486             
     487            oSRS.Clear(); 
     488 
     489            CPLError( CE_Warning, CPLE_AppDefined, 
     490                      "Unable to perform coordinate transformations, so the correct\n" 
     491                      "projected geotransform could not be deduced from the lat/long\n" 
     492                      "control points.  Defaulting to ungeoreferenced." ); 
    481493        } 
    482494        delete poTransformLLtoSRS; 
     495    } 
     496    else 
     497    { 
     498        rMinX = meta->gds.lon1; // longitude in degrees, to be transformed to meters (or degrees in case of latlon) 
     499        rMaxY = meta->gds.lat1; // latitude in degrees, to be transformed to meters  
     500 
     501        if (meta->gds.scan == GRIB2BIT_2) // Y is minY, GDAL wants maxY 
     502            rMaxY += (meta->gds.Ny - 1) * meta->gds.Dy; // -1 because we GDAL needs the coordinates of the centre of the pixel 
    483503        rPixelSizeX = meta->gds.Dx; 
    484504        rPixelSizeY = meta->gds.Dy; 
    485505    } 
     506 
    486507    adfGeoTransform[0] = rMinX; 
    487508    adfGeoTransform[3] = rMaxY;