Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] Make GeoJSON output valid by transforming to WGS84 #326

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

StefanBrand
Copy link

@StefanBrand StefanBrand commented Jan 24, 2025

Checklist

  • I have read the OpenWISP Contributing Guidelines.
  • I have manually tested the changes proposed in this pull request.
  • I have written new test cases for new code and/or updated existing tests for changes to existing code.
  • I have updated the documentation.

Reference to Existing Issue

Closes #188.

Description of Changes

If the database column has a SRID other than 4326 (WGS84), the geometry and---if configured---its bbox is transformed to 4326 to conform with the GeoJSON spec.

Questions

  • TBD: Default value of the transform parameter. Should it default to None to keep the current behaviour?
  • I think that currently the bbox of the feature would not be transformed because the extent is directly accessed. Maybe we need to move the functionality into get_attribute. -> out of scope
    if self.Meta.auto_bbox and geo_value:
    feature["bbox"] = geo_value.extent
    # otherwise it can be determined via another field
    elif self.Meta.bbox_geo_field:
    field = self.fields[self.Meta.bbox_geo_field]
    value = field.get_attribute(instance)
    feature["bbox"] = value.extent if hasattr(value, 'extent') else None
    processed_fields.add(self.Meta.bbox_geo_field)

auvipy
auvipy previously approved these changes Jan 28, 2025
@auvipy auvipy requested a review from nemesifier January 28, 2025 07:34
@StefanBrand
Copy link
Author

@auvipy thank you for your review. I have noted two questions of mine at the top. What are your thoughts on these?

@auvipy
Copy link
Collaborator

auvipy commented Jan 29, 2025

Answers:

  1. To keep BC, Keeping None would be better choice I believe.

  2. A new function / method might be better in this case, so we can give that a try

@StefanBrand
Copy link
Author

I've added tests for the bbox of the geometry (which is correctly transformed) and decided that the bbox of the Feature is out of scope.

README.rst Outdated
@@ -97,6 +97,10 @@ This field takes three optional arguments:
- ``auto_bbox``: If ``True``, the GeoJSON object will include
a `bounding box <https://datatracker.ietf.org/doc/html/rfc7946#section-5>`_,
which is the smallest possible rectangle enclosing the geometry.
- ``transform`` (defaults to ``4326``): If ``None`` (or the input geometry does not have
a SRID), the GeoJSON's coordinates will not be transformed. If any other `spatial
Copy link
Collaborator

Choose a reason for hiding this comment

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

"If any other" this line is not clear, can you please rephrase it?

Copy link
Author

Choose a reason for hiding this comment

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

I have rephrased these docs after setting the default value to None. I hope it is easier to understand now. What do you think?

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.

Invalid GeoJSON output.
2 participants