PostGIS  2.2.8dev-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 20 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().

21 {
22  LWGEOM *geom = NULL;
23  POINTARRAY *pa = NULL;
24  int length = strlen(encodedpolyline);
25  int idx = 0;
26  double scale = pow(10,precision);
27 
28  float latitude = 0.0f;
29  float longitude = 0.0f;
30 
32 
33  while (idx < length) {
34  POINT4D pt;
35  char byte = 0;
36 
37  int res = 0;
38  char shift = 0;
39  do {
40  byte = encodedpolyline[idx++] - 63;
41  res |= (byte & 0x1F) << shift;
42  shift += 5;
43  } while (byte >= 0x20);
44  float deltaLat = ((res & 1) ? ~(res >> 1) : (res >> 1));
45  latitude += deltaLat;
46 
47  shift = 0;
48  res = 0;
49  do {
50  byte = encodedpolyline[idx++] - 63;
51  res |= (byte & 0x1F) << shift;
52  shift += 5;
53  } while (byte >= 0x20);
54  float deltaLon = ((res & 1) ? ~(res >> 1) : (res >> 1));
55  longitude += deltaLon;
56 
57  pt.x = longitude/scale;
58  pt.y = latitude/scale;
59  pt.m = pt.z = 0.0;
61  }
62 
63  geom = (LWGEOM *)lwline_construct(4326, NULL, pa);
64  lwgeom_add_bbox(geom);
65 
66  return geom;
67 }
double x
Definition: liblwgeom.h:336
tuple res
Definition: window.py:78
double m
Definition: liblwgeom.h:336
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_TRUE, then a duplicate point will not be added.
Definition: ptarray.c:156
#define LW_FALSE
Definition: liblwgeom.h:62
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:29
uint8_t precision
Definition: cu_in_twkb.c:25
double z
Definition: liblwgeom.h:336
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:599
double y
Definition: liblwgeom.h:336
Here is the call graph for this function:
Here is the caller graph for this function: