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

Fixed #34882 -- Fixed no options in AsGeoJSON() for geometries in non-default CRS. #17320

Merged
merged 2 commits into from
Oct 6, 2023

Conversation

3nids
Copy link
Contributor

@3nids 3nids commented Sep 29, 2023

When calling AssGeoJSON, if bbox and crs are both false, then options = 0, there fore not added to the expression.

In Postgis, with geometries, the default is not 0 but 8, meaning the CRS is returned, not respecting the original call arguments.

fixes #34882 https://code.djangoproject.com/ticket/34882#ticket

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Hello! Thank you for your contribution 💪

As it's your first contribution be sure to check out the patch review checklist.

If you're fixing a ticket from Trac make sure to set the "Has patch" flag and include a link to this PR in the ticket!

If you have any design or process questions then you can ask in the Django forum.

Welcome aboard ⛵️!

Copy link
Member

@felixxm felixxm left a comment

Choose a reason for hiding this comment

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

@3nids Thanks 👍 Please add a regression test.

@felixxm
Copy link
Member

felixxm commented Oct 3, 2023

@3nids Do you have time to keep working on this?

@3nids
Copy link
Contributor Author

3nids commented Oct 5, 2023

I'm a rookie in the code, but I can give it a shot. Could you point me to a similar case in the tests?

@felixxm
Copy link
Member

felixxm commented Oct 5, 2023

We could add a test for geometry with non-default crs and check an expected JSON format, e.g.

diff --git a/tests/gis_tests/geoapp/test_functions.py b/tests/gis_tests/geoapp/test_functions.py
index e9e2a5dcae..91441bf90c 100644
--- a/tests/gis_tests/geoapp/test_functions.py
+++ b/tests/gis_tests/geoapp/test_functions.py
@@ -11,7 +11,7 @@ from django.db.models import IntegerField, Sum, Value
 from django.test import TestCase, skipUnlessDBFeature
 
 from ..utils import FuncTestMixin
-from .models import City, Country, CountryWebMercator, State, Track
+from .models import City, Country, CountryWebMercator, ManyPointModel, State, Track
 
 
 class GISFunctionsTests(FuncTestMixin, TestCase):
@@ -119,6 +119,25 @@ class GISFunctionsTests(FuncTestMixin, TestCase):
                 chicago_json,
             )
 
+    @skipUnlessDBFeature("has_AsGeoJSON_function")
+    def test_asgeojson_option_0(self):
+        p1 = Point(1, 1, srid=4326)
+        p2 = Point(2, 2, srid=4326)
+        obj = ManyPointModel.objects.create(
+            point1=p1,
+            point2=p2,
+            point3=p2.transform(3857, clone=True),
+        )
+        self.assertJSONEqual(
+            ManyPointModel.objects.annotate(geojson=functions.AsGeoJSON("point3"))
+            .get(pk=obj.pk)
+            .geojson,
+            # GeoJSON without CRS.
+            json.loads(
+                '{"type":"Point","coordinates":[222638.98158655,222684.20850554]}'
+            ),
+        )
+
     @skipUnlessDBFeature("has_AsGML_function")
     def test_asgml(self):
         # Should throw a TypeError when trying to obtain GML from a

@felixxm felixxm changed the title fix Options are not respected Fixed #34882 -- Fixed no options in AsGeoJSON() for geometries in non-default CRS. Oct 5, 2023
@felixxm
Copy link
Member

felixxm commented Oct 5, 2023

@3nids Check out #17320 (comment).

@3nids
Copy link
Contributor Author

3nids commented Oct 5, 2023

@felixxm many thanks!!!!

@felixxm felixxm self-assigned this Oct 5, 2023
@felixxm felixxm merged commit 96e7a75 into django:main Oct 6, 2023
26 checks passed
@felixxm
Copy link
Member

felixxm commented Oct 6, 2023

@3nids Welcome aboard ⛵

@3nids 3nids deleted the patch-1 branch October 6, 2023 05:00
@3nids
Copy link
Contributor Author

3nids commented Oct 6, 2023

@felixxm small question, guessing that main is the current dev branch, is a backport to 4.2.x possible? how is this handled?
cheers!

@felixxm
Copy link
Member

felixxm commented Oct 6, 2023

guessing that main is the current dev branch, is a backport to 4.2.x possible?

No, it doesn't qualify for a backport to 4.2 based on our supported versions policy.

@3nids
Copy link
Contributor Author

3nids commented Oct 6, 2023

Oh, pity. Thanks for the feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants