PostGIS  2.4.9dev-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  * 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 2014 Kashif Rasul <kashif.rasul@gmail.com> and
22  *
23  **********************************************************************/
24 
25 
26 #include <assert.h>
27 
28 #include "postgres.h"
29 
30 #include "../postgis_config.h"
31 #include "lwgeom_pg.h"
32 #include "liblwgeom.h"
33 
34 Datum line_from_encoded_polyline(PG_FUNCTION_ARGS);
35 
37 Datum line_from_encoded_polyline(PG_FUNCTION_ARGS)
38 {
39  GSERIALIZED *geom;
40  LWGEOM *lwgeom;
41  text *encodedpolyline_input;
42  char *encodedpolyline;
43  int precision = 5;
44 
45  if (PG_ARGISNULL(0)) PG_RETURN_NULL();
46 
47  encodedpolyline_input = PG_GETARG_TEXT_P(0);
48  encodedpolyline = text2cstring(encodedpolyline_input);
49 
50  if (PG_NARGS() > 1 && !PG_ARGISNULL(1))
51  {
52  precision = PG_GETARG_INT32(1);
53  if ( precision < 0 ) precision = 5;
54  }
55 
56  lwgeom = lwgeom_from_encoded_polyline(encodedpolyline, precision);
57  if ( ! lwgeom ) {
58  /* Shouldn't get here */
59  elog(ERROR, "lwgeom_from_encoded_polyline returned NULL");
60  PG_RETURN_NULL();
61  }
62  lwgeom_set_srid(lwgeom, 4326);
63 
64  geom = geometry_serialize(lwgeom);
65  lwgeom_free(lwgeom);
66  PG_RETURN_POINTER(geom);
67 }
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
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.