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

GEOS: Wrap Make Valid #433

Merged
merged 5 commits into from
Nov 22, 2021
Merged

GEOS: Wrap Make Valid #433

merged 5 commits into from
Nov 22, 2021

Conversation

peterstace
Copy link
Owner

@peterstace peterstace commented Nov 17, 2021

Description

  • Wraps the GEOSMakeValid_r function from GEOS.

Check List

Have you:

  • Added unit tests? Yes, just to confirm that the wrapping is working. Doesn't actually do extensive tests of the functionality.

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

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

Related Issue

Benchmark Results

N/A

@peterstace peterstace self-assigned this Nov 17, 2021
@peterstace
Copy link
Owner Author

Hmm, CI build is failing with geos/entrypoints.go:320:10: could not determine kind of name for C.GEOSMakeValid_r. I think this means that GEOSMakeValid_r is not available in that particular version of GEOS. So there's the potential for this change to add a minimum required version of GEOS, which might not be ideal.

@peterstace
Copy link
Owner Author

I think I've got a decent solution for this in c8e5fa0

It basically checks the current GEOS version, and defines a C stub if it doesn't exist. It then checks the version and gives a friendly error if it's about to call the stub.

@@ -62,6 +61,7 @@ func newHandle() (*handle, error) {
h.release()
return nil, errors.New("malloc failed")
}
C.memset((unsafe.Pointer)(h.errBuf), 0, 1024)
Copy link
Owner Author

Choose a reason for hiding this comment

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

This was a bug I noticed while I was here. Malloc is not going to actually zero out the memory content... (I've been spoilt by Go).

Copy link
Collaborator

@albertteoh albertteoh left a comment

Choose a reason for hiding this comment

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

Nice one, a few comments mainly to help with my understanding of the historical context for this PR.

},
} {
t.Run(strconv.Itoa(i), func(t *testing.T) {
in := geomFromWKT(t, tt.input, geom.DisableAllValidations)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a way to assert that the input geometry is invalid?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yes, that's possible. Added in 65c2837

@@ -30,6 +30,9 @@ __Special thanks to Albert Teoh and Sameera Perera for contributing to this rele
- Fixes a bug in Simplify where invalid interior rings would be omitted rather
than producing an error.

- Adds a wrapper in the `geos` package for the `GEOSMakeValid_r` function
Copy link
Collaborator

Choose a reason for hiding this comment

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

What was the motivation for wrapping the GEOSMakeValid_r function? What challenges are there to implementing this natively in Go?

Copy link
Owner Author

Choose a reason for hiding this comment

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

It's something that Ken may find useful in his current work (might be better to take that discussion offline for further details).

The main challenges involved there would be coming up with an actual algorithm to do it (possibly that's the hard part) and the implementing it. It would most likely involve a DCEL data structure (which we have already implemented). I'd ballpark estimate 50hrs to 100hrs of effort would be required.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If there are plans to do this, maybe it's worth creating a ticket for this work; but if it's not in scope of the goals of simplefeatures, then all good.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Good call, it's definitely in scope. I've created a ticket here: #435

)
#if MAKE_VALID_MISSING
// This stub implementation always fails:
GEOSGeometry *GEOSMakeValid_r(GEOSContextHandle_t handle, const GEOSGeometry* g) { return NULL; }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this needed to prevent a compile-time error?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yes, that's correct. Prior versions of the GEOS library don't define the symbol at all, so we can define a stub version conditionally if the GEOS library doesn't do it for us (of course, that stub implementation wouldn't actually do anything, but we can check for that condition before invoking it).

Copy link
Collaborator

@albertteoh albertteoh left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -30,6 +30,9 @@ __Special thanks to Albert Teoh and Sameera Perera for contributing to this rele
- Fixes a bug in Simplify where invalid interior rings would be omitted rather
than producing an error.

- Adds a wrapper in the `geos` package for the `GEOSMakeValid_r` function
Copy link
Collaborator

Choose a reason for hiding this comment

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

If there are plans to do this, maybe it's worth creating a ticket for this work; but if it's not in scope of the goals of simplefeatures, then all good.

@peterstace
Copy link
Owner Author

Thanks for the review, I really appreciate it! 🥳

@peterstace peterstace merged commit 6860cb2 into master Nov 22, 2021
@peterstace peterstace deleted the wrap_make_valid branch November 22, 2021 18:25
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