PostGIS  3.4.0dev-r@@SVN_REVISION@@
geography_inout.c
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  *
6  * PostGIS is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * PostGIS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with PostGIS. If not, see <http://www.gnu.org/licenses/>.
18  *
19  **********************************************************************
20  *
21  * Copyright 2009-2011 Paul Ramsey <pramsey@cleverelephant.ca>
22  *
23  **********************************************************************/
24 
25 
26 #include "postgres.h"
27 
28 #include "../postgis_config.h"
29 
30 #include <math.h>
31 #include <float.h>
32 #include <string.h>
33 #include <stdio.h>
34 
35 #include "utils/elog.h"
36 #include "utils/array.h"
37 #include "utils/builtins.h" /* for text_to_cstring */
38 #include "lib/stringinfo.h" /* For binary input */
39 #include "catalog/pg_type.h" /* for CSTRINGOID, INT4OID */
40 
41 #include "liblwgeom.h" /* For standard geometry types. */
42 #include "liblwgeom_internal.h"
43 #include "lwgeom_cache.h"
44 #include "lwgeom_pg.h" /* For debugging macros. */
45 #include "geography.h" /* For utility functions. */
46 #include "lwgeom_transform.h"
47 
48 Datum geography_in(PG_FUNCTION_ARGS);
49 Datum geography_out(PG_FUNCTION_ARGS);
50 
51 Datum geography_as_text(PG_FUNCTION_ARGS);
52 Datum geography_from_text(PG_FUNCTION_ARGS);
53 Datum geography_as_geojson(PG_FUNCTION_ARGS);
54 Datum geography_as_gml(PG_FUNCTION_ARGS);
55 Datum geography_as_kml(PG_FUNCTION_ARGS);
56 Datum geography_as_svg(PG_FUNCTION_ARGS);
57 Datum geography_from_binary(PG_FUNCTION_ARGS);
58 Datum geography_from_geometry(PG_FUNCTION_ARGS);
59 Datum geometry_from_geography(PG_FUNCTION_ARGS);
60 Datum geography_send(PG_FUNCTION_ARGS);
61 Datum geography_recv(PG_FUNCTION_ARGS);
62 
64 
71 {
72  if ( ! (
73  type == POINTTYPE ||
74  type == LINETYPE ||
75  type == POLYGONTYPE ||
76  type == MULTIPOINTTYPE ||
77  type == MULTILINETYPE ||
80  ) )
81  {
82  ereport(ERROR, (
83  errcode(ERRCODE_INVALID_PARAMETER_VALUE),
84  errmsg("Geography type does not support %s", lwtype_name(type) )));
85 
86  }
87 }
88 
90 {
91  GSERIALIZED *g_ser = NULL;
92 
93  /* Set geodetic flag */
94  lwgeom_set_geodetic(lwgeom, true);
95 
96  /* Check that this is a type we can handle */
97  geography_valid_type(lwgeom->type);
98 
99  /* Force the geometry to have valid geodetic coordinate range. */
100  lwgeom_nudge_geodetic(lwgeom);
101  if ( lwgeom_force_geodetic(lwgeom) == LW_TRUE )
102  {
103  ereport(NOTICE, (
104  errmsg_internal("Coordinate values were coerced into range [-180 -90, 180 90] for GEOGRAPHY" ))
105  );
106  }
107 
108  /* Force default SRID to the default */
109  if ( (int)lwgeom->srid <= 0 )
110  lwgeom->srid = SRID_DEFAULT;
111 
112  /*
113  ** Serialize our lwgeom and set the geodetic flag so subsequent
114  ** functions do the right thing.
115  */
116  g_ser = geography_serialize(lwgeom);
117 
118  /* Check for typmod agreement */
119  if ( geog_typmod >= 0 )
120  {
121  g_ser = postgis_valid_typmod(g_ser, geog_typmod);
122  POSTGIS_DEBUG(3, "typmod and geometry were consistent");
123  }
124  else
125  {
126  POSTGIS_DEBUG(3, "typmod was -1");
127  }
128 
129  return g_ser;
130 }
131 
132 
133 /*
134 ** geography_in(cstring) returns *GSERIALIZED
135 */
137 Datum geography_in(PG_FUNCTION_ARGS)
138 {
139  char *str = PG_GETARG_CSTRING(0);
140  /* Datum geog_oid = PG_GETARG_OID(1); Not needed. */
141  int32 geog_typmod = -1;
142  LWGEOM_PARSER_RESULT lwg_parser_result;
143  LWGEOM *lwgeom = NULL;
144  GSERIALIZED *g_ser = NULL;
145 
146  if ( (PG_NARGS()>2) && (!PG_ARGISNULL(2)) ) {
147  geog_typmod = PG_GETARG_INT32(2);
148  }
149 
150  lwgeom_parser_result_init(&lwg_parser_result);
151 
152  /* Empty string. */
153  if ( str[0] == '\0' )
154  ereport(ERROR,(errmsg("parse error - invalid geometry")));
155 
156  /* WKB? Let's find out. */
157  if ( str[0] == '0' )
158  {
159  /* TODO: 20101206: No parser checks! This is inline with current 1.5 behavior, but needs discussion */
161  /* Error out if something went sideways */
162  if ( ! lwgeom )
163  ereport(ERROR,(errmsg("parse error - invalid geometry")));
164  }
165  /* WKT then. */
166  else
167  {
168  if ( lwgeom_parse_wkt(&lwg_parser_result, str, LW_PARSER_CHECK_ALL) == LW_FAILURE )
169  PG_PARSER_ERROR(lwg_parser_result);
170 
171  lwgeom = lwg_parser_result.geom;
172  }
173 
174  /* Error on any SRID != default */
175  srid_check_latlong(lwgeom->srid);
176 
177  /* Convert to gserialized */
178  g_ser = gserialized_geography_from_lwgeom(lwgeom, geog_typmod);
179 
180  /* Clean up temporary object */
181  lwgeom_free(lwgeom);
182 
183 
184  PG_RETURN_POINTER(g_ser);
185 }
186 
187 /*
188 ** geography_out(*GSERIALIZED) returns cstring
189 */
191 Datum geography_out(PG_FUNCTION_ARGS)
192 {
193 
194  GSERIALIZED *g = PG_GETARG_GSERIALIZED_P(0);
195  LWGEOM *lwgeom = lwgeom_from_gserialized(g);
196  PG_RETURN_CSTRING(lwgeom_to_hexwkb_buffer(lwgeom, WKB_EXTENDED));
197 }
198 
199 
200 /*
201 ** geography_as_gml(*GSERIALIZED) returns text
202 */
204 Datum geography_as_gml(PG_FUNCTION_ARGS)
205 {
206  LWGEOM *lwgeom = NULL;
207  GSERIALIZED *g = NULL;
208  lwvarlena_t *v;
209  int version;
210  const char *srs;
211  int32_t srid = SRID_DEFAULT;
212  int precision = -1;
213  int option = 0;
214  int lwopts = LW_GML_IS_DIMS;
215  static const char *default_prefix = "gml:";
216  const char *prefix = default_prefix;
217  char *prefix_buf = "";
218  text *prefix_text, *id_text = NULL;
219  const char *id = NULL;
220  char *id_buf;
221 
222  /*
223  * Two potential callers, one starts with GML version,
224  * one starts with geography, and we check for initial
225  * argument type and then dynamically change what args
226  * we read based on presence/absence
227  */
228  Oid first_type = get_fn_expr_argtype(fcinfo->flinfo, 0);
229  int argnum = 0;
230  if (first_type != INT4OID)
231  {
232  version = 2;
233  }
234  else
235  {
236  /* Get the version */
237  version = PG_GETARG_INT32(argnum++);
238  if (version != 2 && version != 3)
239  {
240  elog(ERROR, "Only GML 2 and GML 3 are supported");
241  PG_RETURN_NULL();
242  }
243  }
244 
245  /* Get the parameters, both callers have same order */
246  g = PG_GETARG_GSERIALIZED_P(argnum++);
247  precision = PG_GETARG_INT32(argnum++);
248  option = PG_GETARG_INT32(argnum++);
249  prefix_text = PG_GETARG_TEXT_P(argnum++);
250  id_text = PG_GETARG_TEXT_P(argnum++);
251 
252  /* Convert to lwgeom so we can run the old functions */
253  lwgeom = lwgeom_from_gserialized(g);
254 
255  /* Condition the prefix argument */
256  if (VARSIZE_ANY_EXHDR(prefix_text) > 0)
257  {
258  /* +2 is one for the ':' and one for term null */
259  prefix_buf = palloc(VARSIZE_ANY_EXHDR(prefix_text)+2);
260  memcpy(prefix_buf, VARDATA_ANY(prefix_text),
261  VARSIZE_ANY_EXHDR(prefix_text));
262  /* add colon and null terminate */
263  prefix_buf[VARSIZE_ANY_EXHDR(prefix_text)] = ':';
264  prefix_buf[VARSIZE_ANY_EXHDR(prefix_text)+1] = '\0';
265  prefix = prefix_buf;
266  }
267  else
268  {
269  prefix = "";
270  }
271 
272  if (VARSIZE_ANY_EXHDR(id_text) > 0)
273  {
274  id_buf = palloc(VARSIZE_ANY_EXHDR(id_text)+2);
275  memcpy(id_buf, VARDATA(id_text), VARSIZE_ANY_EXHDR(id_text));
276  id_buf[VARSIZE_ANY_EXHDR(id_text)+1] = '\0';
277  id = id_buf;
278  }
279 
280  if (option & 1)
281  srs = GetSRSCacheBySRID(fcinfo, srid, false);
282  else
283  srs = GetSRSCacheBySRID(fcinfo, srid, true);
284  if (!srs)
285  {
286  elog(ERROR, "SRID %d unknown in spatial_ref_sys table", SRID_DEFAULT);
287  PG_RETURN_NULL();
288  }
289 
290  /* Revert lat/lon only with long SRS */
291  if (option & 1) lwopts |= LW_GML_IS_DEGREE;
292  if (option & 2) lwopts &= ~LW_GML_IS_DIMS;
293  if (option & 8)
294  {
295  elog(ERROR,
296  "Options %d passed to ST_AsGML(geography) sets "
297  "unsupported value 8",
298  option);
299  PG_RETURN_NULL();
300  }
301  if ((option & 4) || (option & 16) || (option & 32))
302  {
303  elog(ERROR,
304  "Options %d passed to ST_AsGML(geography) but are only "
305  "applicable to ST_AsGML(geometry)",
306  option);
307  PG_RETURN_NULL();
308  }
309 
310  if (version == 2)
311  v = lwgeom_to_gml2(lwgeom, srs, precision, prefix);
312  else
313  v = lwgeom_to_gml3(lwgeom, srs, precision, lwopts, prefix, id);
314 
315  if (!v)
316  PG_RETURN_NULL();
317  else
318  PG_RETURN_TEXT_P(v);
319 }
320 
321 
322 /*
323 ** geography_as_kml(*GSERIALIZED) returns text
324 */
326 Datum geography_as_kml(PG_FUNCTION_ARGS)
327 {
328 
329  lwvarlena_t *kml;
330  static const char *default_prefix = "";
331  char *prefixbuf;
332  const char *prefix = default_prefix;
333  GSERIALIZED *g = PG_GETARG_GSERIALIZED_P(0);
334  int precision = PG_GETARG_INT32(1);
335  text *prefix_text = PG_GETARG_TEXT_P(2);
336  LWGEOM *lwgeom = lwgeom_from_gserialized(g);
337 
338  /* Condition the precision */
339  if (precision < 0)
340  precision = 0;
341 
342  if (VARSIZE_ANY_EXHDR(prefix_text) > 0)
343  {
344  /* +2 is one for the ':' and one for term null */
345  prefixbuf = palloc(VARSIZE_ANY_EXHDR(prefix_text)+2);
346  memcpy(prefixbuf, VARDATA(prefix_text),
347  VARSIZE_ANY_EXHDR(prefix_text));
348  /* add colon and null terminate */
349  prefixbuf[VARSIZE_ANY_EXHDR(prefix_text)] = ':';
350  prefixbuf[VARSIZE_ANY_EXHDR(prefix_text)+1] = '\0';
351  prefix = prefixbuf;
352  }
353  else
354  {
355  prefix = "";
356  }
357 
358  kml = lwgeom_to_kml2(lwgeom, precision, prefix);
359  if (kml)
360  PG_RETURN_TEXT_P(kml);
361  PG_RETURN_NULL();
362 }
363 
364 
365 /*
366 ** geography_as_svg(*GSERIALIZED) returns text
367 */
369 Datum geography_as_svg(PG_FUNCTION_ARGS)
370 {
371  GSERIALIZED *g = PG_GETARG_GSERIALIZED_P(0);
372  int relative = PG_GETARG_INT32(1) ? 1 : 0;
373  int precision = PG_GETARG_INT32(2);
374  LWGEOM *lwgeom = lwgeom_from_gserialized(g);
375 
376  if (precision < 0)
377  precision = 0;
378 
379  PG_RETURN_TEXT_P(lwgeom_to_svg(lwgeom, precision, relative));
380 }
381 
382 
383 /*
384 ** geography_as_geojson(*GSERIALIZED) returns text
385 */
387 Datum geography_as_geojson(PG_FUNCTION_ARGS)
388 {
389  lwvarlena_t *geojson;
390  int has_bbox = 0;
391  const char *srs = NULL;
392  GSERIALIZED *g = PG_GETARG_GSERIALIZED_P(0);
393  int precision = PG_GETARG_INT32(1);
394  int option = PG_GETARG_INT32(2);
395  LWGEOM *lwgeom = lwgeom_from_gserialized(g);
396 
397  if (precision < 0)
398  precision = 0;
399 
400  /* Retrieve output option
401  * 0 = without option (default)
402  * 1 = bbox
403  * 2 = short crs
404  * 4 = long crs
405  */
406 
407  if (option & 2 || option & 4)
408  {
409  /* Geography only handle srid SRID_DEFAULT */
410  if (option & 2)
411  srs = GetSRSCacheBySRID(fcinfo, SRID_DEFAULT, true);
412  if (option & 4)
413  srs = GetSRSCacheBySRID(fcinfo, SRID_DEFAULT, false);
414 
415  if (!srs)
416  {
417  elog(ERROR, "SRID SRID_DEFAULT unknown in spatial_ref_sys table");
418  PG_RETURN_NULL();
419  }
420  }
421 
422  if (option & 1) has_bbox = 1;
423 
424  geojson = lwgeom_to_geojson(lwgeom, srs, precision, has_bbox);
425  lwgeom_free(lwgeom);
426  PG_FREE_IF_COPY(g, 0);
427 
428  PG_RETURN_TEXT_P(geojson);
429 }
430 
431 
432 /*
433 ** geography_from_text(*char) returns *GSERIALIZED
434 **
435 ** Convert text (varlena) to cstring and then call geography_in().
436 */
438 Datum geography_from_text(PG_FUNCTION_ARGS)
439 {
440  LWGEOM_PARSER_RESULT lwg_parser_result;
441  GSERIALIZED *g_ser = NULL;
442  text *wkt_text = PG_GETARG_TEXT_P(0);
443 
444  /* Extract the cstring from the varlena */
445  char *wkt = text_to_cstring(wkt_text);
446 
447  /* Pass the cstring to the input parser, and magic occurs! */
448  if ( lwgeom_parse_wkt(&lwg_parser_result, wkt, LW_PARSER_CHECK_ALL) == LW_FAILURE )
449  PG_PARSER_ERROR(lwg_parser_result);
450 
451  /* Error on any SRID != default */
452  srid_check_latlong(lwg_parser_result.geom->srid);
453 
454  /* Clean up string */
455  pfree(wkt);
456  g_ser = gserialized_geography_from_lwgeom(lwg_parser_result.geom, -1);
457 
458  /* Clean up temporary object */
459  lwgeom_free(lwg_parser_result.geom);
460 
461  PG_RETURN_POINTER(g_ser);
462 }
463 
464 /*
465 ** geography_from_binary(*char) returns *GSERIALIZED
466 */
468 Datum geography_from_binary(PG_FUNCTION_ARGS)
469 {
470  char *wkb_bytea = (char*)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
471  GSERIALIZED *gser = NULL;
472  size_t wkb_size = VARSIZE(wkb_bytea);
473  uint8_t *wkb = (uint8_t*)VARDATA(wkb_bytea);
474  LWGEOM *lwgeom = lwgeom_from_wkb(wkb, wkb_size, LW_PARSER_CHECK_NONE);
475 
476  if ( ! lwgeom )
477  lwpgerror("Unable to parse WKB");
478 
479  /* Error on any SRID != default */
480  srid_check_latlong(lwgeom->srid);
481 
482  gser = gserialized_geography_from_lwgeom(lwgeom, -1);
483  lwgeom_free(lwgeom);
484  PG_RETURN_POINTER(gser);
485 }
486 
487 
489 Datum geography_from_geometry(PG_FUNCTION_ARGS)
490 {
491  GSERIALIZED *g_ser = NULL;
492  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P_COPY(0);
493  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
494 
496 
497  /* Force default SRID */
498  if ( (int)lwgeom->srid <= 0 )
499  {
500  lwgeom->srid = SRID_DEFAULT;
501  }
502 
503  /* Error on any SRID != default */
504  srid_check_latlong(lwgeom->srid);
505 
506  /* Force the geometry to have valid geodetic coordinate range. */
507  lwgeom_nudge_geodetic(lwgeom);
508  if ( lwgeom_force_geodetic(lwgeom) == LW_TRUE )
509  {
510  ereport(NOTICE, (
511  errmsg_internal("Coordinate values were coerced into range [-180 -90, 180 90] for GEOGRAPHY" ))
512  );
513  }
514 
515  /* force recalculate of box by dropping */
516  lwgeom_drop_bbox(lwgeom);
517 
518  lwgeom_set_geodetic(lwgeom, true);
519  /* We are trusting geography_serialize will add a box if needed */
520  g_ser = geography_serialize(lwgeom);
521 
522 
523  lwgeom_free(lwgeom);
524 
525  PG_FREE_IF_COPY(geom, 0);
526  PG_RETURN_POINTER(g_ser);
527 }
528 
530 Datum geometry_from_geography(PG_FUNCTION_ARGS)
531 {
532  LWGEOM *lwgeom = NULL;
533  GSERIALIZED *ret = NULL;
534  GSERIALIZED *g_ser = PG_GETARG_GSERIALIZED_P(0);
535 
536  lwgeom = lwgeom_from_gserialized(g_ser);
537 
538  /* Recalculate the boxes after re-setting the geodetic bit */
539  lwgeom_set_geodetic(lwgeom, false);
540  lwgeom_refresh_bbox(lwgeom);
541 
542  /* We want "geometry" to think all our "geography" has an SRID, and the
543  implied SRID is the default, so we fill that in if our SRID is actually unknown. */
544  if ( (int)lwgeom->srid <= 0 )
545  lwgeom->srid = SRID_DEFAULT;
546 
547  ret = geometry_serialize(lwgeom);
548  lwgeom_free(lwgeom);
549 
550  PG_RETURN_POINTER(ret);
551 }
552 
554 Datum geography_recv(PG_FUNCTION_ARGS)
555 {
556  StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
557  int32 geog_typmod = -1;
558  LWGEOM *lwgeom = NULL;
559  GSERIALIZED *g_ser = NULL;
560 
561  if ( (PG_NARGS()>2) && (!PG_ARGISNULL(2)) ) {
562  geog_typmod = PG_GETARG_INT32(2);
563  }
564 
565  lwgeom = lwgeom_from_wkb((uint8_t*)buf->data, buf->len, LW_PARSER_CHECK_ALL);
566 
567  /* Error on any SRID != default */
568  srid_check_latlong(lwgeom->srid);
569 
570  g_ser = gserialized_geography_from_lwgeom(lwgeom, geog_typmod);
571 
572  /* Clean up temporary object */
573  lwgeom_free(lwgeom);
574 
575  /* Set cursor to the end of buffer (so the backend is happy) */
576  buf->cursor = buf->len;
577 
578  PG_RETURN_POINTER(g_ser);
579 }
580 
581 
583 Datum geography_send(PG_FUNCTION_ARGS)
584 {
585  GSERIALIZED *g = PG_GETARG_GSERIALIZED_P(0);
586  LWGEOM *lwgeom = lwgeom_from_gserialized(g);
587  PG_RETURN_POINTER(lwgeom_to_wkb_varlena(lwgeom, WKB_EXTENDED));
588 }
static uint8_t precision
Definition: cu_in_twkb.c:25
GSERIALIZED * postgis_valid_typmod(GSERIALIZED *gser, int32_t typmod)
Check the consistency of the metadata we want to enforce in the typmod: srid, type and dimensionality...
Datum geography_as_kml(PG_FUNCTION_ARGS)
Datum geography_from_geometry(PG_FUNCTION_ARGS)
Datum geometry_from_geography(PG_FUNCTION_ARGS)
GSERIALIZED * gserialized_geography_from_lwgeom(LWGEOM *lwgeom, int32 geog_typmod)
Datum geography_in(PG_FUNCTION_ARGS)
Datum geography_recv(PG_FUNCTION_ARGS)
Datum geography_send(PG_FUNCTION_ARGS)
Datum geography_from_text(PG_FUNCTION_ARGS)
Datum geography_as_text(PG_FUNCTION_ARGS)
Datum geography_out(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(geography_in)
void geography_valid_type(uint8_t type)
The geography type only support POINT, LINESTRING, POLYGON, MULTI* variants of same,...
Datum geography_from_binary(PG_FUNCTION_ARGS)
Datum geography_as_gml(PG_FUNCTION_ARGS)
Datum geography_as_geojson(PG_FUNCTION_ARGS)
Datum geography_as_svg(PG_FUNCTION_ARGS)
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
void lwgeom_refresh_bbox(LWGEOM *lwgeom)
Drop current bbox and calculate a fresh one.
Definition: lwgeom.c:707
#define LW_PARSER_CHECK_ALL
Definition: liblwgeom.h:2115
void lwgeom_set_geodetic(LWGEOM *geom, int value)
Set the FLAGS geodetic bit on geometry an all sub-geometries and pointlists.
Definition: lwgeom.c:964
#define COLLECTIONTYPE
Definition: liblwgeom.h:108
lwvarlena_t * lwgeom_to_kml2(const LWGEOM *geom, int precision, const char *prefix)
Definition: lwout_kml.c:44
#define LW_GML_IS_DEGREE
For GML3 only, declare that datas are lat/lon.
Definition: liblwgeom.h:1684
LWGEOM * lwgeom_from_hexwkb(const char *hexwkb, const char check)
Definition: lwin_wkb.c:858
lwvarlena_t * lwgeom_to_svg(const LWGEOM *geom, int precision, int relative)
Takes a GEOMETRY and returns a SVG representation.
Definition: lwout_svg.c:559
#define LW_FAILURE
Definition: liblwgeom.h:96
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1155
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2114
#define MULTILINETYPE
Definition: liblwgeom.h:106
#define LINETYPE
Definition: liblwgeom.h:103
lwvarlena_t * lwgeom_to_geojson(const LWGEOM *geo, const char *srs, int precision, int has_bbox)
Takes a GEOMETRY and returns a GeoJson representation.
void lwgeom_parser_result_init(LWGEOM_PARSER_RESULT *parser_result)
Definition: lwin_wkt.c:880
#define MULTIPOINTTYPE
Definition: liblwgeom.h:105
int lwgeom_parse_wkt(LWGEOM_PARSER_RESULT *parser_result, char *wktstr, int parse_flags)
Parse a WKT geometry string into an LWGEOM structure.
char * lwgeom_to_hexwkb_buffer(const LWGEOM *geom, uint8_t variant)
Definition: lwout_wkb.c:845
lwvarlena_t * lwgeom_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix)
Definition: lwout_gml.c:920
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:102
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
Definition: lwgeom.c:682
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:107
#define SRID_DEFAULT
Definition: liblwgeom.h:225
#define POLYGONTYPE
Definition: liblwgeom.h:104
#define WKB_EXTENDED
Definition: liblwgeom.h:2177
int lwgeom_force_geodetic(LWGEOM *geom)
Force coordinates of LWGEOM into geodetic range (-180, -90, 180, 90)
Definition: lwgeodetic.c:3221
#define LW_GML_IS_DIMS
Macros for specifying GML options.
Definition: liblwgeom.h:1682
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:216
int lwgeom_nudge_geodetic(LWGEOM *geom)
Gently move coordinates of LWGEOM if they are close enough into geodetic range.
Definition: lwgeodetic.c:3403
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:93
LWGEOM * lwgeom_from_wkb(const uint8_t *wkb, const size_t wkb_size, const char check)
WKB inputs must have a declared size, to prevent malformed WKB from reading off the end of the memory...
Definition: lwin_wkb.c:834
lwvarlena_t * lwgeom_to_wkb_varlena(const LWGEOM *geom, uint8_t variant)
Definition: lwout_wkb.c:851
lwvarlena_t * lwgeom_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix, const char *id)
Definition: lwout_gml.c:978
This library is the generic geometry handling section of PostGIS.
#define str(s)
static uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.
Definition: lwinline.h:145
type
Definition: ovdump.py:42
unsigned int int32
Definition: shpopen.c:54
uint8_t type
Definition: liblwgeom.h:462
int32_t srid
Definition: liblwgeom.h:460
Parser result structure: returns the result of attempting to convert (E)WKT/(E)WKB to LWGEOM.
Definition: liblwgeom.h:2122