Package madrona :: Package raster_stats :: Module views
[hide private]

Source Code for Module madrona.raster_stats.views

 1  # Create your views here. 
 2  from django.http import HttpResponse 
 3  from madrona.raster_stats.models import zonal_stats, RasterDataset, ZonalStatsCache 
 4  from django.core import serializers 
 5  from django.contrib.gis.geos import fromstr 
 6   
7 -def stats_for_geom(request, raster_name):
8 # Confirm that we have a valid polygon geometry 9 if 'geom_txt' in request.REQUEST: 10 geom_txt = str(request.REQUEST['geom_txt']) 11 else: 12 return HttpResponse("Must supply a geom_txt parameter", status=404) 13 14 try: 15 geom = fromstr(geom_txt) 16 except: 17 return HttpResponse("Must supply a parsable geom_txt parameter (wkt or json)", status=404) 18 19 # Confirm raster with pk exists 20 try: 21 raster = RasterDataset.objects.get(name=raster_name) 22 except: 23 return HttpResponse("No raster with pk of %s" % pk, status=404) 24 25 #TODO check if continuous 26 zonal = zonal_stats(geom, raster) 27 zonal.save() 28 zqs = ZonalStatsCache.objects.filter(pk=zonal.pk) 29 data = serializers.serialize("json", zqs, fields=('avg','min','max','median','mode','stdev','nulls','pixels','date_modified','raster')) 30 return HttpResponse(data, mimetype='application/json')
31
32 -def raster_list(request):
33 rasts = RasterDataset.objects.all() 34 data = serializers.serialize("json", rasts, fields=('name','type')) 35 return HttpResponse(data, mimetype='application/json')
36