Skip to content

Commit

Permalink
close wkt
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacbrodsky committed Dec 2, 2024
1 parent ee10e9f commit be04078
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/h3_directededge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ struct DirectedEdgeToBoundaryOperator {
// TODO: Is it possible to return null here instead?
return StringVector::EmptyString(result, 0);
} else {
std::string str = "POLYGON ((";
std::string str = "LINESTRING ((";
for (int i = 0; i <= boundary.numVerts; i++) {
std::string sep = (i == 0) ? "" : ", ";
int vertIndex = (i == boundary.numVerts) ? 0 : i;
Expand Down
1 change: 1 addition & 0 deletions src/h3_indexing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ struct CellToBoundaryOperator {
std::string str = "POLYGON ((";
for (int i = 0; i <= boundary.numVerts; i++) {
std::string sep = (i == 0) ? "" : ", ";
// Add an extra vertex onto the end to close the polygon
int vertIndex = (i == boundary.numVerts) ? 0 : i;
str += StringUtil::Format("%s%f %f", sep,
radsToDegs(boundary.verts[vertIndex].lng),
Expand Down
8 changes: 8 additions & 0 deletions src/h3_regions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ static void CellsToMultiPolygonWktFunction(DataChunk &args,
lat_lng_sep = ", ";
lat_lng = lat_lng->next;
}

if (loop->first) {
// Duplicate first vertex, to close the polygon
str += StringUtil::Format(", %f %f",
radsToDegs(loop->first->vertex.lng),
radsToDegs(loop->first->vertex.lat));
}

str += ")";
loop_sep = ", ";
loop = loop->next;
Expand Down
6 changes: 3 additions & 3 deletions test/sql/h3/h3_functions_directededge.test
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,17 @@ SELECT strlen(h3_directed_edge_to_boundary_wkt('0'))
query I
SELECT h3_directed_edge_to_boundary_wkt(1608492358964346879::ubigint)
----
POLYGON ((-121.915080 37.271356, -121.862223 37.353926, -121.915080 37.271356))
LINESTRING ((-121.915080 37.271356, -121.862223 37.353926, -121.915080 37.271356))

query I
SELECT h3_directed_edge_to_boundary_wkt(1608492358964346879::bigint)
----
POLYGON ((-121.915080 37.271356, -121.862223 37.353926, -121.915080 37.271356))
LINESTRING ((-121.915080 37.271356, -121.862223 37.353926, -121.915080 37.271356))

query I
SELECT h3_directed_edge_to_boundary_wkt('115283473fffffff')
----
POLYGON ((-122.037735 37.420129, -122.090429 37.337556, -122.037735 37.420129))
LINESTRING ((-122.037735 37.420129, -122.090429 37.337556, -122.037735 37.420129))

query I
SELECT h3_origin_to_directed_edges('85283473fffffff')
Expand Down
Loading

0 comments on commit be04078

Please sign in to comment.