PostGIS  2.2.8dev-r@@SVN_REVISION@@
lwgeom_in_encoded_polyline.c
Go to the documentation of this file.
1 /**********************************************************************
2 *
3 * PostGIS - Spatial Types for PostgreSQL
4 * http://postgis.net
5 *
6 * Copyright 2014 Kashif Rasul <kashif.rasul@gmail.com> and
7 * Shoaib Burq <saburq@gmail.com>
8 *
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU General Public Licence. See the COPYING file.
11 *
12 **********************************************************************/
13 
14 #include <assert.h>
15 
16 #include "postgres.h"
17 
18 #include "../postgis_config.h"
19 #include "lwgeom_pg.h"
20 #include "liblwgeom.h"
21 
22 Datum line_from_encoded_polyline(PG_FUNCTION_ARGS);
23 
25 Datum line_from_encoded_polyline(PG_FUNCTION_ARGS)
26 {
27  GSERIALIZED *geom;
28  LWGEOM *lwgeom;
29  text *encodedpolyline_input;
30  char *encodedpolyline;
31  int precision = 5;
32 
33  if (PG_ARGISNULL(0)) PG_RETURN_NULL();
34 
35  encodedpolyline_input = PG_GETARG_TEXT_P(0);
36  encodedpolyline = text2cstring(encodedpolyline_input);
37 
38  if (PG_NARGS() > 1 && !PG_ARGISNULL(1))
39  {
40  precision = PG_GETARG_INT32(1);
41  if ( precision < 0 ) precision = 5;
42  }
43 
44  lwgeom = lwgeom_from_encoded_polyline(encodedpolyline, precision);
45  if ( ! lwgeom ) {
46  /* Shouldn't get here */
47  elog(ERROR, "lwgeom_from_encoded_polyline returned NULL");
48  PG_RETURN_NULL();
49  }
50  lwgeom_set_srid(lwgeom, 4326);
51 
52  geom = geometry_serialize(lwgeom);
53  lwgeom_free(lwgeom);
54  PG_RETURN_POINTER(geom);
55 }
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
LWGEOM * lwgeom_from_encoded_polyline(const char *encodedpolyline, int precision)
Create an LWGEOM object from an Encoded Polyline representation.
Datum line_from_encoded_polyline(PG_FUNCTION_ARGS)
char * text2cstring(const text *textptr)
uint8_t precision
Definition: cu_in_twkb.c:25
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
void lwgeom_set_srid(LWGEOM *geom, int srid)
Set the SRID on an LWGEOM For collections, only the parent gets an SRID, all the children get SRID_UN...
PG_FUNCTION_INFO_V1(line_from_encoded_polyline)
This library is the generic geometry handling section of PostGIS.