mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-02 08:25:40 +02:00
FlatGeobuf MultiPolygon parsing [#2]
This commit is contained in:
+34
-9
@@ -36,13 +36,12 @@ uint64_t PackedRTreeSize(const uint64_t numItems, const uint16_t nodeSize)
|
|||||||
return numNodes * sizeof(NodeItem);
|
return numNodes * sizeof(NodeItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
drawvec readGeometry(const FlatGeobuf::Geometry *geometry, FlatGeobuf::GeometryType geometry_type) {
|
drawvec readPolygon(const FlatGeobuf::Geometry *geometry) {
|
||||||
// if it is a GeometryCollection, parse Parts, ignore XY
|
|
||||||
auto xy = geometry->xy();
|
auto xy = geometry->xy();
|
||||||
auto ends = geometry->ends();
|
auto ends = geometry->ends();
|
||||||
size_t current_end = 0;
|
size_t current_end = 0;
|
||||||
|
|
||||||
drawvec dv;
|
drawvec dv;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < xy->size(); i+=2) {
|
for (unsigned int i = 0; i < xy->size(); i+=2) {
|
||||||
long long x, y;
|
long long x, y;
|
||||||
projection->project(xy->Get(i), xy->Get(i+1), 32, &x, &y);
|
projection->project(xy->Get(i), xy->Get(i+1), 32, &x, &y);
|
||||||
@@ -53,10 +52,30 @@ drawvec readGeometry(const FlatGeobuf::Geometry *geometry, FlatGeobuf::GeometryT
|
|||||||
dv.push_back(draw(VT_LINETO, x, y));
|
dv.push_back(draw(VT_LINETO, x, y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return dv;
|
return dv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
drawvec readGeometry(const FlatGeobuf::Geometry *geometry, FlatGeobuf::GeometryType h_geometry_type) {
|
||||||
|
|
||||||
|
if (h_geometry_type == FlatGeobuf::GeometryType::Polygon) {
|
||||||
|
return readPolygon(geometry);
|
||||||
|
} else if (h_geometry_type == FlatGeobuf::GeometryType::MultiPolygon) {
|
||||||
|
// if it is a GeometryCollection, parse Parts, ignore XY
|
||||||
|
drawvec dv;
|
||||||
|
for (size_t part = 0; part < geometry->parts()->size(); part++) {
|
||||||
|
drawvec dv2 = readPolygon(geometry->parts()->Get(part));
|
||||||
|
for (size_t k = 0; k < dv2.size(); k++) {
|
||||||
|
dv.push_back(dv2[k]);
|
||||||
|
}
|
||||||
|
dv.push_back(draw(VT_CLOSEPATH, 0, 0));
|
||||||
|
}
|
||||||
|
return dv;
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "flatgeobuf has unsupported geometry type %u\n", (unsigned int)h_geometry_type);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void parse_flatgeobuf(std::vector<struct serialization_state> *sst, const char *src, int layer, std::string layername) {
|
void parse_flatgeobuf(std::vector<struct serialization_state> *sst, const char *src, int layer, std::string layername) {
|
||||||
auto header_size = flatbuffers::GetPrefixedSize((const uint8_t *)src + 8);
|
auto header_size = flatbuffers::GetPrefixedSize((const uint8_t *)src + 8);
|
||||||
auto header = FlatGeobuf::GetSizePrefixedHeader(src + 8);
|
auto header = FlatGeobuf::GetSizePrefixedHeader(src + 8);
|
||||||
@@ -86,7 +105,7 @@ void parse_flatgeobuf(std::vector<struct serialization_state> *sst, const char *
|
|||||||
case FlatGeobuf::GeometryType::GeometryCollection :
|
case FlatGeobuf::GeometryType::GeometryCollection :
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "flatgeobuf has unsupported geometry type\n");
|
fprintf(stderr, "flatgeobuf has unsupported geometry type %u\n", (unsigned int)h_geometry_type);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,18 +144,24 @@ void parse_flatgeobuf(std::vector<struct serialization_state> *sst, const char *
|
|||||||
FlatGeobuf::ColumnType col_type = h_column_types[col_idx];
|
FlatGeobuf::ColumnType col_type = h_column_types[col_idx];
|
||||||
|
|
||||||
serial_val sv;
|
serial_val sv;
|
||||||
if (col_type == FlatGeobuf::ColumnType::Long) {
|
if (col_type == FlatGeobuf::ColumnType::Int) {
|
||||||
|
sv.type = mvt_double; // this is quirky
|
||||||
|
int32_t int_val;
|
||||||
|
memcpy(&int_val, feature->properties()->data() + p_pos + 2, sizeof(int_val));
|
||||||
|
sv.s = to_string(int_val);
|
||||||
|
p_pos += 2 + sizeof(int_val);
|
||||||
|
} else if (col_type == FlatGeobuf::ColumnType::Long) {
|
||||||
sv.type = mvt_double; // this is quirky
|
sv.type = mvt_double; // this is quirky
|
||||||
uint64_t long_val;
|
uint64_t long_val;
|
||||||
memcpy(&long_val, feature->properties()->data() + p_pos + 2, sizeof(long_val));
|
memcpy(&long_val, feature->properties()->data() + p_pos + 2, sizeof(long_val));
|
||||||
sv.s = to_string(long_val);
|
sv.s = to_string(long_val);
|
||||||
p_pos += 2 + 8;
|
p_pos += 2 + sizeof(long_val);
|
||||||
} else if (col_type == FlatGeobuf::ColumnType::Double) {
|
} else if (col_type == FlatGeobuf::ColumnType::Double) {
|
||||||
sv.type = mvt_double;
|
sv.type = mvt_double;
|
||||||
double double_val;
|
double double_val;
|
||||||
memcpy(&double_val, feature->properties()->data() + p_pos + 2, sizeof(double_val));
|
memcpy(&double_val, feature->properties()->data() + p_pos + 2, sizeof(double_val));
|
||||||
sv.s = milo::dtoa_milo(double_val);
|
sv.s = milo::dtoa_milo(double_val);
|
||||||
p_pos += 2 + 8;
|
p_pos += 2 + sizeof(double_val);
|
||||||
} else if (col_type == FlatGeobuf::ColumnType::String) {
|
} else if (col_type == FlatGeobuf::ColumnType::String) {
|
||||||
sv.type = mvt_string;
|
sv.type = mvt_string;
|
||||||
uint32_t str_len;
|
uint32_t str_len;
|
||||||
@@ -145,7 +170,7 @@ void parse_flatgeobuf(std::vector<struct serialization_state> *sst, const char *
|
|||||||
sv.s = s;
|
sv.s = s;
|
||||||
p_pos += 2 + 4 + str_len;
|
p_pos += 2 + 4 + str_len;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "flatgeobuf has unsupported column type\n");
|
fprintf(stderr, "flatgeobuf has unsupported column type %u\n", (unsigned int)col_type);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
full_keys.push_back(h_column_names[col_idx]);
|
full_keys.push_back(h_column_names[col_idx]);
|
||||||
|
|||||||
Reference in New Issue
Block a user