FlatCityBuf C++ reader 0.10.0
Native C++17 reader for FlatCityBuf, the cloud-optimized CityJSON format
Loading...
Searching...
No Matches
attribute.hpp
Go to the documentation of this file.
1#pragma once
2
3#ifdef FCB_WITH_JSON
4
5# include <fcb/generated/header_generated.h>
6# include <fcb/key.hpp>
7
8# include <nlohmann/json.hpp>
9
10# include <cstdint>
11# include <map>
12# include <optional>
13# include <string>
14# include <utility>
15# include <vector>
16
17# include <flatbuffers/flatbuffers.h>
18
19namespace fcb {
20
43using AttributeSchema = std::map<std::string, std::pair<std::uint16_t, ::ColumnType>>;
44
51void add_attributes(AttributeSchema& schema, const nlohmann::ordered_json& attrs);
52
55std::size_t attr_size(::ColumnType coltype, const nlohmann::ordered_json& colval);
56
63std::vector<std::uint8_t> encode_attributes_with_schema(const nlohmann::ordered_json& attr,
64 const AttributeSchema& schema);
65
70::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<::Column>>>
71to_columns(::flatbuffers::FlatBufferBuilder& fbb, const AttributeSchema& schema,
72 std::optional<std::uint16_t> id_column = std::nullopt);
73
76inline constexpr const char* kIdColumnName = "id";
77
82std::optional<std::uint16_t> id_column_index(const std::optional<std::uint16_t>& id_index,
83 const AttributeSchema& schema);
84
89 std::uint16_t index;
91};
92
96std::vector<AttributeIndexEntry>
97cityfeature_to_id_index_entries(const nlohmann::ordered_json& city_feature, std::uint16_t index);
98
107std::vector<AttributeIndexEntry>
108attribute_to_index_entries(const nlohmann::ordered_json& attr, const AttributeSchema& schema,
109 const std::vector<std::string>& indexing_attr);
110
116std::vector<AttributeIndexEntry>
117cityfeature_to_index_entries(const nlohmann::ordered_json& city_feature,
118 const AttributeSchema& schema,
119 const std::vector<std::string>& indexing_attr);
120
121} // namespace fcb
122
123#endif // FCB_WITH_JSON
A decoded index key.
Definition key.hpp:40
std::vector< std::uint8_t > encode_attributes_with_schema(const nlohmann::ordered_json &attr, const AttributeSchema &schema)
Encodes attr (a CityJSON attributes object) against schema: repeated [u16 LE column index][value] rec...
::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<::Column > > > to_columns(::flatbuffers::FlatBufferBuilder &fbb, const AttributeSchema &schema, std::optional< std::uint16_t > id_column=std::nullopt)
Builds the Column vector for Header.columns or CityObject.columns, in ascending column-index order.
std::size_t attr_size(::ColumnType coltype, const nlohmann::ordered_json &colval)
Byte width one value of coltype occupies in the attribute blob, EXCLUDING the 2-byte column-index pre...
constexpr const char * kIdColumnName
The name of the header column that stands for a City Object's id.
Definition attribute.hpp:76
std::map< std::string, std::pair< std::uint16_t, ::ColumnType > > AttributeSchema
Attribute schema: name -> (column index, column type).
Definition attribute.hpp:43
void add_attributes(AttributeSchema &schema, const nlohmann::ordered_json &attrs)
Adds every member of a JSON object to schema, assigning each new, non-null name the next free column ...
std::vector< AttributeIndexEntry > cityfeature_to_index_entries(const nlohmann::ordered_json &city_feature, const AttributeSchema &schema, const std::vector< std::string > &indexing_attr)
Same, over every object in one CityJSONFeature's CityObjects, visited in ascending object-id order (n...
std::vector< AttributeIndexEntry > cityfeature_to_id_index_entries(const nlohmann::ordered_json &city_feature, std::uint16_t index)
One index entry per City Object of city_feature, keyed by the object's id, for the id column at index...
std::optional< std::uint16_t > id_column_index(const std::optional< std::uint16_t > &id_index, const AttributeSchema &schema)
The index of the City Object id column: the next free one when id_index asks for an id index and sche...
std::vector< AttributeIndexEntry > attribute_to_index_entries(const nlohmann::ordered_json &attr, const AttributeSchema &schema, const std::vector< std::string > &indexing_attr)
Extracts index entries for indexing_attr from one CityJSON attributes object.
One indexable (column, value) pair pulled out of a feature for the static B+tree builder (M6).
Definition attribute.hpp:88