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

◆ getSRSbySRID()

char * getSRSbySRID ( FunctionCallInfo  fcinfo,
int32_t  srid,
bool  short_crs 
)

Definition at line 66 of file lwgeom_export.c.

67{
68 static const uint16_t max_query_size = 512;
69 char query[512];
70 char *srs, *srscopy;
71 int size, err;
72 postgis_initialize_cache(fcinfo);
73
74 if (SPI_OK_CONNECT != SPI_connect ())
75 {
76 elog(NOTICE, "getSRSbySRID: could not connect to SPI manager");
77 SPI_finish();
78 return NULL;
79 }
80
81 if (short_crs)
82 snprintf(query,
83 max_query_size,
84 "SELECT auth_name||':'||auth_srid \
85 FROM %s WHERE srid='%d'",
86 postgis_spatial_ref_sys(),
87 srid);
88 else
89 snprintf(query,
90 max_query_size,
91 "SELECT 'urn:ogc:def:crs:'||auth_name||'::'||auth_srid \
92 FROM %s WHERE srid='%d'",
93 postgis_spatial_ref_sys(),
94 srid);
95
96 err = SPI_exec(query, 1);
97 if ( err < 0 )
98 {
99 elog(NOTICE, "getSRSbySRID: error executing query %d", err);
100 SPI_finish();
101 return NULL;
102 }
103
104 /* no entry in spatial_ref_sys */
105 if (SPI_processed <= 0)
106 {
107 SPI_finish();
108 return NULL;
109 }
110
111 /* get result */
112 srs = SPI_getvalue(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1);
113
114 /* NULL result */
115 if ( ! srs )
116 {
117 SPI_finish();
118 return NULL;
119 }
120
121 /* copy result to upper executor context */
122 size = strlen(srs)+1;
123 srscopy = SPI_palloc(size);
124 memcpy(srscopy, srs, size);
125
126 /* disconnect from SPI */
127 SPI_finish();
128
129 return srscopy;
130}

Referenced by geography_as_geojson(), geography_as_gml(), LWGEOM_asGeoJson(), LWGEOM_asGML(), and LWGEOM_asX3D().

Here is the caller graph for this function: