postgis-workshops
postgis-workshops copied to clipboard
[Potential bug?] Update spatial_relationships_exercises.rst
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 :
Using suggested parsed linestring :
Also, for completion purpose, shouldn't the question be answered excluding the street itself (atlantic commons) ?
š 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?
šŖ§ 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
@coderabbitaiin 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
@coderabbitaiin 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 pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR. (Beta)@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile 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.
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?
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.