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

Add BoundingDiagonal() method to Envelope #489

Merged
merged 2 commits into from
Feb 6, 2023
Merged

Conversation

peterstace
Copy link
Owner

Description

The main usecase for this method is to help a user construct a compact representation of an envelope, for example as WKB. Rather than encoding the polygon representation of the Envelope, the LineString representation can be used instead.

The Polygon representation uses 89 bytes (1 for the byte order, 4 to encode the number of rings, 4 to encode the number of points in the outer ring, and then 80 to represent the 5 points in the ring itself). The LineString representation only uses 37 bytes (1 for the byte order, 4 to encode the number
of points, and 32 to represent 2 points).

Check List

Have you:

  • Added unit tests? Yes.

  • Add cmprefimpl tests? (if appropriate?) N/A

  • Updated release notes? (if appropriate?) Yes.

Related Issue

Benchmark Results

N/A, this is new functionality that doesn't have benchmark tests.

The main usecase for this method is to help a user construct a compact
representation of an envelope, for example as WKB. Rather than encoding
the polygon representation of the Envelope, the LineString
representation can be used instead.

The Polygon representation uses 89 bytes (1 for the byte order, 4 to
encode the number of rings, 4 to encode the number of points in the
outer ring, and then 80 to represent the 5 points in the ring itself).
The LineString representation only uses 37 bytes (1 for the byte order,
4 to encode the number of points, and 32 to represent 2 points).
@peterstace peterstace self-assigned this Feb 4, 2023
@@ -295,3 +295,27 @@ func (e Envelope) box() (rtree.Box, bool) {
MaxY: e.maxY,
}, !e.IsEmpty()
}

// BoundingDiagonal returns the LineString that goes from the minimum point in
// the Envelope to the point in the Envelope. If the envelope is degenerate and
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from the minimum point in the Envelope to the point in the Envelope: to which point in the Envelope?

What do you think about describing this as a LineString going from the bottom-left vertex to the top-right vertex of the envelope? At least, that's my understanding of the code, but perhaps my understanding/terminology is too plebeian. 😅

Copy link
Owner Author

@peterstace peterstace Feb 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I should have said "from the minimum point in the Envelope to the maximum point in the Envelope".

What do you think about describing this as a LineString going from the bottom-left vertex to the top-right vertex of the envelope?

That would work if we could assume that geometries were always in a coordinate system where X increases from left to right and Y as you move up the map. WGS84 and the UTM projections are examples. Unfortunately it doesn't hold for other projections, such as Web Mertcator, which has Y increasing as you move down the map.

I've reworded the comment in 3046816 to explicitly refer to the Min and Max methods, which is uses to construct the LineString.

@peterstace
Copy link
Owner Author

Thanks for reviewing! 🙇

@peterstace peterstace merged commit 0f60dd0 into master Feb 6, 2023
@peterstace peterstace deleted the bounding_diagonal branch February 6, 2023 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants