Skip to content

Commit

Permalink
start new object
Browse files Browse the repository at this point in the history
  • Loading branch information
paleolimbot committed Jan 9, 2025
1 parent db02936 commit e4b3657
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 1 deletion.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ set(GEOARROW_SOURCES
src/geoarrow/array_view.c
src/geoarrow/util.c
src/geoarrow/visitor.c
src/geoarrow/native_writer.c
src/geoarrow/wkb_reader.c
src/geoarrow/wkb_writer.c
src/geoarrow/wkt_reader.c
Expand Down
2 changes: 1 addition & 1 deletion src/geoarrow/builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct BuilderPrivate {
int64_t size[32];
int32_t level;
int64_t null_count;
};
};

static ArrowErrorCode GeoArrowBuilderInitArrayAndCachePointers(
struct GeoArrowBuilder* builder) {
Expand Down
25 changes: 25 additions & 0 deletions src/geoarrow/geoarrow.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,31 @@ GeoArrowErrorCode GeoArrowArrayViewVisit(const struct GeoArrowArrayView* array_v
int64_t offset, int64_t length,
struct GeoArrowVisitor* v);

struct GeoArrowNativeWriter {
void* private_data;
};

/// \brief Initialize the memory of a GeoArrowNativeWriter
///
/// If GEOARROW_OK is returned, the caller is responsible for calling
/// GeoArrowNativeWriterReset().
GeoArrowErrorCode GeoArrowNativeWriterInit(struct GeoArrowNativeWriter* writer,
enum GeoArrowType type);

/// \brief Populate a GeoArrowVisitor pointing to this writer
GeoArrowErrorCode GeoArrowNativeWriterInitVisitor(struct GeoArrowNativeWriter* writer,
struct GeoArrowVisitor* v);

/// \brief Finish an ArrowArray containing elements from the visited input
///
/// This function can be called more than once to support multiple batches.
GeoArrowErrorCode GeoArrowNativeWriterFinish(struct GeoArrowNativeWriter* writer,
struct ArrowArray* array,
struct GeoArrowError* error);

/// \brief Free resources held by a GeoArrowNativeWriter
void GeoArrowNativeWriterReset(struct GeoArrowNativeWriter* writer);

/// \brief Well-known text writer
///
/// This struct also contains options for well-known text serialization.
Expand Down
56 changes: 56 additions & 0 deletions src/geoarrow/native_writer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

#include <string.h>

#include "nanoarrow/nanoarrow.h"

#include "geoarrow.h"

// Bytes for four quiet (little-endian) NANs
// static uint8_t kEmptyPointCoords[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x7f,
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x7f,
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x7f,
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x7f};

struct GeoArrowNativeWriterPrivate {
struct GeoArrowBuilder builder;

// Fields to keep track of state when using the visitor pattern
int visitor_initialized;
int feat_is_null;
int nesting_multipoint;
double empty_coord_values[4];
struct GeoArrowCoordView empty_coord;
enum GeoArrowDimensions last_dimensions;
int64_t size[32];
int32_t level;
int64_t null_count;
};

GeoArrowErrorCode GeoArrowNativeWriterInit(struct GeoArrowNativeWriter* writer,

enum GeoArrowType type) {
struct GeoArrowNativeWriterPrivate* private_data =
(struct GeoArrowNativeWriterPrivate*)ArrowMalloc(
sizeof(struct GeoArrowNativeWriterPrivate));
if (private_data == NULL) {
return ENOMEM;
}

memset(private_data, 0, sizeof(struct GeoArrowNativeWriterPrivate));

GeoArrowErrorCode code = GeoArrowBuilderInitFromType(&private_data->builder, type);
if (code != GEOARROW_OK) {
ArrowFree(private_data);
return code;
}

writer->private_data = private_data;
return GEOARROW_OK;
}

void GeoArrowNativeWriterReset(struct GeoArrowNativeWriter* writer) {
struct GeoArrowNativeWriterPrivate* private_data =
(struct GeoArrowNativeWriterPrivate*)writer->private_data;
GeoArrowBuilderReset(&private_data->builder);
ArrowFree(private_data);
}

0 comments on commit e4b3657

Please sign in to comment.