Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::ArrowGeometry Struct Reference

Static Public Member Functions

static unique_ptr< ArrowTypeGetType (ClientContext &context, const ArrowSchema &schema, const ArrowSchemaMetadata &schema_metadata)
 
static void WriteCRS (duckdb_yyjson::yyjson_mut_doc *doc, const CoordinateReferenceSystem &crs, ClientContext &context)
 
static void PopulateSchema (DuckDBArrowSchemaHolder &root_holder, ArrowSchema &schema, const LogicalType &type, ClientContext &context, const ArrowTypeExtension &extension)
 
static void ArrowToDuck (ClientContext &, Vector &source, Vector &result, idx_t count)
 
static void DuckToArrow (ClientContext &context, Vector &source, Vector &result, idx_t count)
 

Member Function Documentation

◆ GetType()

static unique_ptr< ArrowType > duckdb::ArrowGeometry::GetType ( ClientContext context,
const ArrowSchema schema,
const ArrowSchemaMetadata schema_metadata 
)
inlinestatic
45342 {
45343 // Validate extension metadata. This metadata also contains a CRS, which we drop
45344 // because the GEOMETRY type does not implement a CRS at the type level (yet).
45345 const auto extension_metadata = schema_metadata.GetOption(ArrowSchemaMetadata::ARROW_METADATA_KEY);
45346
45347 unique_ptr<CoordinateReferenceSystem> duckdb_crs;
45348
45349 if (!extension_metadata.empty()) {
45350 unique_ptr<duckdb_yyjson::yyjson_doc, void (*)(duckdb_yyjson::yyjson_doc *)> doc(
45351 duckdb_yyjson::yyjson_read(extension_metadata.data(), extension_metadata.size(),
45352 duckdb_yyjson::YYJSON_READ_NOFLAG),
45353 duckdb_yyjson::yyjson_doc_free);
45354 if (!doc) {
45355 throw SerializationException("Invalid JSON in GeoArrow metadata");
45356 }
45357
45358 duckdb_yyjson::yyjson_val *val = yyjson_doc_get_root(doc.get());
45359 if (!yyjson_is_obj(val)) {
45360 throw SerializationException("Invalid GeoArrow metadata: not a JSON object");
45361 }
45362
45363 duckdb_yyjson::yyjson_val *edges = yyjson_obj_get(val, "edges");
45364 if (edges && yyjson_is_str(edges) && std::strcmp(yyjson_get_str(edges), "planar") != 0) {
45365 throw NotImplementedException("Can't import non-planar edges");
45366 }
45367
45368 // Pick out the CRS if present
45369 duckdb_yyjson::yyjson_val *crs = yyjson_obj_get(val, "crs");
45370
45371 if (crs) {
45372 if (duckdb_yyjson::yyjson_is_str(crs)) {
45373 const char *crs_str = duckdb_yyjson::yyjson_get_str(crs);
45374 duckdb_crs = CoordinateReferenceSystem::TryIdentify(context, crs_str);
45375 } else if (duckdb_yyjson::yyjson_is_obj(crs)) {
45376 // Stringify the object
45377 duckdb_yyjson::yyjson_write_flag write_flags = duckdb_yyjson::YYJSON_WRITE_NOFLAG;
45378 size_t len = 0;
45379 const auto crs_str = duckdb_yyjson::yyjson_val_write(crs, write_flags, &len);
45380 if (crs_str) {
45381 const auto str = string(crs_str, len);
45382 free(crs_str);
45383 duckdb_crs = CoordinateReferenceSystem::TryIdentify(context, str);
45384 } else {
45385 throw SerializationException("Could not serialize CRS object from GeoArrow metadata");
45386 }
45387 }
45388 }
45389 }
45390
45391 // Create the geometry type, with or without CRS
45392 auto geo_type = duckdb_crs ? LogicalType::GEOMETRY(*duckdb_crs) : LogicalType::GEOMETRY();
45393
45394 const auto format = string(schema.format);
45395 if (format == "z") {
45396 return make_uniq<ArrowType>(std::move(geo_type), make_uniq<ArrowStringInfo>(ArrowVariableSizeType::NORMAL));
45397 }
45398 if (format == "Z") {
45399 return make_uniq<ArrowType>(std::move(geo_type),
45400 make_uniq<ArrowStringInfo>(ArrowVariableSizeType::SUPER_SIZE));
45401 }
45402 if (format == "vz") {
45403 return make_uniq<ArrowType>(std::move(geo_type), make_uniq<ArrowStringInfo>(ArrowVariableSizeType::VIEW));
45404 }
45405 throw InvalidInputException("Arrow extension type \"%s\" not supported for geoarrow.wkb", format.c_str());
45406 }
static constexpr const char * ARROW_METADATA_KEY
Key for encode of the metadata key.
Definition duckdb.cpp:34558
static unique_ptr< CoordinateReferenceSystem > TryIdentify(ClientContext &context, const string &source_crs)
const char * format
Array type description.
Definition duckdb.hpp:11265
Definition duckdb.cpp:41548
Definition duckdb.cpp:41543

◆ WriteCRS()

