Skip to content

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

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

Merged
merged 7 commits into from
Jun 2, 2025

Conversation

StefanBrand
Copy link
Contributor

@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
Contributor 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
Contributor 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
Contributor 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ping @auvipy

Copy link
Collaborator

@auvipy auvipy left a comment

Choose a reason for hiding this comment

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

this looks good to me. but I want to wait for other maintainers to look into it. you might need to push again to make the CI green again

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

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

@StefanBrand can you please merge with the latest master and run openwisp-qa-format again?

Make sure to have the dev version of openwisp-utils[qa] (uninstall and resinstall if necessary to update the openwisp-qa-format script), eg:

pip uninstall openwisp-utils
pip install "openwisp-utils[qa] @ https://github.com/openwisp/openwisp-utils/tarball/1.2"

For the rest it looks good to me as well, thank you @StefanBrand @auvipy!

Copy link
Collaborator

@auvipy auvipy left a comment

Choose a reason for hiding this comment

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

it seems we also need to fix the merge conflicts as well!

@nemesifier
Copy link
Member

The conflicts are likely due to the recent black formatter changes, running openwisp-qa-format should fix it.

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

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

I fixed the conflcits and qa issues, I am merging, thanks everyone who contributed to this @StefanBrand @auvipy 👏

@nemesifier nemesifier merged commit 1ad8e0c into openwisp:master Jun 2, 2025
20 checks passed
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.
3 participants