This commit is contained in:
Sanj 2011-08-29 05:52:27 +05:30
parent 3a9ebfb9dd
commit a6334a26d1
2 changed files with 22 additions and 2 deletions

View File

@ -1,6 +1,10 @@
from django.db import connection
from django.contrib.gis.db import models
from django.contrib.gis.geos import Polygon
try:
import json
except:
import simplejson as json
# Create your models here.
@ -53,6 +57,18 @@ class Feature(models.Model):
return "%s: %s" % (self.feature_type.code, self.feature_type.name,)
feature_type_name.short_description = "Feature Type"
def get_geojson(self):
geom = json.loads(self.geojson)
properties = {
'id': self.id,
'preferred_name': self.preferred_name
}
return {
'type': 'Feature',
'properties': properties,
'geometry': geom
}
def time_start(self):
tf = self.time_frame
if tf is not None:

View File

@ -17,8 +17,12 @@ def search_json(request):
bs = bbox.split(",")
bs_param = (float(bs[0]), float(bs[1]), float(bs[2]), float(bs[3]),)
features = Feature.search.overlaps(bs_param, text=search_term, srid=3785)
d = {'c': features.count()}
features_qset = Feature.search.overlaps(bs_param, text=search_term, srid=3785)
features = [f.get_geojson() for f in features_qset]
d = {
'type': 'FeatureCollection',
'features': features
}
return render_to_json_response(d)
def search_related(request):