Skip to content

Commit

Permalink
some clenaup
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche committed Oct 9, 2024
1 parent 2288f40 commit 5fb0170
Showing 1 changed file with 16 additions and 89 deletions.
105 changes: 16 additions & 89 deletions src/s2geography/geoarrow.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

#include "s2geography/geoarrow.h"

#include <sstream>
#include <iostream>

#include "geoarrow/geoarrow.h"
Expand Down Expand Up @@ -743,8 +742,6 @@ void Reader::ReadGeography(const ArrowArray* array, int64_t offset,
impl_->ReadGeography(array, offset, length, out);
}



class WriterImpl {
public:
WriterImpl() {
Expand All @@ -766,7 +763,8 @@ class WriterImpl {
InitCommon();
}

void Init(GeoArrowType type, const ImportOptions& options, struct ArrowSchema* out_schema) {
void Init(GeoArrowType type, const ImportOptions& options,
struct ArrowSchema* out_schema) {
options_ = options;

int code = GeoArrowArrayWriterInitFromType(&writer_, type);
Expand All @@ -788,8 +786,7 @@ class WriterImpl {
}

void WriteGeography(const Geography** geographies, size_t geographies_size,
struct ArrowArray* out){

struct ArrowArray* out) {
for (size_t i = 0; i < geographies_size; i++) {
// if (geography == nullptr) {
// GEOARROW_RETURN_NOT_OK(visitor_.feat_start(&visitor_));
Expand All @@ -811,30 +808,26 @@ class WriterImpl {
GeoArrowError error_;

int VisitPoints(const PointGeography& point) {
// coords_view_.n_coords = point.num_vertices();
// coords_view_.n_values = 3;
// coords_view_.values = point.data();
// return handler->coords(&coords_view_);
std::cout << "In VisitPoints" << "\n";
coords_view_.n_coords = 1;
coords_view_.n_values = 2;
coords_view_.coords_stride = 2;
double coords[2];

if (point.Points().size() == 0) {
GEOARROW_RETURN_NOT_OK(visitor_.geom_start(&visitor_, GEOARROW_GEOMETRY_TYPE_POINT, GEOARROW_DIMENSIONS_XY));
GEOARROW_RETURN_NOT_OK(visitor_.geom_start(
&visitor_, GEOARROW_GEOMETRY_TYPE_POINT, GEOARROW_DIMENSIONS_XY));
GEOARROW_RETURN_NOT_OK(visitor_.geom_end(&visitor_));
} else if (point.Points().size() == 1) {
GEOARROW_RETURN_NOT_OK(visitor_.geom_start(&visitor_, GEOARROW_GEOMETRY_TYPE_POINT, GEOARROW_DIMENSIONS_XY));
GEOARROW_RETURN_NOT_OK(visitor_.geom_start(
&visitor_, GEOARROW_GEOMETRY_TYPE_POINT, GEOARROW_DIMENSIONS_XY));
S2LatLng ll(point.Points()[0]);
coords_view_.n_coords = 1;
coords_view_.n_values = 2;
coords_view_.coords_stride = 2;
coords[0] = ll.lng().degrees();
coords[1] = ll.lat().degrees();
coords_view_.values[0] = &coords[0];
coords_view_.values[1] = &coords[1];
// coords_view_.values = static_cast<const double*[4]>(coords);
// GEOARROW_COORD_VIEW_VALUE(&coords_view_, 0, 0) = ll.lng().degrees();
// GEOARROW_COORD_VIEW_VALUE(&coords_view_, 0, 1) = ll.lng().degrees();

GEOARROW_RETURN_NOT_OK(visitor_.coords(&visitor_, &coords_view_));
GEOARROW_RETURN_NOT_OK(visitor_.geom_end(&visitor_));
}
Expand All @@ -854,12 +847,10 @@ class WriterImpl {

// handler->geom_end();
// }
std::cout << "-- end of VisitPoints" << "\n";
return GEOARROW_OK;
}

int VisitFeature(const Geography& geog) {
std::cout << "In VisitFeature" << "\n";
GEOARROW_RETURN_NOT_OK(visitor_.feat_start(&visitor_));

auto child_point = dynamic_cast<const PointGeography*>(&geog);
Expand All @@ -875,16 +866,15 @@ class WriterImpl {
// if (child_polygon != nullptr) {
// HANDLE_OR_RETURN(handle_polygon(*child_polygon, handler));
// } else {
// auto child_collection = dynamic_cast<const GeographyCollection*>(&geog);
// if (child_collection != nullptr) {
// auto child_collection = dynamic_cast<const
// GeographyCollection*>(&geog); if (child_collection != nullptr) {
// HANDLE_OR_RETURN(handle_collection(*child_collection, handler));
// } else {
// throw Exception("Unsupported Geography subclass");
// }
// }
// }
}
std::cout << "-- end of VisitFeature" << "\n";
return GEOARROW_OK;
}

Expand All @@ -895,7 +885,6 @@ class WriterImpl {
}
};


Writer::Writer() : impl_(new WriterImpl()) {}

Writer::~Writer() { impl_.reset(); }
Expand All @@ -904,7 +893,8 @@ void Writer::Init(const ArrowSchema* schema, const ImportOptions& options) {
impl_->Init(schema, options);
}

void Writer::Init(OutputType output_type, const ImportOptions& options, struct ArrowSchema* out_schema) {
void Writer::Init(OutputType output_type, const ImportOptions& options,
struct ArrowSchema* out_schema) {
switch (output_type) {
case OutputType::kPoints:
impl_->Init(GEOARROW_TYPE_INTERLEAVED_POINT, options, out_schema);
Expand All @@ -920,72 +910,9 @@ void Writer::Init(OutputType output_type, const ImportOptions& options, struct
}
}

void Writer::WriteGeography(const Geography** geographies, size_t geographies_size,
struct ArrowArray* out) {
void Writer::WriteGeography(const Geography** geographies,
size_t geographies_size, struct ArrowArray* out) {
impl_->WriteGeography(geographies, geographies_size, out);
}

// class ArrayBuilder {
// public:
// ArrayBuilder() : builder_(nullptr) {}

// ArrayBuilder(ArrayBuilder&& rhs) : builder_(rhs.builder_) { rhs.builder_ = nullptr; }

// ArrayBuilder(ArrayBuilder& rhs) = delete;

// ~ArrayBuilder() {
// if (builder_ != nullptr) {
// GeoArrowGEOSArrayBuilderDestroy(builder_);
// }
// }

// const char* GetLastError() {
// if (builder_ == nullptr) {
// return "";
// } else {
// return GeoArrowGEOSArrayBuilderGetLastError(builder_);
// }
// }

// GeoArrowGEOSErrorCode InitFromEncoding(GEOSContextHandle_t handle,
// GeoArrowGEOSEncoding encoding,
// int wkb_type = 0) {
// ArrowSchema tmp_schema;
// tmp_schema.release = nullptr;
// int result = GeoArrowGEOSMakeSchema(encoding, wkb_type, &tmp_schema);
// if (result != GEOARROW_GEOS_OK) {
// return result;
// }

// result = InitFromSchema(handle, &tmp_schema);
// tmp_schema.release(&tmp_schema);
// return result;
// }

// GeoArrowGEOSErrorCode InitFromSchema(GEOSContextHandle_t handle, ArrowSchema* schema) {
// if (builder_ != nullptr) {
// GeoArrowGEOSArrayBuilderDestroy(builder_);
// }

// return GeoArrowGEOSArrayBuilderCreate(handle, schema, &builder_);
// }

// GeoArrowGEOSErrorCode Append(const GEOSGeometry** geom, size_t geom_size,
// size_t* n_appended) {
// return GeoArrowGEOSArrayBuilderAppend(builder_, geom, geom_size, n_appended);
// }

// GeoArrowGEOSErrorCode Finish(struct ArrowArray* out) {
// return GeoArrowGEOSArrayBuilderFinish(builder_, out);
// }

// private:
// GeoArrowGEOSArrayBuilder* builder_;
// };




} // namespace geoarrow

} // namespace s2geography

0 comments on commit 5fb0170

Please sign in to comment.