5/19/2011

ST_Simplify(provided by PostGIS) and GeoDjango

ST_Simplify function is provided by PostGIS.
It is used to simplify the geometry(eg. LINESTRING or POLYGON).
It use `simplify` method of GEOSGeometry class.
Django version is 1.3.
>>> line_string.simplify?
Type:           instancemethod
Base Class:     <type 'instancemethod'>
String Form:    <bound method LineString.simplify of <LineString object at 0xa4ed5f0>>
Namespace:      Interactive
File:           /usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/contrib/gis/geos/geometry.py
Definition:     line_string.simplify(self, tolerance=0.0, preserve_topology=False)
...
>>> line_string
<LineString object at 0xa4ed5f0>
>>> len(line_string)
4367
>>> line_string[:3]
[(138.67654300000001, 35.492500999999997, 944.62300000000005), (138.676545, 35.4925, 944.62300000000005), (138.676546, 35.492499000000002, 944.63)]
>>> simplified = line_string.simplify(0.001)
>>> len(simplified)
90
>>> simplified2 = line_string.simplify(0.001, True)
>>> len(simplified2)
2458

1/27/2011

Django session key changes on every request?

Django version is 1.2.4.
views.py
from django.http import HttpResponse
from random import choice

def index(request):
    x = choice([0, 1, 2])
    if x == 0:
        request.session['a'] = 1
    elif x == 1:
        request.session.flush()
    return HttpResponse(request.session.session_key + ' ' + str(request.session.keys()) + ' ' + str(x), content_type='text/plain')
  • session.clear() method doesn't change session key.
  • The session key was changed when call the session.flush() method. (eg. logout())
  • If session isn't used in request, session key was changed on every request.

ref:

1/26/2011

First entry

Syntax highlighting

from django.http import HttpResponse

def index(request):
    return HttpResponse('OK')