Add opt-in linearization of curve types when reading - #35
Open
grootstebozewolf wants to merge 1 commit into
Open
Add opt-in linearization of curve types when reading#35grootstebozewolf wants to merge 1 commit into
grootstebozewolf wants to merge 1 commit into
Conversation
Reading CircularString, CompoundCurve and CurvePolygon values threw a ParseException. Add SqlServerBytesReader.LinearizeCurves to approximate them using LineString and Polygon values instead, and MaxLinearizationAngle to control the accuracy of the approximation. The default (pi/32) matches the granularity of SQL Server's STCurveToLine method. The original points of an arc are always preserved, and Z and M values of inserted points are interpolated linearly. Serialized test values were produced by SQL Server 2025, including the CurvePolygon circle from NetTopologySuite#18, and the expected values are point-wise comparisons against SQL Server's STCurveToLine output. Part of NetTopologySuite#18 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #18, as offered in this comment (thanks @bjornharrtell for the go-ahead).
Reading
CIRCULARSTRING,COMPOUNDCURVEorCURVEPOLYGONvalues currently throws aParseException, which (as discussed in #18) can't even be intercepted by an EF Core value converter. Since NTS itself has no curve geometry types yet (NetTopologySuite/NetTopologySuite#854 is still in progress), this adds a self-contained, opt-in client-side approximation instead — the equivalent of callingSTCurveToLinein SQL, but without having to change your queries:What it does
FigureAttribute.Arc/FigureAttribute.Curvefigures and the segment-type array) and approximates them usingLineStringandPolygonvalues. Works for curves nested insideGEOMETRYCOLLECTIONand forCURVEPOLYGONrings that mix line, arc and compound figures, for both geometry and geography data.MaxLinearizationAngleproperty controls accuracy (maximum angle subtended by one line segment). The default, π/32, matches the granularity SQL Server'sSTCurveToLineuses, so default output is point-wise identical to whatSTCurveToLinereturns (verified in tests).STCurveToLine— so the original points of an arc are always preserved in the output.STCurveToLinejust drops them; SQL Server requires constant Z along an arc anyway).ParseException.LinearizeCurves, the existingParseExceptionis thrown (its message now mentions the new option).What it doesn't do
LinearizeCurvescan be complemented by returning real curve geometries.Testing
All serialized test values were generated by SQL Server 2025 via
CAST(geometry::Parse(N'...') AS varbinary(max)), including the exactCURVEPOLYGONcircle from #18. Expected values are point-wise comparisons against SQL Server's actualSTCurveToLineoutput, plus geometric invariants (all approximated points lie on the arc's circle, rings close exactly, polygon areas match the inscribed-polygon formula). 113 tests pass (95 existing + 18 new).Happy to adjust naming, defaults or scope however you prefer.
🤖 Generated with Claude Code