Skip to content

SFCGAL: Add CG_Simplify - #803

Closed
lbartoletti wants to merge 3 commits into
postgis:masterfrom
lbartoletti:sfcgal_simplify
Closed

lbartoletti wants to merge 3 commits into
postgis:masterfrom
lbartoletti:sfcgal_simplify

Conversation

@lbartoletti

Copy link
Copy Markdown
Contributor

This introduces CG_Simplify, a new function for SFCGAL
backend based on sfcgal_geometry_simplify.
The algorithm is based on CGAL Simplification package and uses CDT.

The documentation and unit tests are updated accordingly.

Since our algorithm supports both Z and M coordinates, I have also enhanced the ptarray to SFCGAL conversion with proper M dimension support. This enhancement requires SFCGAL 1.5.0 or higher for M coordinate handling. This requirement is not an issue in practice, as the CG_Simplify function itself requires SFCGAL 2.1.0 or higher, which already satisfies the dependency.

SFCGAL 2.1 or above is needed.

cc @ptitjano

@coderabbitai

coderabbitai Bot commented May 14, 2025 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

A new geometry simplification function, CG_Simplify, has been introduced, leveraging SFCGAL's polyline simplification capabilities with support for Z and M coordinates and optional topology preservation. The change includes C implementation, SQL binding, documentation, test cases, expected outputs, and accompanying images and WKT data for illustrative and regression testing purposes.

Changes

File(s) Change Summary
sfcgal/lwgeom_sfcgal.c, sfcgal/sfcgal.sql.in Added C implementation and SQL binding for the new CG_Simplify function, supporting geometry simplification with optional topology.
doc/reference_sfcgal.xml Documented the new CG_Simplify function, its parameters, usage, algorithm, and provided illustrative examples and cross-references.
sfcgal/regress/simplify.sql, sfcgal/regress/simplify_expected, sfcgal/regress/tests.mk.in Added regression test SQL, expected output, and test registration for CG_Simplify (enabled for SFCGAL >= 2.1.0).
doc/html/images/Makefile.in Registered three new generated image files for inclusion in the build and install process.
doc/html/images/wkt/cg_simplify00.wkt, doc/html/images/wkt/cg_simplify01.wkt, doc/html/images/wkt/cg_simplify02.wkt Added WKT data files for input and result geometries used in documentation and examples.
NEWS Updated changelog to announce the addition of the CG_Simplify function in version 3.6.0.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SQL
    participant PostGIS
    participant SFCGAL

    User->>SQL: CALL CG_Simplify(geom, threshold, preserveTopology)
    SQL->>PostGIS: Invoke sfcgal_simplify()
    PostGIS->>SFCGAL: Convert geometry and call sfcgal_geometry_simplify()
    SFCGAL-->>PostGIS: Return simplified geometry
    PostGIS-->>SQL: Convert back and return result
    SQL-->>User: Return simplified geometry
Loading

Poem

A function hops into the code,
CG_Simplify, in tidy mode!
With Z and M, it leaps so high,
Preserving shapes as it hops by.
Topology safe, or wild and free—
New tests and docs for all to see!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 366478b and 62de99f.

📒 Files selected for processing (11)
  • NEWS (1 hunks)
  • doc/html/images/Makefile.in (1 hunks)
  • doc/html/images/wkt/cg_simplify00.wkt (1 hunks)
  • doc/html/images/wkt/cg_simplify01.wkt (1 hunks)
  • doc/html/images/wkt/cg_simplify02.wkt (1 hunks)
  • doc/reference_sfcgal.xml (2 hunks)
  • sfcgal/lwgeom_sfcgal.c (2 hunks)
  • sfcgal/regress/simplify.sql (1 hunks)
  • sfcgal/regress/simplify_expected (1 hunks)
  • sfcgal/regress/tests.mk.in (1 hunks)
  • sfcgal/sfcgal.sql.in (1 hunks)
✅ Files skipped from review due to trivial changes (4)
  • NEWS
  • doc/html/images/Makefile.in
  • sfcgal/regress/tests.mk.in
  • sfcgal/regress/simplify.sql
🚧 Files skipped from review as they are similar to previous changes (7)
  • doc/html/images/wkt/cg_simplify02.wkt
  • sfcgal/regress/simplify_expected
  • doc/html/images/wkt/cg_simplify01.wkt
  • doc/html/images/wkt/cg_simplify00.wkt
  • sfcgal/sfcgal.sql.in
  • doc/reference_sfcgal.xml
  • sfcgal/lwgeom_sfcgal.c
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: CI (pg15-geos311-gdal35-proj90, coverage)
  • GitHub Check: Analyze (c-cpp)
  • GitHub Check: CI (pg17-geosmain-gdal39-proj94, coverage)
  • GitHub Check: macOS
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

♻️ Duplicate comments (1)
doc/html/images/wkt/cg_simplicity02.wkt (1)

1-1: Filename prefix mismatch duplicates earlier issue.
See the comment in cg_simplicity01.wkt regarding renaming cg_simplicity02.wkt → cg_simplify02.wkt.

🧹 Nitpick comments (4)
doc/reference_sfcgal.xml (4)

3577-3586: Align default parameter syntax with DocBook conventions.

Other optional parameters in this file embed the default value directly in the <parameter> tag (e.g. allow_holes = false) rather than using an <initializer> element. To maintain consistency, consider changing to:

<paramdef choice="opt">
  <type>boolean</type>
  <parameter>preserveTopology = false</parameter>
</paramdef>

3588-3604: Clarify terminology and grammar.

  • In the description of threshold, “in geometry unit” should be “in geometry units.”
  • Consider tightening the phrase “preserving the essential features of the geometry” to “preserving essential geometric features” to match the style of other entries.

3656-3698: Ensure <programlisting> tags are balanced and captions match.

The complex examples interleave <programlisting> and <informalfigure> blocks. Please verify that each <programlisting> is properly closed before its corresponding figure, and that captions refer to the correct image files (cg_simplify00.png, cg_simplify01.png, cg_simplify02.png). Indentation tweaks could improve readability.


3701-3707: Consider enhancing “See Also” cross-references.

You currently link to ST_Simplify and ST_SimplifyPreserveTopology. As this documents CG_Simplify, you might also cross-reference related CG_ functions or mention the SQL interface functions for 2D/3D simplification. However, the existing links are appropriate.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 637410f and 30c1eb1.

📒 Files selected for processing (11)
  • doc/html/images/Makefile.in (1 hunks)
  • doc/html/images/wkt/cg_simplicity00.wkt (1 hunks)
  • doc/html/images/wkt/cg_simplicity01.wkt (1 hunks)
  • doc/html/images/wkt/cg_simplicity02.wkt (1 hunks)
  • doc/reference_sfcgal.xml (2 hunks)
  • liblwgeom/lwgeom_sfcgal.c (1 hunks)
  • sfcgal/lwgeom_sfcgal.c (2 hunks)
  • sfcgal/regress/simplify.sql (1 hunks)
  • sfcgal/regress/simplify_expected (1 hunks)
  • sfcgal/regress/tests.mk.in (1 hunks)
  • sfcgal/sfcgal.sql.in (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
sfcgal/lwgeom_sfcgal.c (2)
sfcgal/lwgeom_sfcgal.h (3)
  • sfcgal_postgis_init (40-40)
  • POSTGIS2SFCGALGeometry (28-28)
  • SFCGALGeometry2POSTGIS (34-34)
liblwgeom/gserialized.c (1)
  • gserialized_get_srid (155-161)
liblwgeom/lwgeom_sfcgal.c (1)
liblwgeom/lwgeom_api.c (1)
  • getPoint4d_p (124-179)
⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: macOS
  • GitHub Check: 14.2-RELEASE
  • GitHub Check: CI (pg13-geos38-gdal31-proj71, tests)
  • GitHub Check: CI (pg17-geosmain-gdal39-proj94, coverage)
  • GitHub Check: CI (pg12-geos38-gdal30-proj611, tests)
  • GitHub Check: CI (latest, tests)
  • GitHub Check: CI (pg13-clang-geos39-gdal31-proj71, usan_clang)
  • GitHub Check: CI (pg15-clang-geos311-gdal35-proj90, usan_clang)
  • GitHub Check: CI (pg14-geos39-gdal33-proj71, tests)
  • GitHub Check: CI (pg15-geos311-gdal35-proj90, coverage)
  • GitHub Check: CI (pg16-geos312-gdal37-proj921, coverage)
  • GitHub Check: Analyze (c-cpp)
🔇 Additional comments (15)
doc/html/images/Makefile.in (1)

50-52: New simplification images added to GENERATED_IMAGES.
The entries for cg_simplify00.png, cg_simplify01.png, and cg_simplify02.png correctly integrate the new CG_Simplify visual examples into the build.

sfcgal/regress/tests.mk.in (1)

40-44: Conditionally include simplify.sql for SFCGAL ≥ 2.1.0.
This block mirrors the existing version checks and will ensure the new regression tests run only when the SFCGAL backend supports CG_Simplify. The version constant 20100 correctly represents 2.1.0 in this scheme.

sfcgal/sfcgal.sql.in (1)

598-603: SQL function definition looks good.

The new CG_Simplify function follows the standard pattern of SFCGAL function definitions, with proper implementation linking, parameter definition, and function attributes. The preserveTopology parameter defaulting to false aligns with standard simplification behavior while providing flexibility.

sfcgal/regress/simplify_expected (1)

1-2: Regression test expected output is correctly formatted.

The expected output for both simplification operations (with and without topology preservation) is properly defined, showing the same geometries but with different topology characteristics. Both outputs correctly maintain ZM dimension information from the input.

sfcgal/regress/simplify.sql (1)

1-2: Test cases comprehensive for core functionality.

Both test cases use the same complex 4D geometry collection with Z and M coordinates, properly testing the simplification with and without topology preservation. The tests provide good coverage for the function's key capabilities.

sfcgal/lwgeom_sfcgal.c (2)

80-80: Function prototype correctly added.

The sfcgal_simplify function is properly declared in the prototypes section, following the pattern of other SFCGAL functions.


1732-1767: Implementation is robust with proper version checking.

The function implementation:

  1. Properly checks for SFCGAL version 2.1.0+ compatibility
  2. Correctly handles parameter validation and conversion
  3. Follows the standard pattern of initialize → convert → process → convert back → cleanup
  4. Properly manages memory by deleting temporary geometries

The implementation preserves the original SRID of the input geometry when returning the simplified geometry. This is essential for maintaining spatial reference integrity.

liblwgeom/lwgeom_sfcgal.c (5)

239-262: Well-designed helper function for dimensional handling.

The function create_sfcgal_point_by_dimensions is a good abstraction that cleanly handles different dimension combinations (XY, XYZ, XYM, XYZM) with proper version checking. The careful handling of backward compatibility for SFCGAL versions before 1.5.0 is excellent.


267-285: Good use of POINT4D for handling all dimensions.

The refactored code properly extracts both Z and M dimensions from the point array using the appropriate flags. Using the getPoint4d_p function to retrieve the full dimensional information and delegating to the new helper function creates cleaner, more maintainable code.


286-298: Clean implementation for linestring point handling.

The linestring case is well implemented, iterating through all points and properly handling their dimensional information. This change ensures that M-values are preserved when converting from PostGIS to SFCGAL geometries.


299-328: Good version-specific triangle handling.

The triangle case correctly handles measured dimensions when SFCGAL version is 1.5.0 or higher, falling back to coordinate-specific methods for older versions or non-measured cases. This ensures proper preservation of M values while maintaining backward compatibility.


329-333: Corrected error message matches function name.

The error message in the default case has been correctly updated to reflect the function name ptarray_to_SFCGAL instead of the previous incorrect reference to ptarray_from_SFCGAL.

doc/reference_sfcgal.xml (3)

3571-3576: Check xml:id and naming consistency.

The <refentry xml:id="CG_Simplify"> and <refname>CG_Simplify</refname> align with the naming of other CG_ functions. Please ensure that the &M_support; entity used later is defined in the DocBook preamble so that the M-coordinate support macro resolves correctly.


3606-3628: Parameter descriptions are thorough.

The entries for geom, threshold, and preserveTopology clearly describe their purpose and defaults. Optionally, you may note that threshold must be non-negative, matching the C implementation’s validation.


3630-3636: Return Value section is concise and accurate.

It correctly states that Z and M values are preserved in the output, reflecting the implementation.

Comment thread doc/html/images/wkt/cg_simplicity01.wkt Outdated
@@ -0,0 +1 @@
GEOMETRYCOLLECTION(MULTIPOLYGON(((5.96 46.13,6.81 46.39,6.8 45.78,6.33 45.69,5.83 45.94,5.96 46.13))),MULTIPOLYGON(((6.33 45.69,6.8 45.78,7.14 45.26,5.62 45.61,5.83 45.94,6.33 45.69))))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Filename prefix mismatch: cg_simplicity01.wkt vs cg_simplify01.png.
The Makefile rule generates cg_simplify01.png from wkt/cg_simplify01.wkt, but the source WKT is named cg_simplicity01.wkt. Rename the file to cg_simplify01.wkt (and update references) so the generator can locate it.

🤖 Prompt for AI Agents (early access)
In doc/html/images/wkt/cg_simplicity01.wkt at line 1, the filename prefix does
not match the expected prefix used in the Makefile and related references.
Rename the file from cg_simplicity01.wkt to cg_simplify01.wkt and update any
references in the Makefile or code to use the new filename so the generator can
correctly locate and process the source WKT file.

Comment thread doc/html/images/wkt/cg_simplicity00.wkt Outdated
@@ -0,0 +1 @@
GeometryCollection(MULTIPOLYGON(((5.96 46.13,6.3 46.26,6.32 46.37,6.81 46.39,6.8 46.14,7.04 45.92,6.8 45.78,6.51 45.91,6.33 45.69,6.1 45.76,5.83 45.94,5.89 46.12,5.96 46.13))),MULTIPOLYGON(((6.33 45.69,6.51 45.91,6.8 45.78,7.18 45.41,7.14 45.26,6.63 45.11,6.26 45.13,6.12 45.44,5.91 45.39,5.62 45.61,5.83 45.94,6.1 45.76,6.33 45.69))))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Filename and WKT keyword casing inconsistencies.

  1. The file is named cg_simplicity00.wkt but the Makefile expects cg_simplify00.wkt.
  2. Inside the file, GeometryCollection is mixed-case, whereas other examples use GEOMETRYCOLLECTION.

Apply these fixes:

  1. Rename the file in the repository:
    git mv doc/html/images/wkt/cg_simplicity00.wkt doc/html/images/wkt/cg_simplify00.wkt
  2. Update the keyword casing in the file:
    -GeometryCollection(MULTIPOLYGON(...
    +GEOMETRYCOLLECTION(MULTIPOLYGON(...
🤖 Prompt for AI Agents (early access)
In doc/html/images/wkt/cg_simplicity00.wkt at line 1, rename the file to
cg_simplify00.wkt to match the Makefile expectation. Also, change the keyword
GeometryCollection to uppercase GEOMETRYCOLLECTION to maintain consistent WKT
keyword casing with other examples.

Comment thread doc/reference_sfcgal.xml Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (1)
doc/reference_sfcgal.xml (1)

3641-3654: 🛠️ Refactor suggestion

Explicitly cast geometry literals in examples
Examples that pass raw string literals for GEOMETRYCOLLECTION ZM(...) rely on implicit type inference. PostgreSQL may not infer the correct geometry type without an explicit cast. Update the two examples as follows:

-- Simplify two geometries preserving Z and M values, without topology
- SELECT ST_AsText(CG_Simplify('GEOMETRYCOLLECTION ZM(...)', 2, false));
+ SELECT ST_AsText(CG_Simplify('GEOMETRYCOLLECTION ZM(...)'::geometry, 2, false));

-- Simplify two geometries preserving Z and M values, with topology
- SELECT ST_AsText(CG_Simplify('GEOMETRYCOLLECTION ZM(...)', 2, true));
+ SELECT ST_AsText(CG_Simplify('GEOMETRYCOLLECTION ZM(...)'::geometry, 2, true));
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 30c1eb1 and a7b3e32.

📒 Files selected for processing (6)
  • doc/html/images/Makefile.in (1 hunks)
  • doc/html/images/wkt/cg_simplify00.wkt (1 hunks)
  • doc/html/images/wkt/cg_simplify01.wkt (1 hunks)
  • doc/html/images/wkt/cg_simplify02.wkt (1 hunks)
  • doc/reference_sfcgal.xml (2 hunks)
  • liblwgeom/lwgeom_sfcgal.c (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • doc/html/images/wkt/cg_simplify01.wkt
  • doc/html/images/wkt/cg_simplify02.wkt
  • doc/html/images/wkt/cg_simplify00.wkt
🚧 Files skipped from review as they are similar to previous changes (2)
  • doc/html/images/Makefile.in
  • liblwgeom/lwgeom_sfcgal.c
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: CI (pg13-geos38-gdal31-proj71, tests)
  • GitHub Check: CI (pg12-geos38-gdal30-proj611, tests)
  • GitHub Check: CI (pg13-clang-geos39-gdal31-proj71, usan_clang)
  • GitHub Check: CI (latest, tests)
  • GitHub Check: CI (pg15-geos311-gdal35-proj90, coverage)
  • GitHub Check: CI (pg15-clang-geos311-gdal35-proj90, usan_clang)
  • GitHub Check: CI (pg14-geos39-gdal33-proj71, tests)
  • GitHub Check: Analyze (c-cpp)
  • GitHub Check: macOS

Comment thread doc/reference_sfcgal.xml Resolved
Comment thread doc/reference_sfcgal.xml Resolved
@lbartoletti
lbartoletti marked this pull request as draft May 14, 2025 19:15

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
sfcgal/lwgeom_sfcgal.c (1)

1742-1742: Fix comment to match version check condition.

There's a mismatch between the conditional check and the comment. The condition checks for < 20100 but the comment mentions >= 21000.

-#else /* POSTGIS_SFCGAL_VERSION >= 21000 */
+#else /* POSTGIS_SFCGAL_VERSION >= 20100 */
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a7b3e32 and 4d339b9.

📒 Files selected for processing (11)
  • doc/html/images/Makefile.in (1 hunks)
  • doc/html/images/wkt/cg_simplify00.wkt (1 hunks)
  • doc/html/images/wkt/cg_simplify01.wkt (1 hunks)
  • doc/html/images/wkt/cg_simplify02.wkt (1 hunks)
  • doc/reference_sfcgal.xml (2 hunks)
  • liblwgeom/lwgeom_sfcgal.c (1 hunks)
  • sfcgal/lwgeom_sfcgal.c (2 hunks)
  • sfcgal/regress/simplify.sql (1 hunks)
  • sfcgal/regress/simplify_expected (1 hunks)
  • sfcgal/regress/tests.mk.in (1 hunks)
  • sfcgal/sfcgal.sql.in (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • sfcgal/regress/tests.mk.in
  • doc/html/images/Makefile.in
🚧 Files skipped from review as they are similar to previous changes (8)
  • doc/html/images/wkt/cg_simplify02.wkt
  • doc/html/images/wkt/cg_simplify01.wkt
  • sfcgal/regress/simplify_expected
  • doc/html/images/wkt/cg_simplify00.wkt
  • sfcgal/sfcgal.sql.in
  • sfcgal/regress/simplify.sql
  • doc/reference_sfcgal.xml
  • liblwgeom/lwgeom_sfcgal.c
🧰 Additional context used
🧬 Code Graph Analysis (1)
sfcgal/lwgeom_sfcgal.c (2)
sfcgal/lwgeom_sfcgal.h (3)
  • sfcgal_postgis_init (40-40)
  • POSTGIS2SFCGALGeometry (28-28)
  • SFCGALGeometry2POSTGIS (34-34)
liblwgeom/gserialized.c (1)
  • gserialized_get_srid (155-161)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: macOS
  • GitHub Check: Analyze (c-cpp)
  • GitHub Check: CI (latest, tests)
  • GitHub Check: CI (pg13-clang-geos39-gdal31-proj71, usan_clang)
  • GitHub Check: CI (pg13-geos38-gdal31-proj71, tests)
  • GitHub Check: CI (pg12-geos38-gdal30-proj611, tests)
  • GitHub Check: CI (pg15-clang-geos311-gdal35-proj90, usan_clang)
  • GitHub Check: CI (pg14-geos39-gdal33-proj71, tests)
🔇 Additional comments (6)
sfcgal/lwgeom_sfcgal.c (6)

80-80: Good function declaration placement.

This is a well-placed function declaration alongside other similar SFCGAL functions. Adding the function prototype in the appropriate location ensures consistent organization of the code.


1732-1742: Version checking aligned with requirements.

The function correctly checks for SFCGAL version 2.1.0 as specified in the PR objectives. This ensures that users are informed when trying to use this function with an incompatible SFCGAL version.


1743-1748: Good variable declarations and clear naming.

The variables are well-named and clearly indicate their purpose, maintaining consistency with the rest of the codebase. The function correctly declares variables for input/output geometries, threshold, topology preservation flag, and SRID.


1749-1758: Proper initialization and parameter extraction.

The function follows the established pattern for SFCGAL functions:

  1. Initializes the SFCGAL library
  2. Extracts input parameters
  3. Converts PostGIS geometry to SFCGAL geometry
  4. Frees the input geometry

This ensures consistent behavior and proper memory management.


1759-1764: Appropriate geometry processing and memory cleanup.

The function correctly:

  1. Calls the SFCGAL simplify function with appropriate parameters
  2. Frees the input SFCGAL geometry
  3. Converts the result back to PostGIS format
  4. Frees the SFCGAL result geometry

This ensures proper memory management and follows the established pattern in the codebase.


1765-1767: Function correctly returns the processed geometry.

The function properly returns the simplified geometry using the PostgreSQL function return mechanism, which is consistent with other functions in the file.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
liblwgeom/cunit/cu_sfcgal.c (1)

103-125: Consider enhancing test failure messages with test case index

While the error message formatting has been improved, consider adding the test case index to the error message to make it easier to identify which test case failed.

-			fprintf(stderr, "\nExp:\t%s\nObt:\t%s\n", expected_ewkt[i], out_ewkt);
+			fprintf(stderr, "\nTest case %zu failed:\nExp:\t%s\nObt:\t%s\n", i, expected_ewkt[i], out_ewkt);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4d339b9 and 606f411.

📒 Files selected for processing (1)
  • liblwgeom/cunit/cu_sfcgal.c (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: macOS
  • GitHub Check: CI (pg12-geos38-gdal30-proj611, tests)
  • GitHub Check: CI (pg14-geos39-gdal33-proj71, tests)
  • GitHub Check: CI (pg13-geos38-gdal31-proj71, tests)
  • GitHub Check: CI (latest, tests)
  • GitHub Check: CI (pg13-clang-geos39-gdal31-proj71, usan_clang)
  • GitHub Check: CI (pg15-clang-geos311-gdal35-proj90, usan_clang)
  • GitHub Check: Analyze (c-cpp)
🔇 Additional comments (3)
liblwgeom/cunit/cu_sfcgal.c (3)

44-63: Good addition of test cases for Z/M support

These new test cases comprehensively cover all geometry types with Z, M, and combined ZM dimensions, which is excellent for ensuring the proper handling of geometries with additional dimensions.


82-101: Appropriate expected outputs for Z/M test cases

The expected outputs correctly reflect how SFCGAL handles different dimension types:

  1. For ZM geometries, the dimension indicators are dropped in output type names
  2. For M-only geometries, the "M" suffix is preserved

This behavior is consistent across all geometry types and properly tests the dimensional handling in the SFCGAL backend.


120-120: Improved error message formatting

The change to tab-based formatting improves readability for test failure messages, making it easier to compare expected vs obtained values during debugging.

@lbartoletti
lbartoletti force-pushed the sfcgal_simplify branch 7 times, most recently from 5729dba to 366478b Compare May 15, 2025 06:13
@lbartoletti
lbartoletti marked this pull request as ready for review May 15, 2025 06:42
@lbartoletti

Copy link
Copy Markdown
Contributor Author

Merged

@lbartoletti
lbartoletti deleted the sfcgal_simplify branch October 3, 2025 08:00
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.

1 participant