PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches
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 pg_atoi */
38#include "lib/stringinfo.h" /* For binary input */
39#include "catalog/pg_type.h" /* for CSTRINGOID */
40
41#include "liblwgeom.h" /* For standard geometry types. */
42#include "lwgeom_pg.h" /* For debugging macros. */
43#include "geography.h" /* For utility functions. */
44#include "lwgeom_export.h" /* For export functions. */
45#include "lwgeom_transform.h"
46
47Datum geography_in(PG_FUNCTION_ARGS);
48Datum geography_out(PG_FUNCTION_ARGS);
49
50Datum geography_as_text(PG_FUNCTION_ARGS);
51Datum geography_from_text(PG_FUNCTION_ARGS);
52Datum geography_as_geojson(PG_FUNCTION_ARGS);
53Datum geography_as_gml(PG_FUNCTION_ARGS);
54Datum geography_as_kml(PG_FUNCTION_ARGS);
55Datum geography_as_svg(PG_FUNCTION_ARGS);
56Datum geography_from_binary(PG_FUNCTION_ARGS);
57Datum geography_from_geometry(PG_FUNCTION_ARGS);
58Datum geometry_from_geography(PG_FUNCTION_ARGS);
59Datum geography_send(PG_FUNCTION_ARGS);
60Datum geography_recv(PG_FUNCTION_ARGS);
61
63
69void geography_valid_type(uint8_t type)
70{
71 if ( ! (
72 type == POINTTYPE ||
73 type == LINETYPE ||
74 type == POLYGONTYPE ||
75 type == MULTIPOINTTYPE ||
76 type == MULTILINETYPE ||
77 type == MULTIPOLYGONTYPE ||
78 type == COLLECTIONTYPE
79 ) )
80 {
81 ereport(ERROR, (
82 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
83 errmsg("Geography type does not support %s", lwtype_name(type) )));
84
85 }
86}
87
89{
90 GSERIALIZED *g_ser = NULL;
91
92 /* Set geodetic flag */
93 lwgeom_set_geodetic(lwgeom, true);
94
95 /* Check that this is a type we can handle */
97
98 /* Force the geometry to have valid geodetic coordinate range. */
100 if ( lwgeom_force_geodetic(lwgeom) == LW_TRUE )
101 {
102 ereport(NOTICE, (
103 errmsg_internal("Coordinate values were coerced into range [-180 -90, 180 90] for GEOGRAPHY" ))
104 );
105 }
106
107 /* Force default SRID to the default */
108 if ( (int)lwgeom->srid <= 0 )
109 lwgeom->srid = SRID_DEFAULT;
110
111 /*
112 ** Serialize our lwgeom and set the geodetic flag so subsequent
113 ** functions do the right thing.
114 */
115 g_ser = geography_serialize(lwgeom);
116
117 /* Check for typmod agreement */
118 if ( geog_typmod >= 0 )
119 {
120 g_ser = postgis_valid_typmod(g_ser, geog_typmod);
121 POSTGIS_DEBUG(3, "typmod and geometry were consistent");
122 }
123 else
124 {
125 POSTGIS_DEBUG(3, "typmod was -1");
126 }
127
128 return g_ser;
129}
130
131
132/*
133** geography_in(cstring) returns *GSERIALIZED
134*/
136Datum geography_in(PG_FUNCTION_ARGS)
137{
138 char *str = PG_GETARG_CSTRING(0);
139 /* Datum geog_oid = PG_GETARG_OID(1); Not needed. */
140 int32 geog_typmod = -1;
141 LWGEOM_PARSER_RESULT lwg_parser_result;
142 LWGEOM *lwgeom = NULL;
143 GSERIALIZED *g_ser = NULL;
144
145 if ( (PG_NARGS()>2) && (!PG_ARGISNULL(2)) ) {
146 geog_typmod = PG_GETARG_INT32(2);
147 }
148
149 lwgeom_parser_result_init(&lwg_parser_result);
150
151 /* Empty string. */
152 if ( str[0] == '\0' )
153 ereport(ERROR,(errmsg("parse error - invalid geometry")));
154
155 /* WKB? Let's find out. */
156 if ( str[0] == '0' )
157 {
158 /* TODO: 20101206: No parser checks! This is inline with current 1.5 behavior, but needs discussion */
160 /* Error out if something went sideways */
161 if ( ! lwgeom )
162 ereport(ERROR,(errmsg("parse error - invalid geometry")));
163 }
164 /* WKT then. */
165 else
166 {
167 if ( lwgeom_parse_wkt(&lwg_parser_result, str, LW_PARSER_CHECK_ALL) == LW_FAILURE )
168 PG_PARSER_ERROR(lwg_parser_result);
169
170 lwgeom = lwg_parser_result.geom;
171 }
172
173 /* Error on any SRID != default */
174 srid_check_latlong(fcinfo, lwgeom->srid);
175
176 /* Convert to gserialized */
177 g_ser = gserialized_geography_from_lwgeom(lwgeom, geog_typmod);
178
179 /* Clean up temporary object */
180 lwgeom_free(lwgeom);
181
182
183 PG_RETURN_POINTER(g_ser);
184}
185
186/*
187** geography_out(*GSERIALIZED) returns cstring
188*/
190Datum geography_out(PG_FUNCTION_ARGS)
191{
192 LWGEOM *lwgeom = NULL;
193 GSERIALIZED *g = NULL;
194 char *hexwkb;
195
196 g = PG_GETARG_GSERIALIZED_P(0);
197 lwgeom = lwgeom_from_gserialized(g);
198 hexwkb = lwgeom_to_hexwkb(lwgeom, WKB_EXTENDED, 0);
199 lwgeom_free(lwgeom);
200
201 PG_RETURN_CSTRING(hexwkb);
202}
203
204
205/*
206** geography_as_gml(*GSERIALIZED) returns text
207*/
209Datum geography_as_gml(PG_FUNCTION_ARGS)
210{
211 LWGEOM *lwgeom = NULL;
212 GSERIALIZED *g = NULL;
213 char *gml;
214 text *result;
215 int version;
216 char *srs;
217 int32_t srid = SRID_DEFAULT;
218 int precision = DBL_DIG;
219 int option = 0;
220 int lwopts = LW_GML_IS_DIMS;
221 static const char *default_prefix = "gml:";
222 const char *prefix = default_prefix;
223 char *prefix_buf = "";
224 text *prefix_text, *id_text = NULL;
225 const char *id = NULL;
226 char *id_buf;
227
228 /*
229 * Two potential callers, one starts with GML version,
230 * one starts with geography, and we check for initial
231 * argument type and then dynamically change what args
232 * we read based on presence/absence
233 */
234 Oid first_type = get_fn_expr_argtype(fcinfo->flinfo, 0);
235 int argnum = 0;
236 int argeom = 0;
237 if (first_type != INT4OID)
238 {
239 version = 2;
240 }
241 else
242 {
243 /* Get the version */
244 version = PG_GETARG_INT32(argnum++);
245 argeom = 1;
246 if (version != 2 && version != 3)
247 {
248 elog(ERROR, "Only GML 2 and GML 3 are supported");
249 PG_RETURN_NULL();
250 }
251 }
252
253 /* Get the parameters, both callers have same order */
254 g = PG_GETARG_GSERIALIZED_P(argnum++);
255 precision = PG_GETARG_INT32(argnum++);
256 option = PG_GETARG_INT32(argnum++);
257 prefix_text = PG_GETARG_TEXT_P(argnum++);
258 id_text = PG_GETARG_TEXT_P(argnum++);
259
260 /* Convert to lwgeom so we can run the old functions */
261 lwgeom = lwgeom_from_gserialized(g);
262
263 /* Condition the precision argument */
264 if (precision > DBL_DIG)
265 precision = DBL_DIG;
266 if (precision < 0)
267 precision = 0;
268
269 /* Condition the prefix argument */
270 if (VARSIZE_ANY_EXHDR(prefix_text) > 0)
271 {
272 /* +2 is one for the ':' and one for term null */
273 prefix_buf = palloc(VARSIZE_ANY_EXHDR(prefix_text)+2);
274 memcpy(prefix_buf, VARDATA_ANY(prefix_text),
275 VARSIZE_ANY_EXHDR(prefix_text));
276 /* add colon and null terminate */
277 prefix_buf[VARSIZE_ANY_EXHDR(prefix_text)] = ':';
278 prefix_buf[VARSIZE_ANY_EXHDR(prefix_text)+1] = '\0';
279 prefix = prefix_buf;
280 }
281 else
282 {
283 prefix = "";
284 }
285
286 if (VARSIZE_ANY_EXHDR(id_text) > 0)
287 {
288 id_buf = palloc(VARSIZE_ANY_EXHDR(id_text)+2);
289 memcpy(id_buf, VARDATA(id_text), VARSIZE_ANY_EXHDR(id_text));
290 id_buf[VARSIZE_ANY_EXHDR(id_text)+1] = '\0';
291 id = id_buf;
292 }
293
294 if (option & 1)
295 srs = getSRSbySRID(fcinfo, srid, false);
296 else
297 srs = getSRSbySRID(fcinfo, srid, true);
298 if (!srs)
299 {
300 elog(ERROR, "SRID %d unknown in spatial_ref_sys table", SRID_DEFAULT);
301 PG_RETURN_NULL();
302 }
303
304 /* Revert lat/lon only with long SRS */
305 if (option & 1) lwopts |= LW_GML_IS_DEGREE;
306 if (option & 2) lwopts &= ~LW_GML_IS_DIMS;
307 if (option & 8)
308 {
309 elog(ERROR,
310 "Options %d passed to ST_AsGML(geography) sets "
311 "unsupported value 8",
312 option);
313 PG_RETURN_NULL();
314 }
315 if ((option & 4) || (option & 16) || (option & 32))
316 {
317 elog(ERROR,
318 "Options %d passed to ST_AsGML(geography) but are only "
319 "applicable to ST_AsGML(geometry)",
320 option);
321 PG_RETURN_NULL();
322 }
323
324 if (version == 2)
325 gml = lwgeom_to_gml2(lwgeom, srs, precision, prefix);
326 else
327 gml = lwgeom_to_gml3(lwgeom, srs, precision, lwopts, prefix, id);
328
329 lwgeom_free(lwgeom);
330 PG_FREE_IF_COPY(g, argeom);
331
332 /* Return null on null */
333 if (!gml)
334 PG_RETURN_NULL();
335
336 /* Turn string result into text for return */
337 result = cstring_to_text(gml);
338 lwfree(gml);
339
340 PG_RETURN_TEXT_P(result);
341}
342
343
344/*
345** geography_as_kml(*GSERIALIZED) returns text
346*/
348Datum geography_as_kml(PG_FUNCTION_ARGS)
349{
350
351 char *kml;
352 text *result;
353 static const char *default_prefix = "";
354 char *prefixbuf;
355 const char *prefix = default_prefix;
356 GSERIALIZED *g = PG_GETARG_GSERIALIZED_P(0);
357 int precision = PG_GETARG_INT32(1);
358 text *prefix_text = PG_GETARG_TEXT_P(2);
359 LWGEOM *lwgeom = lwgeom_from_gserialized(g);
360
361 /* Condition the precision */
362 if (precision > DBL_DIG)
363 precision = DBL_DIG;
364 if (precision < 0)
365 precision = 0;
366
367 if (VARSIZE_ANY_EXHDR(prefix_text) > 0)
368 {
369 /* +2 is one for the ':' and one for term null */
370 prefixbuf = palloc(VARSIZE_ANY_EXHDR(prefix_text)+2);
371 memcpy(prefixbuf, VARDATA(prefix_text),
372 VARSIZE_ANY_EXHDR(prefix_text));
373 /* add colon and null terminate */
374 prefixbuf[VARSIZE_ANY_EXHDR(prefix_text)] = ':';
375 prefixbuf[VARSIZE_ANY_EXHDR(prefix_text)+1] = '\0';
376 prefix = prefixbuf;
377 }
378 else
379 {
380 prefix = "";
381 }
382
383 kml = lwgeom_to_kml2(lwgeom, precision, prefix);
384
385 lwgeom_free(lwgeom);
386 PG_FREE_IF_COPY(g, 0);
387
388 if (!kml)
389 PG_RETURN_NULL();
390
391 result = cstring_to_text(kml);
392 lwfree(kml);
393
394 PG_RETURN_TEXT_P(result);
395}
396
397
398/*
399** geography_as_svg(*GSERIALIZED) returns text
400*/
402Datum geography_as_svg(PG_FUNCTION_ARGS)
403{
404 char *svg;
405 text *result;
406 GSERIALIZED *g = PG_GETARG_GSERIALIZED_P(0);
407 int relative = PG_GETARG_INT32(1) ? 1 : 0;
408 int precision = PG_GETARG_INT32(2);
409 LWGEOM *lwgeom = lwgeom_from_gserialized(g);
410
411 if (precision > DBL_DIG)
412 precision = DBL_DIG;
413 else if (precision < 0)
414 precision = 0;
415
416 svg = lwgeom_to_svg(lwgeom, precision, relative);
417
418 lwgeom_free(lwgeom);
419 PG_FREE_IF_COPY(g, 0);
420
421 result = cstring_to_text(svg);
422 lwfree(svg);
423
424 PG_RETURN_TEXT_P(result);
425}
426
427
428/*
429** geography_as_geojson(*GSERIALIZED) returns text
430*/
432Datum geography_as_geojson(PG_FUNCTION_ARGS)
433{
434 char *geojson;
435 text *result;
436 int has_bbox = 0;
437 char * srs = NULL;
438 GSERIALIZED *g = PG_GETARG_GSERIALIZED_P(0);
439 int precision = PG_GETARG_INT32(1);
440 int option = PG_GETARG_INT32(2);
441 LWGEOM *lwgeom = lwgeom_from_gserialized(g);
442
443 if (precision > DBL_DIG)
444 precision = DBL_DIG;
445 if (precision < 0)
446 precision = 0;
447
448 /* Retrieve output option
449 * 0 = without option (default)
450 * 1 = bbox
451 * 2 = short crs
452 * 4 = long crs
453 */
454
455 if (option & 2 || option & 4)
456 {
457 /* Geography only handle srid SRID_DEFAULT */
458 if (option & 2)
459 srs = getSRSbySRID(fcinfo, SRID_DEFAULT, true);
460 if (option & 4)
461 srs = getSRSbySRID(fcinfo, SRID_DEFAULT, false);
462
463 if (!srs)
464 {
465 elog(ERROR, "SRID SRID_DEFAULT unknown in spatial_ref_sys table");
466 PG_RETURN_NULL();
467 }
468 }
469
470 if (option & 1) has_bbox = 1;
471
472 geojson = lwgeom_to_geojson(lwgeom, srs, precision, has_bbox);
473 lwgeom_free(lwgeom);
474 PG_FREE_IF_COPY(g, 0);
475 if (srs) pfree(srs);
476
477 result = cstring_to_text(geojson);
478 lwfree(geojson);
479
480 PG_RETURN_TEXT_P(result);
481}
482
483
484/*
485** geography_from_text(*char) returns *GSERIALIZED
486**
487** Convert text (varlena) to cstring and then call geography_in().
488*/
490Datum geography_from_text(PG_FUNCTION_ARGS)
491{
492 LWGEOM_PARSER_RESULT lwg_parser_result;
493 GSERIALIZED *g_ser = NULL;
494 text *wkt_text = PG_GETARG_TEXT_P(0);
495
496 /* Extract the cstring from the varlena */
497 char *wkt = text_to_cstring(wkt_text);
498
499 /* Pass the cstring to the input parser, and magic occurs! */
500 if ( lwgeom_parse_wkt(&lwg_parser_result, wkt, LW_PARSER_CHECK_ALL) == LW_FAILURE )
501 PG_PARSER_ERROR(lwg_parser_result);
502
503 /* Error on any SRID != default */
504 srid_check_latlong(fcinfo, lwg_parser_result.geom->srid);
505
506 /* Clean up string */
507 pfree(wkt);
508 g_ser = gserialized_geography_from_lwgeom(lwg_parser_result.geom, -1);
509
510 /* Clean up temporary object */
511 lwgeom_free(lwg_parser_result.geom);
512
513 PG_RETURN_POINTER(g_ser);
514}
515
516/*
517** geography_from_binary(*char) returns *GSERIALIZED
518*/
520Datum geography_from_binary(PG_FUNCTION_ARGS)
521{
522 char *wkb_bytea = (char*)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
523 GSERIALIZED *gser = NULL;
524 size_t wkb_size = VARSIZE(wkb_bytea);
525 uint8_t *wkb = (uint8_t*)VARDATA(wkb_bytea);
526 LWGEOM *lwgeom = lwgeom_from_wkb(wkb, wkb_size, LW_PARSER_CHECK_NONE);
527
528 if ( ! lwgeom )
529 lwpgerror("Unable to parse WKB");
530
531 /* Error on any SRID != default */
532 srid_check_latlong(fcinfo, lwgeom->srid);
533
534 gser = gserialized_geography_from_lwgeom(lwgeom, -1);
535 lwgeom_free(lwgeom);
536 PG_RETURN_POINTER(gser);
537}
538
539
541Datum geography_from_geometry(PG_FUNCTION_ARGS)
542{
543 GSERIALIZED *g_ser = NULL;
544 GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P_COPY(0);
545 LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
546
548
549 /* Force default SRID */
550 if ( (int)lwgeom->srid <= 0 )
551 {
552 lwgeom->srid = SRID_DEFAULT;
553 }
554
555 /* Error on any SRID != default */
556 srid_check_latlong(fcinfo, lwgeom->srid);
557
558 /* Force the geometry to have valid geodetic coordinate range. */
559 lwgeom_nudge_geodetic(lwgeom);
560 if ( lwgeom_force_geodetic(lwgeom) == LW_TRUE )
561 {
562 ereport(NOTICE, (
563 errmsg_internal("Coordinate values were coerced into range [-180 -90, 180 90] for GEOGRAPHY" ))
564 );
565 }
566
567 /* force recalculate of box by dropping */
568 lwgeom_drop_bbox(lwgeom);
569
570 lwgeom_set_geodetic(lwgeom, true);
571 /* We are trusting geography_serialize will add a box if needed */
572 g_ser = geography_serialize(lwgeom);
573
574
575 lwgeom_free(lwgeom);
576
577 PG_FREE_IF_COPY(geom, 0);
578 PG_RETURN_POINTER(g_ser);
579}
580
582Datum geometry_from_geography(PG_FUNCTION_ARGS)
583{
584 LWGEOM *lwgeom = NULL;
585 GSERIALIZED *ret = NULL;
586 GSERIALIZED *g_ser = PG_GETARG_GSERIALIZED_P(0);
587
588 lwgeom = lwgeom_from_gserialized(g_ser);
589
590 /* Recalculate the boxes after re-setting the geodetic bit */
591 lwgeom_set_geodetic(lwgeom, false);
592 lwgeom_refresh_bbox(lwgeom);
593
594 /* We want "geometry" to think all our "geography" has an SRID, and the
595 implied SRID is the default, so we fill that in if our SRID is actually unknown. */
596 if ( (int)lwgeom->srid <= 0 )
597 lwgeom->srid = SRID_DEFAULT;
598
599 ret = geometry_serialize(lwgeom);
600 lwgeom_free(lwgeom);
601
602 PG_RETURN_POINTER(ret);
603}
604
606Datum geography_recv(PG_FUNCTION_ARGS)
607{
608 StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
609 int32 geog_typmod = -1;
610 LWGEOM *lwgeom = NULL;
611 GSERIALIZED *g_ser = NULL;
612
613 if ( (PG_NARGS()>2) && (!PG_ARGISNULL(2)) ) {
614 geog_typmod = PG_GETARG_INT32(2);
615 }
616
617 lwgeom = lwgeom_from_wkb((uint8_t*)buf->data, buf->len, LW_PARSER_CHECK_ALL);
618 if ( !lwgeom )
619 {
620 ereport(ERROR,(errmsg("recv error - invalid geometry")));
621 PG_RETURN_NULL();
622 }
623
624 /* Error on any SRID != default */
625 srid_check_latlong(fcinfo, lwgeom->srid);
626
627 g_ser = gserialized_geography_from_lwgeom(lwgeom, geog_typmod);
628
629 /* Clean up temporary object */
630 lwgeom_free(lwgeom);
631
632 /* Set cursor to the end of buffer (so the backend is happy) */
633 buf->cursor = buf->len;
634
635 PG_RETURN_POINTER(g_ser);
636}
637
638
640Datum geography_send(PG_FUNCTION_ARGS)
641{
642 LWGEOM *lwgeom = NULL;
643 GSERIALIZED *g = NULL;
644 size_t size_result;
645 uint8_t *wkb;
646 bytea *result;
647
648 g = PG_GETARG_GSERIALIZED_P(0);
649 lwgeom = lwgeom_from_gserialized(g);
650 wkb = lwgeom_to_wkb(lwgeom, WKB_EXTENDED, &size_result);
651 lwgeom_free(lwgeom);
652
653 result = palloc(size_result + VARHDRSZ);
654 SET_VARSIZE(result, size_result + VARHDRSZ);
655 memcpy(VARDATA(result), wkb, size_result);
656 lwfree(wkb);
657
658 PG_RETURN_POINTER(result);
659}
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.
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition lwutil.c:216
void lwgeom_refresh_bbox(LWGEOM *lwgeom)
Drop current bbox and calculate a fresh one.
Definition lwgeom.c:689
#define LW_PARSER_CHECK_ALL
Definition liblwgeom.h:2061
void lwgeom_set_geodetic(LWGEOM *geom, int value)
Set the FLAGS geodetic bit on geometry an all sub-geometries and pointlists.
Definition lwgeom.c:946
#define COLLECTIONTYPE
Definition liblwgeom.h:122
char * lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
Definition lwout_wkb.c:874
#define LW_GML_IS_DEGREE
For GML3 only, declare that datas are lat/lon.
Definition liblwgeom.h:1650
#define LW_FAILURE
Definition liblwgeom.h:110
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1138
#define LW_PARSER_CHECK_NONE
Definition liblwgeom.h:2060
char * lwgeom_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix)
VERSION GML 2 takes a GEOMETRY and returns a GML2 representation.
Definition lwout_gml.c:231
#define MULTILINETYPE
Definition liblwgeom.h:120
char * lwgeom_to_svg(const LWGEOM *geom, int precision, int relative)
Takes a GEOMETRY and returns a SVG representation.
Definition lwout_svg.c:56
#define LINETYPE
Definition liblwgeom.h:117
void lwgeom_parser_result_init(LWGEOM_PARSER_RESULT *parser_result)
Definition lwin_wkt.c:880
#define MULTIPOINTTYPE
Definition liblwgeom.h:119
int lwgeom_parse_wkt(LWGEOM_PARSER_RESULT *parser_result, char *wktstr, int parse_flags)
Parse a WKT geometry string into an LWGEOM structure.
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition liblwgeom.h:116
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
Definition lwgeom.c:664
#define MULTIPOLYGONTYPE
Definition liblwgeom.h:121
char * lwgeom_to_kml2(const LWGEOM *geom, int precision, const char *prefix)
Definition lwout_kml.c:44
void lwfree(void *mem)
Definition lwutil.c:242
#define SRID_DEFAULT
Definition liblwgeom.h:239
#define POLYGONTYPE
Definition liblwgeom.h:118
LWGEOM * lwgeom_from_hexwkb(const char *hexwkb, const char check)
Definition lwin_wkb.c:857
#define WKB_EXTENDED
Definition liblwgeom.h:2123
int lwgeom_force_geodetic(LWGEOM *geom)
Force coordinates of LWGEOM into geodetic range (-180, -90, 180, 90)
#define LW_GML_IS_DIMS
Macros for specifying GML options.
Definition liblwgeom.h:1648
uint8_t * lwgeom_to_wkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
Convert LWGEOM to a char* in WKB format.
Definition lwout_wkb.c:790
int lwgeom_nudge_geodetic(LWGEOM *geom)
Gently move coordinates of LWGEOM if they are close enough into geodetic range.
#define LW_TRUE
Return types for functions with status returns.
Definition liblwgeom.h:107
char * lwgeom_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix, const char *id)
Definition lwout_gml.c:716
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:833
char * lwgeom_to_geojson(const LWGEOM *geo, char *srs, int precision, int has_bbox)
Takes a GEOMETRY and returns a GeoJson representation.
This library is the generic geometry handling section of PostGIS.
char * getSRSbySRID(FunctionCallInfo fcinfo, int32_t srid, bool short_crs)
#define str(s)
static uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.
Definition lwinline.h:135
char * text_to_cstring(const text *textptr)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
unsigned int int32
Definition shpopen.c:273
uint8_t type
Definition liblwgeom.h:448
int32_t srid
Definition liblwgeom.h:446
Parser result structure: returns the result of attempting to convert (E)WKT/(E)WKB to LWGEOM.
Definition liblwgeom.h:2068