PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ ST_AsMARC21()

Datum ST_AsMARC21 ( PG_FUNCTION_ARGS  )

Definition at line 51 of file lwgeom_out_marc21.c.

51  {
52  lwvarlena_t *marc21;
53  int32_t srid;
54  LWPROJ *lwproj;
55  LWGEOM *lwgeom;
56  //uint8_t is_latlong;
57  GSERIALIZED *gs = PG_GETARG_GSERIALIZED_P(0);
58  text *format_text_input = PG_GETARG_TEXT_P(1);
59  const char *format = text_to_cstring(format_text_input);
60 
61  srid = gserialized_get_srid(gs);
62 
63  if (srid == SRID_UNKNOWN) {
64 
65  PG_FREE_IF_COPY(gs, 0);
66  lwpgerror("ST_AsMARC21: Input geometry has unknown (%d) SRID", srid);
67  PG_RETURN_NULL();
68 
69  }
70 
71  if (lwproj_lookup(srid, srid, &lwproj) == LW_FAILURE) {
72 
73  PG_FREE_IF_COPY(gs, 0);
74  lwpgerror("ST_AsMARC21: Failure reading projections from spatial_ref_sys.");
75  PG_RETURN_NULL();
76 
77  }
78 
79 // if (GetLWPROJ(srid, srid, &lwproj) == LW_FAILURE) {
80 //
81 // PG_FREE_IF_COPY(gs, 0);
82 // lwpgerror("ST_AsMARC21: Failure reading projections from spatial_ref_sys.");
83 // PG_RETURN_NULL();
84 //
85 // }
86 
87 //#if POSTGIS_PROJ_VERSION < 61
88 // is_latlong = pj_is_latlong(lwproj->pj_from);
89 //#else
90 // is_latlong = lwproj->source_is_latlong;
91 //#endif
92 
93  //is_latlong = lwproj_is_latlong(lwproj);
94 
95  if (!lwproj_is_latlong(lwproj)) {
96 
97  PG_FREE_IF_COPY(gs, 0);
98  lwpgerror("ST_AsMARC21: Unsupported SRID (%d). Only lon/lat coordinate systems are supported in MARC21/XML Documents.", srid);
99  PG_RETURN_NULL();
100  }
101 
102 
103  lwgeom = lwgeom_from_gserialized(gs);
104  marc21 = lwgeom_to_marc21(lwgeom, format);
105 
106  if (marc21) PG_RETURN_TEXT_P(marc21);
107 
108  PG_RETURN_NULL();
109 }
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: gserialized.c:126
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
#define LW_FAILURE
Definition: liblwgeom.h:96
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:215
lwvarlena_t * lwgeom_to_marc21(const LWGEOM *geom, const char *format)

References gserialized_get_srid(), LW_FAILURE, lwgeom_from_gserialized(), lwgeom_to_marc21(), and SRID_UNKNOWN.

Here is the call graph for this function: