Skip to content

Commit

Permalink
clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche committed Oct 26, 2024
1 parent 082a929 commit 198e85e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 39 deletions.
61 changes: 23 additions & 38 deletions src/s2geography/geoarrow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,14 @@ class WriterImpl {
visitor_.error = &error_;
int code = GeoArrowArrayWriterInitVisitor(&writer_, &visitor_);
ThrowNotOk(code);

// Currently we always visit single coordinate pairs one by one, so set
// up the appropiate view for that once, which is then reused
coords_view_.n_coords = 1;
coords_view_.n_values = 2;
coords_view_.coords_stride = 2;
coords_view_.values[0] = &coords_[0];
coords_view_.values[1] = &coords_[1];
}

void WriteGeography(const Geography& geog) { VisitFeature(geog); }
Expand All @@ -791,15 +799,10 @@ class WriterImpl {
GeoArrowArrayWriter writer_;
GeoArrowVisitor visitor_;
GeoArrowCoordView coords_view_;
double coords_[2];
GeoArrowError error_;

int VisitPoints(const PointGeography& point) {
coords_view_.n_coords = 1;
coords_view_.n_values = 2;
coords_view_.coords_stride = 2;
double coords[2];
coords_view_.values[0] = &coords[0];
coords_view_.values[1] = &coords[1];

if (point.Points().size() == 0) {
// empty Point
Expand All @@ -812,8 +815,8 @@ class WriterImpl {
GEOARROW_RETURN_NOT_OK(visitor_.geom_start(
&visitor_, GEOARROW_GEOMETRY_TYPE_POINT, GEOARROW_DIMENSIONS_XY));
S2LatLng ll(point.Points()[0]);
coords[0] = ll.lng().degrees();
coords[1] = ll.lat().degrees();
coords_[0] = ll.lng().degrees();
coords_[1] = ll.lat().degrees();
GEOARROW_RETURN_NOT_OK(visitor_.coords(&visitor_, &coords_view_));
GEOARROW_RETURN_NOT_OK(visitor_.geom_end(&visitor_));

Expand All @@ -827,8 +830,8 @@ class WriterImpl {
GEOARROW_RETURN_NOT_OK(visitor_.geom_start(
&visitor_, GEOARROW_GEOMETRY_TYPE_POINT, GEOARROW_DIMENSIONS_XY));
S2LatLng ll(pt);
coords[0] = ll.lng().degrees();
coords[1] = ll.lat().degrees();
coords_[0] = ll.lng().degrees();
coords_[1] = ll.lat().degrees();
GEOARROW_RETURN_NOT_OK(visitor_.coords(&visitor_, &coords_view_));
GEOARROW_RETURN_NOT_OK(visitor_.geom_end(&visitor_));
}
Expand All @@ -839,12 +842,6 @@ class WriterImpl {
}

int VisitPolylines(const PolylineGeography& geog) {
coords_view_.n_coords = 1;
coords_view_.n_values = 2;
coords_view_.coords_stride = 2;
double coords[2];
coords_view_.values[0] = &coords[0];
coords_view_.values[1] = &coords[1];

if (geog.Polylines().size() == 0) {
// empty LineString
Expand All @@ -863,8 +860,8 @@ class WriterImpl {

for (int i = 0; i < poly->num_vertices(); i++) {
S2LatLng ll(poly->vertex(i));
coords[0] = ll.lng().degrees();
coords[1] = ll.lat().degrees();
coords_[0] = ll.lng().degrees();
coords_[1] = ll.lat().degrees();
GEOARROW_RETURN_NOT_OK(visitor_.coords(&visitor_, &coords_view_));
}

Expand All @@ -883,8 +880,8 @@ class WriterImpl {

for (int i = 0; i < poly->num_vertices(); i++) {
S2LatLng ll(poly->vertex(i));
coords[0] = ll.lng().degrees();
coords[1] = ll.lat().degrees();
coords_[0] = ll.lng().degrees();
coords_[1] = ll.lat().degrees();
GEOARROW_RETURN_NOT_OK(visitor_.coords(&visitor_, &coords_view_));
}

Expand All @@ -898,12 +895,6 @@ class WriterImpl {
}

int VisitLoopShell(const S2Loop* loop) {
coords_view_.n_coords = 1;
coords_view_.n_values = 2;
coords_view_.coords_stride = 2;
double coords[2];
coords_view_.values[0] = &coords[0];
coords_view_.values[1] = &coords[1];

if (loop->num_vertices() == 0) {
throw Exception("Unexpected S2Loop with 0 verties");
Expand All @@ -913,8 +904,8 @@ class WriterImpl {

for (int i = 0; i <= loop->num_vertices(); i++) {
S2LatLng ll(loop->vertex(i));
coords[0] = ll.lng().degrees();
coords[1] = ll.lat().degrees();
coords_[0] = ll.lng().degrees();
coords_[1] = ll.lat().degrees();
GEOARROW_RETURN_NOT_OK(visitor_.coords(&visitor_, &coords_view_));
}

Expand All @@ -924,12 +915,6 @@ class WriterImpl {
}

int VisitLoopHole(const S2Loop* loop) {
coords_view_.n_coords = 1;
coords_view_.n_values = 2;
coords_view_.coords_stride = 2;
double coords[2];
coords_view_.values[0] = &coords[0];
coords_view_.values[1] = &coords[1];

if (loop->num_vertices() == 0) {
throw Exception("Unexpected S2Loop with 0 verties");
Expand All @@ -941,14 +926,14 @@ class WriterImpl {
// have the opposite orientation of the shell
for (int i = loop->num_vertices() - 1; i >= 0; i--) {
S2LatLng ll(loop->vertex(i));
coords[0] = ll.lng().degrees();
coords[1] = ll.lat().degrees();
coords_[0] = ll.lng().degrees();
coords_[1] = ll.lat().degrees();
GEOARROW_RETURN_NOT_OK(visitor_.coords(&visitor_, &coords_view_));
}

S2LatLng ll(loop->vertex(loop->num_vertices() - 1));
coords[0] = ll.lng().degrees();
coords[1] = ll.lat().degrees();
coords_[0] = ll.lng().degrees();
coords_[1] = ll.lat().degrees();
GEOARROW_RETURN_NOT_OK(visitor_.coords(&visitor_, &coords_view_));

GEOARROW_RETURN_NOT_OK(visitor_.ring_end(&visitor_));
Expand Down
2 changes: 1 addition & 1 deletion src/s2geography/geoarrow.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class WriterImpl;

/// \brief Array writer for any GeoArrow extension array
///
/// This class is used to convert a vector of Geography objects into an ArrowArray
/// This class is used to convert Geography objects into an ArrowArray
/// with geoarrow data (serialized or native).
class Writer {
public:
Expand Down

0 comments on commit 198e85e

Please sign in to comment.