ECC-1552: GRIB: return non empty proj string for unprojected gridded fields

This commit is contained in:
Shahram Najm 2023-03-15 21:18:09 +00:00
parent 2a9879b6ca
commit c6f0164f93
2 changed files with 37 additions and 21 deletions

View File

@ -159,17 +159,17 @@ static int get_native_type(grib_accessor* a)
return GRIB_TYPE_STRING;
}
/* Function pointer than takes a handle and returns the proj string */
// Function pointer than takes a handle and returns the proj string
typedef int (*proj_func)(grib_handle*, char*);
struct proj_mapping
{
const char* gridType; /* key gridType */
proj_func func; /* function to compute proj string */
const char* gridType; // key gridType
proj_func func; // function to compute proj string
};
typedef struct proj_mapping proj_mapping;
/* This should only be called for GRID POINT data (not spherical harmonics etc) */
// This should only be called for GRID POINT data (not spherical harmonics etc)
static int get_major_minor_axes(grib_handle* h, double* pMajor, double* pMinor)
{
int err = 0;
@ -185,7 +185,7 @@ static int get_major_minor_axes(grib_handle* h, double* pMajor, double* pMinor)
return err;
}
/* Caller must have allocated enough space in the 'result' argument */
// Caller must have allocated enough space in the 'result' argument
static int get_earth_shape(grib_handle* h, char* result)
{
int err = 0;
@ -193,22 +193,11 @@ static int get_earth_shape(grib_handle* h, char* result)
if ((err = get_major_minor_axes(h, &major, &minor)) != GRIB_SUCCESS)
return err;
if (major == minor)
snprintf(result, 128, "+R=%lf", major); /* spherical */
snprintf(result, 128, "+R=%lf", major); // spherical
else
snprintf(result, 128, "+a=%lf +b=%lf", major, minor); /*oblate*/
snprintf(result, 128, "+a=%lf +b=%lf", major, minor); // oblate
return err;
}
#if 0
static int proj_regular_latlon(grib_handle* h, char* result)
{
int err = 0;
char shape[64] = {0,};
if ((err = get_earth_shape(h, shape)) != GRIB_SUCCESS)
return err;
snprintf(result, 128, "+proj=latlong %s", shape);
return err;
}
#endif
static int proj_space_view(grib_handle* h, char* result)
{
@ -305,6 +294,18 @@ static int proj_polar_stereographic(grib_handle* h, char* result)
return err;
}
// This is for regular_ll, regular_gg, reduced_ll, reduced_gg
static int proj_unprojected(grib_handle* h, char* result)
{
int err = 0;
char shape[64] = {0,};
if ((err = get_earth_shape(h, shape)) != GRIB_SUCCESS)
return err;
snprintf(result, 1024, "+proj=longlat %s", shape);
return err;
}
static int proj_mercator(grib_handle* h, char* result)
{
int err = 0;
@ -322,7 +323,10 @@ static int proj_mercator(grib_handle* h, char* result)
#define NUMBER(a) (sizeof(a) / sizeof(a[0]))
static proj_mapping proj_mappings[] = {
/*{ "regular_ll", &proj_regular_latlon },*/
{ "regular_ll", &proj_unprojected },
{ "regular_gg", &proj_unprojected },
{ "reduced_ll", &proj_unprojected },
{ "reduced_gg", &proj_unprojected },
{ "mercator", &proj_mercator },
{ "lambert", &proj_lambert_conformal },
@ -358,7 +362,7 @@ static int unpack_string(grib_accessor* a, char* v, size_t* len)
snprintf(v, 64, "EPSG:4326");
}
else {
/* Invoke the appropriate function to get the target proj string */
// Invoke the appropriate function to get the target proj string
if ((err = pm.func(h, v)) != GRIB_SUCCESS) return err;
}
}

View File

@ -45,7 +45,19 @@ for f in `echo $files`; do
fi
done
# Various grids
# Various grid types
${tools_dir}/grib_get -p projString $grib2_sample > $tempText
grep -q "proj=longlat" $tempText
${tools_dir}/grib_get -p projString $ECCODES_SAMPLES_PATH/regular_ll_pl_grib2.tmpl > $tempText
grep -q "proj=longlat" $tempText
${tools_dir}/grib_get -p projString $ECCODES_SAMPLES_PATH/regular_gg_ml_grib1.tmpl > $tempText
grep -q "proj=longlat" $tempText
${tools_dir}/grib_get -p projString $ECCODES_SAMPLES_PATH/reduced_ll_sfc_grib1.tmpl > $tempText
grep -q "proj=longlat" $tempText
${tools_dir}/grib_get -p projString $ECCODES_SAMPLES_PATH/reduced_gg_pl_32_grib2.tmpl > $tempText
grep -q "proj=longlat" $tempText
${tools_dir}/grib_set -s gridType=lambert_azimuthal_equal_area $grib2_sample $tempGrib
${tools_dir}/grib_get -p projString $tempGrib > $tempText
grep -q "proj=laea" $tempText