PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ postgis_srs_search()

Datum postgis_srs_search ( PG_FUNCTION_ARGS  )

Search for projections given extent and (optional) auth_name returns TABLE(auth_name, auth_srid, srtext, proj4text, point_sw, point_ne)

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

700 {
701  FuncCallContext *funcctx;
702  MemoryContext oldcontext;
703  struct srs_data *state;
704  Datum result;
705 
706  /*
707  * On the first call, fill in the state with all
708  * of the auth_name/auth_srid pairings in the
709  * proj database. Then the per-call routine is just
710  * one isolated call per pair.
711  */
712  if (SRF_IS_FIRSTCALL())
713  {
714  GSERIALIZED *gbounds = PG_GETARG_GSERIALIZED_P(0);
715  LWGEOM *bounds = lwgeom_from_gserialized(gbounds);
716  text *auth_name = PG_GETARG_TEXT_P(1);
717 
718  funcctx = SRF_FIRSTCALL_INIT();
719  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
720 
721  /*
722  * Could read all authorities from database, but includes
723  * authorities (IGN, OGC) that use non-integral values in
724  * auth_srid. So hand-coded list for now.
725  */
726  state = srs_state_init();
727 
728  /* Run the Proj query */
729  srs_find_planar(text_to_cstring(auth_name), bounds, state);
730 
731  /*
732  * Read the TupleDesc from the FunctionCallInfo. The SQL definition
733  * of the function must have the right number of fields and types
734  * to match up to this C code.
735  */
736  if (get_call_result_type(fcinfo, 0, &funcctx->tuple_desc) != TYPEFUNC_COMPOSITE)
737  {
738  ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
739  errmsg("%s called with incompatible return type", __func__)));
740  }
741 
742  BlessTupleDesc(funcctx->tuple_desc);
743  funcctx->user_fctx = state;
744  MemoryContextSwitchTo(oldcontext);
745  }
746 
747  /* Stuff done on every call of the function */
748  funcctx = SRF_PERCALL_SETUP();
749  state = funcctx->user_fctx;
750 
751  /* Exit when we've read all entries */
752  if (!state->num_entries ||
753  state->current_entry == state->num_entries)
754  {
755  SRF_RETURN_DONE(funcctx);
756  }
757 
758  /* Lookup the srtext/proj4text for this entry */
760  state->entries + state->current_entry++,
761  funcctx->tuple_desc);
762 
763  if (result)
764  SRF_RETURN_NEXT(funcctx, result);
765 
766  /* Stop if lookup fails drastically */
767  SRF_RETURN_DONE(funcctx);
768 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:268
static struct srs_data * srs_state_init()
static Datum srs_tuple_from_entry(const struct srs_entry *entry, TupleDesc tuple_desc)
static void srs_find_planar(const char *auth_name, const LWGEOM *bounds, struct srs_data *state)
struct srs_entry * entries

References srs_data::current_entry, srs_data::entries, lwgeom_from_gserialized(), srs_data::num_entries, result, srs_find_planar(), srs_state_init(), and srs_tuple_from_entry().

Here is the call graph for this function: