Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

close wkt #138

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading