{{{
from django.db.models import Sum
from django.contrib.gis.db.models.functions import Area, Intersection
Country.objects.annotate(intersum=Sum(Area(Intersection('mpoly', geom))))
}}}
I tracked this down to the `from_db_value` function in the GeometryField
class here:
https://github.com/django/django/blob/master/django/contrib/gis/db/models/fields.py#L259
The problem seems to be that the `Area` function returns a float, but the
field is expecting a value that can be converted to a Geometry.
I'll open a pull request with a regression test and a proposed solution,
basically checking if the value is a float or int.
--
Ticket URL: <https://code.djangoproject.com/ticket/26112>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Old description:
> There is an error when trying to compute a regular aggregate value from
> a GIS aggregate output. To take an example from the GIS geoapp tests, the
> following query fails.
>
> {{{
> from django.db.models import Sum
> from django.contrib.gis.db.models.functions import Area, Intersection
>
> Country.objects.annotate(intersum=Sum(Area(Intersection('mpoly', geom))))
> }}}
>
> I tracked this down to the `from_db_value` function in the GeometryField
> class here:
>
> https://github.com/django/django/blob/master/django/contrib/gis/db/models/fields.py#L259
>
> The problem seems to be that the `Area` function returns a float, but the
> field is expecting a value that can be converted to a Geometry.
>
> I'll open a pull request with a regression test and a proposed solution,
> basically checking if the value is a float or int.
New description:
There is an error when trying to compute a regular aggregate value from a
GIS aggregate output. To take an example from the GIS geoapp tests, the
following query fails.
{{{
from django.db.models import Sum
from django.contrib.gis.db.models.functions import Area, Intersection
Country.objects.annotate(intersum=Sum(Area(Intersection('mpoly', geom))))
}}}
I tracked this down to the `from_db_value` function in the GeometryField
class here:
https://github.com/django/django/blob/master/django/contrib/gis/db/models/fields.py#L259
The problem seems to be that the `Sum` function returns a float, but the
field is expecting a value that can be converted to a Geometry.
I'll open a pull request with a regression test and a proposed solution,
basically checking if the value is a float or int.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/26112#comment:1>
Old description:
> There is an error when trying to compute a regular aggregate value from
> a GIS aggregate output. To take an example from the GIS geoapp tests, the
> following query fails.
>
> {{{
> from django.db.models import Sum
> from django.contrib.gis.db.models.functions import Area, Intersection
>
> Country.objects.annotate(intersum=Sum(Area(Intersection('mpoly', geom))))
> }}}
>
> I tracked this down to the `from_db_value` function in the GeometryField
> class here:
>
> https://github.com/django/django/blob/master/django/contrib/gis/db/models/fields.py#L259
>
> The problem seems to be that the `Sum` function returns a float, but the
> field is expecting a value that can be converted to a Geometry.
>
> I'll open a pull request with a regression test and a proposed solution,
> basically checking if the value is a float or int.
New description:
There is an error when trying to compute a regular aggregate value from a
GIS Area aggregate output. To take an example from the GIS geoapp tests,
the following query fails.
{{{
from django.db.models import Sum
from django.contrib.gis.db.models.functions import Area
Country.objects.annotate(areasum=Sum(Area('mpoly')))
}}}
I tracked this down to the `from_db_value` function in the GeometryField
class here:
https://github.com/django/django/blob/master/django/contrib/gis/db/models/fields.py#L259
The problem seems to be that the `Area` function returns a float, but the
field is expecting a value that can be converted to a Geometry.
I'll open a pull request with a regression test and a proposed solution.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/26112#comment:2>
* stage: Unreviewed => Accepted
Comment:
[https://github.com/django/django/pull/6004 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/26112#comment:3>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/26112#comment:4>
* needs_better_patch: 1 => 0
* version: 1.9 => master
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/26112#comment:5>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"a08d2463d2674b95f5a995f77cd9596168378a4f" a08d2463]:
{{{
#!CommitTicketReference repository=""
revision="a08d2463d2674b95f5a995f77cd9596168378a4f"
Fixed #26112 -- Error when computing aggregate of GIS areas.
Thanks Simon Charette and Claude Paroz for the reviews.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26112#comment:6>
* status: closed => new
* has_patch: 1 => 0
* resolution: fixed =>
* stage: Ready for checkin => Accepted
Comment:
The new test fails on Oracle:
{{{
File "/home/tim/code/django/tests/gis_tests/geoapp/test_functions.py",
line 243, in test_area_with_regular_aggregate
for c in qs:
...
ORA-22901: cannot compare VARRAY or LOB attributes of an object type
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26112#comment:7>
Comment (by shaib):
Oracle-fixing [https://github.com/django/django/pull/6041 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/26112#comment:8>
* has_patch: 0 => 1
Comment:
When I submitted the PR I was doubtful about it being the right solution,
but now I've convinced myself that it is.
--
Ticket URL: <https://code.djangoproject.com/ticket/26112#comment:9>
Comment (by Tim Graham <timograham@…>):
In [changeset:"bb51dc902dc760b6fd03b860335fd99f47e2e13d" bb51dc9]:
{{{
#!CommitTicketReference repository=""
revision="bb51dc902dc760b6fd03b860335fd99f47e2e13d"
Refs #26112 -- Fixed aggregate GIS test on Oracle.
Made sure the test doesn't try to aggregate over MultiPolygonField and
made
AreaField turn decimals into floats on the way from the DB.
Thanks Daniel Wiesmann, Jani Tiainen, and Tim Graham for review and
discussion.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26112#comment:10>
* status: new => closed
* resolution: => fixed
--
Ticket URL: <https://code.djangoproject.com/ticket/26112#comment:11>