geom update

6 views
Skip to first unread message

Adonis

unread,
Mar 4, 2009, 6:28:13 AM3/4/09
to geodjango
Hello,

I am trying to update my geometry column but i get a "can't adapt"
error.
After posting my data, i format them accordingly and insert them
succesfully into the geometry column like this:

-
geometria = GEOSGeometry('POLYGON((%s))' % coords)
insert_info = polygons(geometry=geometria)
insert_info.save()
-

when i post the new data i do exactly the same formating to get the
'geometria' variable and try to update my geometry column like this:

-
up = polygons.objects.filter(id=area_id).update(geometry=geometria)
-

but i am getting the "cant adapt" error.

Any suggestions?
Thanks in advance.

Ariel Mauricio Nunez Gomez

unread,
Mar 4, 2009, 8:10:00 AM3/4/09
to geod...@googlegroups.com
Adonis,

Can you try with:

up = polygons.objects.get(id=area_id).update(geometry=geometria)

Ariel.

Adonis

unread,
Mar 4, 2009, 8:53:40 AM3/4/09
to geodjango
Hi Ariel,

Thank you for your reply,
The answer is that it pops up a "'polygons' object has no attribute
'update'" error if i use 'get'.

regards,

On Mar 4, 1:10 pm, Ariel Mauricio Nunez Gomez
<ingenieroar...@gmail.com> wrote:
> Adonis,
>
> Can you try with:
>
> *up = polygons.objects.get(id=area_id).update(geometry=geometria)*
>
> Ariel.

Ariel Mauricio Nunez Gomez

unread,
Mar 4, 2009, 9:50:01 AM3/4/09
to geod...@googlegroups.com
Adonis, I am going to fir up my virtual machine to test that locally. In the meantime, have you tested the following simple approach?

up = polygons.objects.get(id=area_id)
up.geometry=geometria
up.save()

Adonis

unread,
Mar 4, 2009, 10:06:07 AM3/4/09
to geodjango
Yes, this works!
Many thanks Ariel!
Btw, did you happen to see the StringLine Post? I 've been having some
issues with storing Stringlines as well...
I know i am being greedy by asking but i really can't help it since u
have answered perfectly all my issues so far...!

Regards,

On Mar 4, 2:50 pm, Ariel Mauricio Nunez Gomez
<ingenieroar...@gmail.com> wrote:
> Adonis, I am going to fir up my virtual machine to test that locally. In the
> meantime, have you tested the following simple approach?
>
> up = polygons.objects.get(id=area_id)up.geometry=geometria
> up.save()
>

Ariel Mauricio Nunez Gomez

unread,
Mar 4, 2009, 10:32:43 AM3/4/09
to geod...@googlegroups.com
I still would like to know the cause of the original issue, can you do the following things for me:

1. Tell me which django version you are using?
2. Post the full traceback for the error.
3. Try with other field the same clause:
    up = polygons.objects.filter(id=area_id).update(other_field='test')

I guess I am not so familiar with update to know what's wrong yet.

Best,
Ariel.

Adonis

unread,
Mar 4, 2009, 11:44:16 AM3/4/09
to geodjango
1. I am using django 1.0.2.
3. update works fine if i change a field that is not geometry related.
I successfully altered the FK with update like this:
-
up = polygons.objects.filter(id=area_id).update(polyuser=16)
-

2.

Traceback:
File "/var/lib/python-support/python2.5/django/core/handlers/base.py"
in get_response
86. response = callback(request, *callback_args,
**callback_kwargs)
File "/var/lib/python-support/python2.5/django/contrib/auth/
decorators.py" in __call__
67. return self.view_func(request, *args, **kwargs)
File "/home/antonios/orchid_demo/../orchid_demo/appname/views.py" in
polystore
297. up = polygons.objects.filter(id=area_id).update
(geometry=geometria)
File "/var/lib/python-support/python2.5/django/db/models/query.py" in
update
417. rows = query.execute_sql(None)
File "/var/lib/python-support/python2.5/django/db/models/sql/
subqueries.py" in execute_sql
117. cursor = super(UpdateQuery, self).execute_sql
(result_type)
File "/var/lib/python-support/python2.5/django/db/models/sql/query.py"
in execute_sql
1734. cursor.execute(sql, params)
File "/var/lib/python-support/python2.5/django/db/backends/util.py" in
execute
19. return self.cursor.execute(sql, params)

Exception Type: ProgrammingError at /appname/polystore/
Exception Value: can't adapt

I hope this helps! It is the least i can do for you.
Regards,



On Mar 4, 3:32 pm, Ariel Mauricio Nunez Gomez
<ingenieroar...@gmail.com> wrote:
> I still would like to know the cause of the original issue, can you do the
> following things for me:
> 1. Tell me which django version you are using?2. Post the full traceback for
> the error.
> 3. Try with other field the same clause:
>     up = polygons.objects.filter(id=area_id).update(other_field='test')
>
> I guess I am not so familiar with update to know what's wrong yet.
>
> Best,
> Ariel.
>

Justin Bronn

unread,
Mar 4, 2009, 11:51:46 AM3/4/09
to geod...@googlegroups.com
Adonis,

I think you've stumbled upon a bug. For now, the solution is to not use
`.update()` and instead use the `.save()` workaround that Ariel
suggested. While `update` should work for non-geo fields, it is indeed
broken for geographic fields.

I've reproduced the error myself using the `WorldBorders` application
from the tutorial. The ticket is available at:

http://code.djangoproject.com/ticket/10411

Regards,
-Justin

Ariel Mauricio Nunez Gomez

unread,
Mar 4, 2009, 12:35:11 PM3/4/09
to geod...@googlegroups.com
Justin,

Excellent timing!

Ariel.
Reply all
Reply to author
Forward
0 new messages