mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-04-08 11:34:12 +00:00
FlatGeobuf MultiPolygon parsing [#2]
This commit is contained in:
parent
88cedf54d4
commit
b350a8dda7
@ -36,13 +36,12 @@ uint64_t PackedRTreeSize(const uint64_t numItems, const uint16_t nodeSize)
|
||||
return numNodes * sizeof(NodeItem);
|
||||
}
|
||||
|
||||
drawvec readGeometry(const FlatGeobuf::Geometry *geometry, FlatGeobuf::GeometryType geometry_type) {
|
||||
// if it is a GeometryCollection, parse Parts, ignore XY
|
||||
drawvec readPolygon(const FlatGeobuf::Geometry *geometry) {
|
||||
auto xy = geometry->xy();
|
||||
auto ends = geometry->ends();
|
||||
size_t current_end = 0;
|
||||
|
||||
drawvec dv;
|
||||
|
||||
for (unsigned int i = 0; i < xy->size(); i+=2) {
|
||||
long long 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));
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
auto header_size = flatbuffers::GetPrefixedSize((const uint8_t *)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 :
|
||||
break;
|
||||
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);
|
||||
}
|
||||
|
||||
@ -125,18 +144,24 @@ void parse_flatgeobuf(std::vector<struct serialization_state> *sst, const char *
|
||||
FlatGeobuf::ColumnType col_type = h_column_types[col_idx];
|
||||
|
||||
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
|
||||
uint64_t long_val;
|
||||
memcpy(&long_val, feature->properties()->data() + p_pos + 2, sizeof(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) {
|
||||
sv.type = mvt_double;
|
||||
double double_val;
|
||||
memcpy(&double_val, feature->properties()->data() + p_pos + 2, sizeof(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) {
|
||||
sv.type = mvt_string;
|
||||
uint32_t str_len;
|
||||
@ -145,7 +170,7 @@ void parse_flatgeobuf(std::vector<struct serialization_state> *sst, const char *
|
||||
sv.s = s;
|
||||
p_pos += 2 + 4 + str_len;
|
||||
} 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);
|
||||
}
|
||||
full_keys.push_back(h_column_names[col_idx]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user