PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ srs_find_planar()

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

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

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