PostGIS  2.5.1dev-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 #include "utils/builtins.h"
30 
31 #include "../postgis_config.h"
32 #include "lwgeom_pg.h"
33 #include "liblwgeom.h"
34 
35 Datum line_from_encoded_polyline(PG_FUNCTION_ARGS);
36 
38 Datum line_from_encoded_polyline(PG_FUNCTION_ARGS)
39 {
40  GSERIALIZED *geom;
41  LWGEOM *lwgeom;
42  text *encodedpolyline_input;
43  char *encodedpolyline;
44  int precision = 5;
45 
46  if (PG_ARGISNULL(0)) PG_RETURN_NULL();
47 
48  encodedpolyline_input = PG_GETARG_TEXT_P(0);
49  encodedpolyline = text_to_cstring(encodedpolyline_input);
50 
51  if (PG_NARGS() > 1 && !PG_ARGISNULL(1))
52  {
53  precision = PG_GETARG_INT32(1);
54  if ( precision < 0 ) precision = 5;
55  }
56 
57  lwgeom = lwgeom_from_encoded_polyline(encodedpolyline, precision);
58  if ( ! lwgeom ) {
59  /* Shouldn't get here */
60  elog(ERROR, "lwgeom_from_encoded_polyline returned NULL");
61  PG_RETURN_NULL();
62  }
63  lwgeom_set_srid(lwgeom, 4326);
64 
65  geom = geometry_serialize(lwgeom);
66  lwgeom_free(lwgeom);
67  PG_RETURN_POINTER(geom);
68 }
char * text_to_cstring(const text *textptr)
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
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)
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.