PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ lwgeom_from_encoded_polyline()

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

Create an LWGEOM object from an Encoded Polyline representation.

Parameters
encodedpolylinethe Encoded Polyline input

Definition at line 34 of file lwin_encoded_polyline.c.

35{
36 LWGEOM *geom = NULL;
37 POINTARRAY *pa = NULL;
38 int length = strlen(encodedpolyline);
39 int idx = 0;
40 double scale = pow(10,precision);
41
42 float latitude = 0.0f;
43 float longitude = 0.0f;
44
46
47 while (idx < length) {
48 POINT4D pt;
49 char byte = 0;
50
51 int res = 0;
52 char shift = 0;
53 do {
54 byte = encodedpolyline[idx++] - 63;
55 res |= (byte & 0x1F) << shift;
56 shift += 5;
57 } while (byte >= 0x20);
58 float deltaLat = ((res & 1) ? ~(res >> 1) : (res >> 1));
59 latitude += deltaLat;
60
61 shift = 0;
62 res = 0;
63 do {
64 byte = encodedpolyline[idx++] - 63;
65 res |= (byte & 0x1F) << shift;
66 shift += 5;
67 } while (byte >= 0x20);
68 float deltaLon = ((res & 1) ? ~(res >> 1) : (res >> 1));
69 longitude += deltaLon;
70
71 pt.x = longitude/scale;
72 pt.y = latitude/scale;
73 pt.m = pt.z = 0.0;
75 }
76
77 geom = (LWGEOM *)lwline_construct(4326, NULL, pa);
78 lwgeom_add_bbox(geom);
79
80 return geom;
81}
static uint8_t precision
Definition cu_in_twkb.c:25
#define LW_FALSE
Definition liblwgeom.h:94
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition ptarray.c:59
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition lwline.c:42
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,...
Definition ptarray.c:147
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition lwgeom.c:723
tuple res
Definition window.py:79
double m
Definition liblwgeom.h:414
double x
Definition liblwgeom.h:414
double z
Definition liblwgeom.h:414
double y
Definition liblwgeom.h:414

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

Referenced by do_encoded_polyline_test(), and line_from_encoded_polyline().

Here is the call graph for this function:
Here is the caller graph for this function: