Repository navigation
Fix spatial Length translation for polygons and collections - #4167
Merged
Merged
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the spatial Length translation fix.
No open issues 🎉
What changed in this PR
Corrects spatial Length translation in the EF Core PostgreSQL provider, addressing #4151 so polygons return their perimeter instead of zero.
Changes:
- Uses
ST_Perimeterfor polygons and multipolygons, with type-aware handling for polymorphic values and collections. - Preserves geography mappings through CLR casts to keep measurements geodesic.
- Adds regression coverage for spatial types, dimensions, nulls, and casts, and documents the polygon translations.
| File | Description |
|---|---|
| test/EFCore.PG.FunctionalTests/Query/SpatialQueryNpgsqlGeometryTest.cs | Adds geometry length assertions and SQL baselines. |
| test/EFCore.PG.FunctionalTests/Query/SpatialQueryNpgsqlGeographyTest.cs | Covers geodesic lengths, collections, casts, and per-property geography mappings. |
| src/EFCore.PG.NTS/Query/ExpressionTranslators/Internal/NpgsqlNetTopologySuiteMemberTranslatorPlugin.cs | Selects length or perimeter by spatial type while preserving geography mappings. |
| docs/mapping/nts.md | Documents polygon and multipolygon Length translations. |
Review effort: Balanced
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Comment on lines
+234
to
+236
| return _sqlExpressionFactory.Case( | ||
| [new CaseWhenClause(_sqlExpressionFactory.In(Function("GeometryType", [instance], typeof(string)), polygonTypes), perimeter)], | ||
| length); |
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.

Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
5e0d65ce8f013ac553cc5b03fb16a51c5f7610b2↓ Only PostGIS 3.6.3 was tested; other versions and expression combinations remain unverified.
ST_Lengthreturns zero for polygons andST_Perimeterreturns their perimeter.Lengthscenario reproduces the incorrect zero result and is covered by the fix.NTS polygon
Lengthtranslates toST_Length, which returns zero instead of the perimeter. Collections and polymorphic geometries also require different handling depending on their actual types.Translate concrete polygons and multipolygons to
ST_Perimeter, keeping the single-functionST_Lengthtranslation for points and lines. For polymorphic values, select the appropriate function at runtime; geometry collections may need both length and perimeter. Preserve geography mappings through CLR casts so measurements remain geodesic.Closes #4151