PostGIS  3.7.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 466 of file postgis/lwgeom_transform.c.

467 {
468  int32_t srid_from = lwgeom_get_srid(bounds);
469  const int32_t srid_to = 4326;
470  GBOX gbox = *(lwgeom_get_bbox(bounds));
471  PJ_TYPE types[1] = {PJ_TYPE_PROJECTED_CRS};
472  PROJ_CRS_INFO **crs_list_ptr, **crs_list;
473  int crs_count;
474  PJ_CONTEXT *ctx = NULL;
475 
476  PROJ_CRS_LIST_PARAMETERS *params = proj_get_crs_list_parameters_create();
477  params->types = types;
478  params->typesCount = 1;
479  params->crs_area_of_use_contains_bbox = true;
480  params->bbox_valid = true;
481  params->allow_deprecated = false;
482 
483 #if POSTGIS_PROJ_VERSION >= 80100
484  params->celestial_body_name = "Earth";
485 #endif
486 
487  if (srid_from != srid_to)
488  {
489  LWPROJ *pj;
490  if (lwproj_lookup(srid_from, srid_to, &pj) == LW_FAILURE)
491  elog(ERROR, "%s: Lookup of SRID %u => %u transform failed",
492  __func__, srid_from, srid_to);
493 
494  box3d_transform(&gbox, pj);
495  }
496 
497  params->west_lon_degree = gbox.xmin;
498  params->south_lat_degree = gbox.ymin;
499  params->east_lon_degree = gbox.xmax;
500  params->north_lat_degree = gbox.ymax;
501 
502  crs_list = crs_list_ptr = proj_get_crs_info_list_from_database(
503  ctx, auth_name, params, &crs_count);
504 
505  /* TODO, throw out really huge / dumb areas? */
506 
507  while (crs_list && *crs_list)
508  {
509  /* Read current crs and move forward one entry */
510  PROJ_CRS_INFO *crs = *crs_list++;
511 
512  /* Read the corners of the CRS area of use */
513  double area;
514  double height = crs->north_lat_degree - crs->south_lat_degree;
515  double width = crs->east_lon_degree - crs->west_lon_degree;
516  if (width < 0.0)
517  width = 360 - (crs->west_lon_degree - crs->east_lon_degree);
518  area = width * height;
519 
520  /* Ensure there is space in the entry list */
521  srs_state_memcheck(state);
522 
523  /* Write the entry into the entry list and increment */
524  state->entries[state->num_entries].auth_name = cstring_to_text(crs->auth_name);
525  state->entries[state->num_entries].auth_code = cstring_to_text(crs->code);
526  state->entries[state->num_entries].sort = area;
527  state->num_entries++;
528  }
529 
530  /* Put the list of entries into order of area size, smallest to largest */
531  qsort(state->entries, state->num_entries, sizeof(struct srs_data), srs_entry_cmp);
532 
533  proj_crs_info_list_destroy(crs_list_ptr);
534  proj_get_crs_list_parameters_destroy(params);
535 }
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: