PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lwgeom_from_encoded_polyline()

LWGEOM* lwgeom_from_encoded_polyline ( const char *  encodedpolyline,
int  precision 
)

Create an LWGEOM object from an Encoded Polyline representation.

Parameters
encodedpolylinethe Encoded Polyline input

Definition at line 32 of file lwin_encoded_polyline.c.

References LW_FALSE, lwgeom_add_bbox(), lwline_construct(), POINT4D::m, ptarray_append_point(), ptarray_construct_empty(), window::res, POINT4D::x, POINT4D::y, and POINT4D::z.

Referenced by do_encoded_polyline_test(), and line_from_encoded_polyline().

33 {
34  LWGEOM *geom = NULL;
35  POINTARRAY *pa = NULL;
36  int length = strlen(encodedpolyline);
37  int idx = 0;
38  double scale = pow(10,precision);
39 
40  float latitude = 0.0f;
41  float longitude = 0.0f;
42 
44 
45  while (idx < length) {
46  POINT4D pt;
47  char byte = 0;
48 
49  int res = 0;
50  char shift = 0;
51  do {
52  byte = encodedpolyline[idx++] - 63;
53  res |= (byte & 0x1F) << shift;
54  shift += 5;
55  } while (byte >= 0x20);
56  float deltaLat = ((res & 1) ? ~(res >> 1) : (res >> 1));
57  latitude += deltaLat;
58 
59  shift = 0;
60  res = 0;
61  do {
62  byte = encodedpolyline[idx++] - 63;
63  res |= (byte & 0x1F) << shift;
64  shift += 5;
65  } while (byte >= 0x20);
66  float deltaLon = ((res & 1) ? ~(res >> 1) : (res >> 1));
67  longitude += deltaLon;
68 
69  pt.x = longitude/scale;
70  pt.y = latitude/scale;
71  pt.m = pt.z = 0.0;
73  }
74 
75  geom = (LWGEOM *)lwline_construct(4326, NULL, pa);
76  lwgeom_add_bbox(geom);
77 
78  return geom;
79 }
double x
Definition: liblwgeom.h:352
tuple res
Definition: window.py:78
double m
Definition: liblwgeom.h:352
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:70
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_FALSE, then a duplicate point will not be added.
Definition: ptarray.c:156
#define LW_FALSE
Definition: liblwgeom.h:77
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
uint8_t precision
Definition: cu_in_twkb.c:25
double z
Definition: liblwgeom.h:352
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:648
double y
Definition: liblwgeom.h:352
Here is the call graph for this function:
Here is the caller graph for this function: