-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
64 lines (47 loc) · 1.51 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from django.shortcuts import render
from .models import Area, Week
from django.shortcuts import redirect
from osgeo import gdal
from django.http import HttpResponse
import tempfile
import rasterio
# Create your views here.
def index(request):
data = {
"areas": Area.objects.all()
}
return render(request, "index.html", data)
def area(request, area):
area = Area.objects.get(id=area)
data = {
"weeks": Week.objects.filter(area=area),
"area": area
}
return render(request, "area.html", data)
def week(request, area, week):
data = {
"week": Week.objects.get(id=week),
"area": Area.objects.get(id=area)
}
return render(request, "colors.html", data)
def color(request, area, week, color):
return redirect(getattr(Week.objects.get(id=week), color).url)
def color_png(request, area, week, color):
color_field = getattr(Week.objects.get(id=week), color)
fn = tempfile.mktemp(prefix=color, suffix=".png")
print(color_field.file)
with rasterio.open(color_field.file) as colorfile:
data = colorfile.read().astype(float)
print(data[0][0])
data = (data-(-1))*((255)/(2))
print(data.min())
print(data.max())
print("#######", fn, color_field.file, "|")
#gdal.Translate(
# fn,
# color_field.file,
# format="PNG"
#)
gdal.Translate(fn, str(color_field.file), format="PNG")
with open(fn, "rb") as f:
return HttpResponse(f.read(), content_type="image/png")