static void duckdb::ArrowGeometry::WriteCRS ( duckdb_yyjson::yyjson_mut_doc doc,
const CoordinateReferenceSystem crs,
ClientContext context 
)
inlinestatic
45409 {
45410 // Try to convert to preferred formats, in order
45412 if (!converted) {
45414 }
45415 if (!converted) {
45417 }
45418 if (!converted) {
45420 }
45421 if (!converted) {
45422 converted = nullptr;
45423 }
45424
45425 const auto &crs_def = converted ? converted->GetDefinition() : crs.GetDefinition();
45426 const auto &crs_type = converted ? converted->GetType() : crs.GetType();
45427
45428 const auto root = duckdb_yyjson::yyjson_mut_doc_get_root(doc);
45429
45430 switch (crs_type) {
45432 const auto projjson_doc =
45433 duckdb_yyjson::yyjson_read(crs_def.c_str(), crs_def.size(), duckdb_yyjson::YYJSON_READ_NOFLAG);
45434 if (projjson_doc) {
45435 const auto projjson_val = duckdb_yyjson::yyjson_doc_get_root(projjson_doc);
45436 const auto projjson_obj = duckdb_yyjson::yyjson_val_mut_copy(doc, projjson_val);
45437
45438 duckdb_yyjson::yyjson_mut_obj_add_str(doc, root, "crs_type", "projjson");
45439 duckdb_yyjson::yyjson_mut_obj_add_val(doc, root, "crs", projjson_obj);
45440
45441 duckdb_yyjson::yyjson_doc_free(projjson_doc);
45442 } else {
45443 duckdb_yyjson::yyjson_mut_doc_free(doc);
45444 throw SerializationException("Could not parse PROJJSON CRS for GeoArrow metadata");
45445 }
45446 } break;
45448 duckdb_yyjson::yyjson_mut_obj_add_str(doc, root, "crs_type", "authority_code");
45449 duckdb_yyjson::yyjson_mut_obj_add_str(doc, root, "crs", crs_def.c_str());
45450 } break;
45452 duckdb_yyjson::yyjson_mut_obj_add_str(doc, root, "crs_type", "srid");
45453 duckdb_yyjson::yyjson_mut_obj_add_str(doc, root, "crs", crs_def.c_str());
45454 } break;
45456 duckdb_yyjson::yyjson_mut_obj_add_str(doc, root, "crs_type", "wkt2:2019");
45457 duckdb_yyjson::yyjson_mut_obj_add_str(doc, root, "crs", crs_def.c_str());
45458 } break;
45459 default:
45460 throw SerializationException("Could not serialize CRS of type %d for GeoArrow metadata",
45461 static_cast<int>(crs.GetType()));
45462 }
45463 }
static unique_ptr< CoordinateReferenceSystem > TryConvert(ClientContext &context, const CoordinateReferenceSystem &source_crs, CoordinateReferenceSystemType target_type)

◆ PopulateSchema()

static void duckdb::ArrowGeometry::PopulateSchema ( DuckDBArrowSchemaHolder root_holder,
ArrowSchema schema,
const LogicalType type,
ClientContext context,
const ArrowTypeExtension extension 
)
inlinestatic
45466 {
45467 ArrowSchemaMetadata schema_metadata;
45468
45469 schema_metadata.AddOption(ArrowSchemaMetadata::ARROW_EXTENSION_NAME, "geoarrow.wkb");
45470
45471 // Make a CRS entry if the type has a CRS
45472 const auto doc = duckdb_yyjson::yyjson_mut_doc_new(nullptr);
45473 const auto root = duckdb_yyjson::yyjson_mut_obj(doc);
45474 duckdb_yyjson::yyjson_mut_doc_set_root(doc, root);
45475
45476 if (GeoType::HasCRS(type)) {
45477 try {
45478 WriteCRS(doc, GeoType::GetCRS(type), context);
45479 } catch (...) {
45480 duckdb_yyjson::yyjson_mut_doc_free(doc);
45481 throw;
45482 }
45483 }
45484
45485 size_t json_size = 0;
45486 const auto json_text = duckdb_yyjson::yyjson_mut_write(doc, duckdb_yyjson::YYJSON_WRITE_NOFLAG, &json_size);
45487 if (json_text) {
45488 schema_metadata.AddOption(ArrowSchemaMetadata::ARROW_METADATA_KEY, json_text);
45489 duckdb_yyjson::yyjson_mut_doc_free(doc);
45490 free(json_text);
45491 } else {
45492 schema_metadata.AddOption(ArrowSchemaMetadata::ARROW_METADATA_KEY, "{}");
45493 }
45494
45495 root_holder.metadata_info.emplace_back(schema_metadata.SerializeMetadata());
45496 schema.metadata = root_holder.metadata_info.back().get();
45497
45498 const auto options = context.GetClientProperties();
45499 if (options.arrow_offset_size == ArrowOffsetSize::LARGE) {
45500 schema.format = "Z";
45501 } else {
45502 schema.format = "z";
45503 }
45504 }
static constexpr const char * ARROW_EXTENSION_NAME
Key for encode of the extension type name.
Definition duckdb.cpp:34556

◆ ArrowToDuck()

static void duckdb::ArrowGeometry::ArrowToDuck ( ClientContext ,
Vector source,
Vector result,
idx_t  count 
)
inlinestatic
45506 {
45507 Geometry::FromBinary(source, result, count, true);
45508 }
static DUCKDB_API bool FromBinary(const string_t &wkb, string_t &result, Vector &result_vector, bool strict)
Convert from WKB.

◆ DuckToArrow()

static void duckdb::ArrowGeometry::DuckToArrow ( ClientContext context,
Vector source,
Vector result,
idx_t  count 
)
inlinestatic
45510 {
45511 Geometry::ToBinary(source, result, count);
45512 }
static DUCKDB_API void ToBinary(Vector &source, Vector &result, idx_t count)
Convert to WKB.

The documentation for this struct was generated from the following file: