postgis-workshops icon indicating copy to clipboard operation
postgis-workshops copied to clipboard

[Potential bug?] Update spatial_relationships_exercises.rst

Open ThomasPrioul opened this issue 9 months ago • 3 comments

Using a subquery instead of a string MULTILINESTRING or LINESTRING gives different and more accurate results. The exercise asks for the following question : What streets does Atlantic Commons join with?

There seems to be a difference between raw geometry format and back/forth serialization! Maybe it is related to the SRID aspects ?

Using multilinestring or subquery : image

Using suggested parsed linestring : image

Also, for completion purpose, shouldn't the question be answered excluding the street itself (atlantic commons) ?

ThomasPrioul avatar Feb 17 '25 13:02 ThomasPrioul

šŸ“ Walkthrough

Walkthrough

The changes update the SQL query in the spatial_relationships_exercises.rst document. The hardcoded LINESTRING geometry for 'Atlantic Commons' has been replaced with a subquery that dynamically retrieves the geometry from the nyc_streets table. Additionally, the explanatory note regarding the use of LINESTRING over MULTILINESTRING, and the rounding effects on the ST_Touches() predicate, remains intact.

Changes

File Change Summary
postgis-intro/.../spatial_relationships_exercises.rst Updated SQL query: replaced hardcoded LINESTRING geometry with a subquery selecting 'Atlantic Commons' geometry; retained note explaining the geometry type and rounding.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant Q as Query Engine
    participant DB as nyc_streets Table

    U->>Q: Execute spatial_relationship query
    Q->>DB: Run subquery to fetch 'Atlantic Commons' geometry
    DB-->>Q: Return geometry data
    Q->>Q: Substitute geometry in the main query
    Q-->>U: Return query results based on dynamic geometry

Poem

I’m a rabbit dancing through lines of code,
Hopping over hardcoded paths now old.
Dynamic queries sing a brand new tune,
As geometry leaps beneath the moon.
A happy hop for every refined node!
šŸ‡šŸ¾


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

ā¤ļø 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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[bot] avatar Feb 17 '25 13:02 coderabbitai[bot]

Using a subquery instead of a string MULTILINESTRING or LINESTRING gives different and more accurate results. The exercise asks for the following question : What streets does Atlantic Commons join with?

There seems to be a difference between raw geometry format and back/forth serialization! Maybe it is related to the SRID aspects ?

I think it's different because the ST_AsText is a rounded geometry, not the actual geometry, so it's no surprise they are different. SRID wouldn't have a play here since everything is in the same SRID and no transform going on here as I recall.

Also, for completion purpose, shouldn't the question be answered excluding the street itself (atlantic commons) ? Yes I would say so, but it would complicate the query a tiny bit so deviates a bit from the intent of the exercise with introducing too much reality.

As to replacing the ST_AsText with a sub query, I do kinda like that more than including the ST_AsText of prior exercise.

@pramsey @dr-jts what are you feelings about the suggested change?

robe2 avatar Mar 02 '25 20:03 robe2

I agree with both suggested changes (i.e. use actual data record in filter, and exclude that record from the result), for the following reasons:

  • It produces a correct result
  • It corresponds more closely to a real world query (which are much more likely to refer to other data items than contain explicit data)

The previous example query (What neighborhood and borough is Atlantic Commons in?) could also be improved in the same way.

dr-jts avatar Mar 02 '25 22:03 dr-jts