Decode MultiLineStrings

This commit is contained in:
Eric Fischer 2017-09-20 17:30:50 -07:00
parent d9fa0a30a8
commit 57e7ef2ed4

View File

@ -48,7 +48,7 @@ drawvec decode_geometry(unsigned char *data, size_t len, int *type) {
}
unsigned t = read32le(data);
if (t == 1) { // point
if (t == 1) { // Point
if (len < 20) {
fprintf(stderr, "Unexpectedly short point geometry\n");
exit(EXIT_FAILURE);
@ -56,10 +56,42 @@ drawvec decode_geometry(unsigned char *data, size_t len, int *type) {
double lon = toDouble(data + 4);
double lat = toDouble(data + 12);
long long x, y;
projection->project(lon, lat, 32, &x, &y);
dv.push_back(draw(VT_MOVETO, x, y));
*type = VT_POINT;
} else if (t == 3) { // MultiLineString
unsigned parts = read32le(data + 36);
unsigned points = read32le(data + 40);
for (size_t i = 0; i < parts; i++) {
unsigned start = read32le(data + 44 * 4 * i);
unsigned end;
if (i + 1 < parts) {
end = read32le(data + 44 * 4 * (i + 1));
} else {
end = points;
}
for (size_t j = start; j < end; j++) {
double lon = toDouble(data + 44 + 4 * parts + 16 * j);
double lat = toDouble(data + 44 + 4 * parts + 16 * j + 8);
long long x, y;
projection->project(lon, lat, 32, &x, &y);
if (j == start) {
dv.push_back(draw(VT_MOVETO, x, y));
} else {
dv.push_back(draw(VT_LINETO, x, y));
}
}
}
*type = VT_LINE;
} else {
static bool warned = false;
if (!warned) {