PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ srs_find_planar()

static void srs_find_planar ( const char *  auth_name,
const LWGEOM bounds,
struct srs_data state 
)
static

Definition at line 456 of file postgis/lwgeom_transform.c.

457 {
458  int32_t srid_from = lwgeom_get_srid(bounds);
459  const int32_t srid_to = 4326;
460  GBOX gbox = *(lwgeom_get_bbox(bounds));
461  PJ_TYPE types[1] = {PJ_TYPE_PROJECTED_CRS};
462  PROJ_CRS_INFO **crs_list_ptr, **crs_list;
463  int crs_count;
464  PJ_CONTEXT *ctx = NULL;
465 
466  PROJ_CRS_LIST_PARAMETERS *params = proj_get_crs_list_parameters_create();
467  params->types = types;
468  params->typesCount = 1;
469  params->crs_area_of_use_contains_bbox = true;
470  params->bbox_valid = true;
471  params->allow_deprecated = false;
472 
473 #if POSTGIS_PROJ_VERSION >= 81
474  params->celestial_body_name = "Earth";
475 #endif
476 
477  if (srid_from != srid_to)
478  {
479  LWPROJ *pj;
480  if (lwproj_lookup(srid_from, srid_to, &pj) == LW_FAILURE)
481  elog(ERROR, "%s: Lookup of SRID %u => %u transform failed",
482  __func__, srid_from, srid_to);
483 
484  box3d_transform(&gbox, pj);
485  }
486 
487  params->west_lon_degree = gbox.xmin;
488  params->south_lat_degree = gbox.ymin;
489  params->east_lon_degree = gbox.xmax;
490  params->north_lat_degree = gbox.ymax;
491 
492  crs_list = crs_list_ptr = proj_get_crs_info_list_from_database(
493  ctx, auth_name, params, &crs_count);
494 
495  /* TODO, throw out really huge / dumb areas? */
496 
497  while (crs_list && *crs_list)
498  {
499  /* Read current crs and move forward one entry */
500  PROJ_CRS_INFO *crs = *crs_list++;
501 
502  /* Read the corners of the CRS area of use */
503  double area;
504  double height = crs->north_lat_degree - crs->south_lat_degree;
505  double width = crs->east_lon_degree - crs->west_lon_degree;
506  if (width < 0.0)
507  width = 360 - (crs->west_lon_degree - crs->east_lon_degree);
508  area = width * height;
509 
510  /* Ensure there is space in the entry list */
511  srs_state_memcheck(state);
512 
513  /* Write the entry into the entry list and increment */
514  state->entries[state->num_entries].auth_name = cstring_to_text(crs->auth_name);
515  state->entries[state->num_entries].auth_code = cstring_to_text(crs->code);
516  state->entries[state->num_entries].sort = area;
517  state->num_entries++;
518  }
519 
520  /* Put the list of entries into order of area size, smallest to largest */
521  qsort(state->entries, state->num_entries, sizeof(struct srs_data), srs_entry_cmp);
522 
523  proj_crs_info_list_destroy(crs_list_ptr);
524  proj_get_crs_list_parameters_destroy(params);
525 }
int32_t lwgeom_get_srid(const LWGEOM *geom)
Return SRID number.
Definition: lwgeom.c:927
#define LW_FAILURE
Definition: liblwgeom.h:96
int box3d_transform(GBOX *box, LWPROJ *pj)
const GBOX * lwgeom_get_bbox(const LWGEOM *lwgeom)
Get a non-empty geometry bounding box, computing and caching it if not already there.
Definition: lwgeom.c:743
static void srs_state_memcheck(struct srs_data *state)
static int srs_entry_cmp(const void *a, const void *b)
double ymax
Definition: liblwgeom.h:357
double xmax
Definition: liblwgeom.h:355
double ymin
Definition: liblwgeom.h:356
double xmin
Definition: liblwgeom.h:354
struct srs_entry * entries
text * auth_name
text * auth_code
double sort

References srs_entry::auth_code, srs_entry::auth_name, box3d_transform(), srs_data::entries, LW_FAILURE, lwgeom_get_bbox(), lwgeom_get_srid(), srs_data::num_entries, srs_entry::sort, srs_entry_cmp(), srs_state_memcheck(), GBOX::xmax, GBOX::xmin, GBOX::ymax, and GBOX::ymin.

Referenced by postgis_srs_search().

Here is the call graph for this function:
Here is the caller graph for this function: