104 lines
2.7 KiB
Python
104 lines
2.7 KiB
Python
import datetime
|
|
from urllib.parse import unquote
|
|
|
|
import httplib2
|
|
from django.db.models import Count
|
|
from django.http import JsonResponse, HttpResponse, HttpResponseNotAllowed
|
|
from django.shortcuts import render
|
|
from .util.utils import *
|
|
from .radar.process import *
|
|
from .spi.process import *
|
|
|
|
PROXY_FORMAT = 'http://%s:%d%s' % ('210.77.68.250', 8080, '%s')
|
|
|
|
data_base_path = '/home/g214/data_from_chenhao/data_analyse/'
|
|
|
|
|
|
## 冰雹相关
|
|
|
|
def hailstones(request):
|
|
# csv_path = '../data/radar/radar-bj.csv'
|
|
csv_path = request.GET['path']
|
|
hailstones_data = get_hailstones(csv_path)
|
|
return JsonResponse(hailstones_data)
|
|
|
|
|
|
def get_type_path(type):
|
|
if type == '棉花':
|
|
type = 'cotton'
|
|
elif type == '玉米':
|
|
type = 'corn'
|
|
elif type == '小麦':
|
|
type = 'wheat'
|
|
elif type == '人口':
|
|
type = 'population'
|
|
elif type == 'GDP':
|
|
type = 'gdp'
|
|
return data_base_path + 'raster/%s_3857.tif' % type
|
|
|
|
|
|
def calc_hailstones_impact(request):
|
|
type = request.GET['type']
|
|
county = request.GET['county']
|
|
calc_dem = request.GET['dem']
|
|
|
|
hailstones_data = get_hailstones(csv_path)
|
|
if county:
|
|
hailstones_data = intersection_xzqh(hailstones_data)
|
|
|
|
tif_path = get_type_path(type)
|
|
if not calc_dem:
|
|
sum = agg_raster_by_gdf_value(tif_path, hailstones_data)
|
|
else:
|
|
sum = agg_raster_by_gdf_area_and_aspect_slope(tif_path, get_type_path('aspect'), get_type_path('slope'),
|
|
hailstones_data)
|
|
res = {}
|
|
res.sum = sum
|
|
res.geo = hailstones_data
|
|
return JsonResponse(res)
|
|
|
|
|
|
def prevent_hailstones_data():
|
|
prevent_data = read_xls('/home/g214/data_from_chenhao/data_analyse/fbd/fbd.xlsx')
|
|
return get_buffer_data(prevent_data, dis=10000)
|
|
|
|
|
|
def prevent_hailstones(request):
|
|
prevent_data = prevent_hailstones_data()
|
|
return JsonResponse(prevent_data)
|
|
|
|
|
|
def calc_prevent_impact(request):
|
|
csv_path = request.GET['path']
|
|
|
|
prevent_data = prevent_hailstones_data()
|
|
|
|
hailstones_data = get_hailstones(csv_path)
|
|
prevent_intersection_disater_data = intersection(prevent_data, hailstones_data)
|
|
print(prevent_intersection_disater_data)
|
|
agg = agg_gdf_by_gdf_area(fbd_data_buffer, prevent_intersection_disater_data)
|
|
# print(res) # 单个点的面积
|
|
# print(res.sum()) # 总面积
|
|
res = {}
|
|
res.agg = agg
|
|
res.sum = res.sum()
|
|
return JsonResponse(res)
|
|
|
|
|
|
## SPI 相关
|
|
def calc_spi_diaster(request):
|
|
spi_type = request.GET['spi_type'] # spi.spei
|
|
county = request.GET['county']
|
|
type = request.GET['type']
|
|
|
|
station_buffer = get_station_polygon()
|
|
spi_gdf = get_spi_dataframe(station_buffer, '')
|
|
|
|
spi_disaster = get_disaster_gdf(spi_gdf, spi_type)
|
|
|
|
if county:
|
|
spi_disaster = intersection_xzqh(spi_disaster)
|
|
|
|
res_spi = agg_raster_by_gdf_value(get_type_path(type), spi_disaster)
|
|
return JsonResponse(res_spi)
|