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

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