Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
b66dd01af2
|
@ -3,3 +3,4 @@ db.sqlite3
|
||||||
drought/local_settings.py
|
drought/local_settings.py
|
||||||
static/media/
|
static/media/
|
||||||
*/migrations
|
*/migrations
|
||||||
|
__pycache__/
|
|
@ -1,14 +1,8 @@
|
||||||
from django.forms import forms
|
from django.forms import forms
|
||||||
|
|
||||||
from dashboard.models import Country, Spi, Hydro, Landuse, Finance, Popu, Crop, Admdiv
|
from dashboard.models import Spi, Hydro, Landuse, Finance
|
||||||
|
|
||||||
|
|
||||||
class CountryForm(forms.Model):
|
|
||||||
class Meta:
|
|
||||||
model = Country
|
|
||||||
fields = ['name', 'parent_name', 'level', 'datetime', 'area', 'arable_land_area', 'population',
|
|
||||||
'agricultural_population', 'gross_national_product', 'total_agricultural_output',
|
|
||||||
'arable_land_per_capita']
|
|
||||||
|
|
||||||
|
|
||||||
class SpiForm(forms.Model):
|
class SpiForm(forms.Model):
|
||||||
|
@ -38,19 +32,3 @@ class FinanceForm(forms.Model):
|
||||||
'arable_land_occupancy_tax', 'deed_tax', 'tobacco_tax', 'non_tax_revenue']
|
'arable_land_occupancy_tax', 'deed_tax', 'tobacco_tax', 'non_tax_revenue']
|
||||||
|
|
||||||
|
|
||||||
class PopuForm(forms.Model):
|
|
||||||
class Meta:
|
|
||||||
model = Popu
|
|
||||||
fields = ['region', 'date', 'permanent_population', 'households', 'census_register_population', 'male', 'female_sex','birth_rate','mortality','growth_rate','urbanization_rate']
|
|
||||||
|
|
||||||
|
|
||||||
class CropForm(forms.Model):
|
|
||||||
class Meta:
|
|
||||||
model = Crop
|
|
||||||
fields = ['county_area', 'date', 'seeded_area', 'growth_rate1', 'yield1', 'growth_rate2', 'seeded_area','growth_rate3','yield2','growth_rate4']
|
|
||||||
|
|
||||||
|
|
||||||
class AdmdivForm(forms.Model):
|
|
||||||
class Meta:
|
|
||||||
model = Admdiv
|
|
||||||
fields = ['county_area', 'date', 'government', 'villager_committee', 'street_office', 'residents_committee', 'land_area','proportion']
|
|
|
@ -24,7 +24,6 @@
|
||||||
<!-- Custom styles for this template -->
|
<!-- Custom styles for this template -->
|
||||||
<link href="{% static 'dashboard/css/dashboard.css' %}" rel="stylesheet">
|
<link href="{% static 'dashboard/css/dashboard.css' %}" rel="stylesheet">
|
||||||
<link href="{% static 'dashboard/css/chart.css' %}" rel="stylesheet">
|
<link href="{% static 'dashboard/css/chart.css' %}" rel="stylesheet">
|
||||||
<link href="{% static 'predict/css/ghyc.css' %}" rel="stylesheet">
|
|
||||||
|
|
||||||
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
|
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
|
||||||
<!--[if lt IE 9]>
|
<!--[if lt IE 9]>
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<li class="nav-header">
|
<li class="nav-header">
|
||||||
<div class="profile-element">
|
<div class="profile-element">
|
||||||
<img alt="image" class="img-circle" src="{% static 'dashboard/img/bjwl.png' %}">
|
<img alt="image" class="img-circle" src="{% static 'dashboard/img/bjwl.png' %}">
|
||||||
<span class="font-bold m-t-xs">
|
<span class="font-bold m-t-xs" style="color: white">
|
||||||
{{ request.user.username }}
|
{{ request.user.username }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
@ -67,21 +67,21 @@
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li {% if url_name|startswith:'predict' %}class=""{% endif %}>
|
<li {% if url_name|startswith:'disaster' %}class="active"{% endif %}>
|
||||||
<a href="#">
|
<a href="#">
|
||||||
<i class="fa fa-th-large"></i>
|
<i class="fa fa-th-large"></i>
|
||||||
<span class="nav-label">灾害预测</span>
|
<span class="nav-label">灾害预测</span>
|
||||||
<span class="fa arrow"></span>
|
<span class="fa arrow"></span>
|
||||||
</a>
|
</a>
|
||||||
<ul class="nav nav-second-level collapse">
|
<ul class="nav nav-second-level collapse">
|
||||||
<li {% if url_name == 'predict' %}class="active"{% endif %}>
|
<li {% if url_name == 'disaster-index' %}class="active"{% endif %}>
|
||||||
<a href="{% url 'ghyc' %}">干旱预测</a>
|
<a href="{% url 'disaster-index' %}">干旱预测</a>
|
||||||
</li>
|
</li>
|
||||||
<li {% if url_name == '' %}class="active"{% endif %}>
|
<li {% if url_name == '' %}class="active"{% endif %}>
|
||||||
<a href="#">暴雨风险预测</a>
|
<a href="#">暴雨风险预测</a>
|
||||||
</li>
|
</li>
|
||||||
<li {% if url_name == '' %}class="active"{% endif %}>
|
<li {% if url_name == 'disaster-hail' %}class="active"{% endif %}>
|
||||||
<a href="#">冰雹风险预测</a>
|
<a href="{% url 'disaster-hail' %}">冰雹风险预测</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
@ -102,12 +102,12 @@
|
||||||
<li {% if url_name == 'policy-timeline4' %}class="active"{% endif %}>
|
<li {% if url_name == 'policy-timeline4' %}class="active"{% endif %}>
|
||||||
<a href="{% url 'policy-timeline4' %}">旱情空间分布</a>
|
<a href="{% url 'policy-timeline4' %}">旱情空间分布</a>
|
||||||
</li>
|
</li>
|
||||||
<li {% if url_name == 'policy-timeline4' %}class="active"{% endif %}>
|
<li {% if url_name == 'policy-timeline5' %}class="active"{% endif %}>
|
||||||
<a href="{% url 'policy-timeline4' %}">旱情分布动态变化</a>
|
<a href="{% url 'policy-timeline5' %}">旱情分布动态变化</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
{% if request.user.is_superuser == 1 %}
|
||||||
<li {% if url_name|startswith:'auth' %}class=""{% endif %}>
|
<li {% if url_name|startswith:'auth' %}class=""{% endif %}>
|
||||||
<a href="#">
|
<a href="#">
|
||||||
<i class="fa fa-th-large"></i>
|
<i class="fa fa-th-large"></i>
|
||||||
|
@ -115,11 +115,11 @@
|
||||||
<span class="fa arrow"></span>
|
<span class="fa arrow"></span>
|
||||||
</a>
|
</a>
|
||||||
<ul class="nav nav-second-level collapse">
|
<ul class="nav nav-second-level collapse">
|
||||||
<li {% if url_name == '' %}class="active"{% endif %}>
|
<li {% if url_name == 'http://{{ request.get_host }}/admin/auth/user/' %}class="active"{% endif %}>
|
||||||
<a href="#"> 用户管理</a>
|
<a href="http://{{ request.get_host }}/admin/auth/user/"> 用户管理</a>
|
||||||
</li>
|
</li>
|
||||||
<li {% if url_name == '' %}class="active"{% endif %}>
|
<li {% if url_name == 'http://{{ request.get_host }}/admin/auth/group/' %}class="active"{% endif %}>
|
||||||
<a href="#">权限管理</a>
|
<a href="http://{{ request.get_host }}/admin/auth/group/">权限管理</a>
|
||||||
</li>
|
</li>
|
||||||
<li {% if url_name == '' %}class="active"{% endif %}>
|
<li {% if url_name == '' %}class="active"{% endif %}>
|
||||||
<a href="#">服务器状态</a>
|
<a href="#">服务器状态</a>
|
||||||
|
@ -129,7 +129,9 @@
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
{% else %}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
<div class="ibox-content" style="padding: 0; position: relative;">
|
<div class="ibox-content" style="padding: 0; position: relative;">
|
||||||
<div id="map" style="width: 100%;height: 800px;">
|
<div id="map" style="width: 100%;height: 800px;">
|
||||||
<div class="legend">
|
<div class="legend">
|
||||||
|
<div style="background: white;text-align: center;color: black">GDP/亿</div>
|
||||||
<img src="http://210.77.68.250:8080/geoserver/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=baoji:bj_eco&STYLE=baoji:gdp">
|
<img src="http://210.77.68.250:8080/geoserver/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=baoji:bj_eco&STYLE=baoji:gdp">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
<div class="ibox-content" style="padding: 0; position: relative;">
|
<div class="ibox-content" style="padding: 0; position: relative;">
|
||||||
<div id="map" style="width: 100%;height: 800px;">
|
<div id="map" style="width: 100%;height: 800px;">
|
||||||
<div class="legend">
|
<div class="legend">
|
||||||
|
<div style="background: white;text-align: center;color: black">土地利用(万亩)</div>
|
||||||
<img src="http://210.77.68.250:8080/geoserver/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=baoji:bj_eco&STYLE=baoji:area_cult">
|
<img src="http://210.77.68.250:8080/geoserver/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=baoji:bj_eco&STYLE=baoji:area_cult">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
<div class="ibox-content" style="padding: 0; position: relative;">
|
<div class="ibox-content" style="padding: 0; position: relative;">
|
||||||
<div id="map" style="width: 100%;height: 800px;">
|
<div id="map" style="width: 100%;height: 800px;">
|
||||||
<div class="legend">
|
<div class="legend">
|
||||||
|
<div style="background: white;text-align: center;color: black">人口(万人)</div>
|
||||||
<img src="http://210.77.68.250:8080/geoserver/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=baoji:bj_eco&STYLE=baoji:pop">
|
<img src="http://210.77.68.250:8080/geoserver/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=baoji:bj_eco&STYLE=baoji:pop">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -27,8 +27,9 @@ def process_point(data):
|
||||||
if 'huibo' in data:
|
if 'huibo' in data:
|
||||||
data = data[['X', 'Y', 'huibo']]
|
data = data[['X', 'Y', 'huibo']]
|
||||||
geometry = [Point(xy) for xy in zip(data.X, data.Y)]
|
geometry = [Point(xy) for xy in zip(data.X, data.Y)]
|
||||||
data['geometry'] = geometry
|
geo_data = GeoDataFrame(data)
|
||||||
return GeoDataFrame(data)
|
geo_data.set_geometry(geometry, inplace=True)
|
||||||
|
return geo_data
|
||||||
|
|
||||||
|
|
||||||
def get_disaster_data(gdf):
|
def get_disaster_data(gdf):
|
||||||
|
@ -52,7 +53,8 @@ if __name__ == '__main__':
|
||||||
xls_path = '../data/radar/radar-20110815-20110825.xlsx'
|
xls_path = '../data/radar/radar-20110815-20110825.xlsx'
|
||||||
csv_path = '../data/radar/radar-bj.csv'
|
csv_path = '../data/radar/radar-bj.csv'
|
||||||
# shp_data = read_xls(xls_path)
|
# shp_data = read_xls(xls_path)
|
||||||
shp_data = read_csv(csv_path)
|
# shp_data = read_csv(csv_path)
|
||||||
|
# print(None.empty)
|
||||||
'''
|
'''
|
||||||
disaster_data = get_disaster_data(shp_data)
|
disaster_data = get_disaster_data(shp_data)
|
||||||
buffer_data = get_buffer_data(disaster_data, dis=1000)
|
buffer_data = get_buffer_data(disaster_data, dis=1000)
|
||||||
|
|
|
@ -88,13 +88,13 @@ def forecast_by_exe(path, scale, forecast_data, type='spi'):
|
||||||
def calc_spi_by_exe(path, scale, type='spi', forecast_data=None):
|
def calc_spi_by_exe(path, scale, type='spi', forecast_data=None):
|
||||||
import platform
|
import platform
|
||||||
if type == 'spi':
|
if type == 'spi':
|
||||||
if 'windows' in platform.platform():
|
if 'windows' in platform.platform().lower():
|
||||||
spi_path = 'spi.exe'
|
spi_path = DATA_BASE_PATH + 'spi.exe'
|
||||||
else:
|
else:
|
||||||
spi_path = DATA_BASE_PATH + 'exc/spi'
|
spi_path = DATA_BASE_PATH + 'exc/spi'
|
||||||
else:
|
else:
|
||||||
if 'windows' in platform.platform():
|
if 'windows' in platform.platform().lower():
|
||||||
spi_path = 'spei.exe'
|
spi_path = DATA_BASE_PATH + 'spei.exe'
|
||||||
else:
|
else:
|
||||||
spi_path = DATA_BASE_PATH + 'exc/spei'
|
spi_path = DATA_BASE_PATH + 'exc/spei'
|
||||||
input_path = DATA_BASE_PATH + "temp/input.csv"
|
input_path = DATA_BASE_PATH + "temp/input.csv"
|
||||||
|
@ -117,21 +117,23 @@ def get_spi_dataframe(station_polygon, newdata_path, month):
|
||||||
spi_list = []
|
spi_list = []
|
||||||
spei_list = []
|
spei_list = []
|
||||||
|
|
||||||
newdata = pandas.read_excel(newdata_path) # name, rain, temp
|
# newdata = pandas.read_excel(newdata_path) # name, rain, temp
|
||||||
|
newdata = pandas.read_csv(newdata_path) # name, rain, temp
|
||||||
|
|
||||||
index = 0
|
index = 0
|
||||||
for station in range(1, 334):
|
for station in range(1, 334):
|
||||||
path = DATA_BASE_PATH + r"station/station_new/V7%s.csv" % str(station).rjust(3, '0')
|
path = DATA_BASE_PATH + r"station/station_new/V7%s.csv" % str(station).rjust(3, '0')
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
continue
|
continue
|
||||||
index += 1
|
|
||||||
spi_month_data = []
|
spi_month_data = []
|
||||||
spei_month_data = []
|
spei_month_data = []
|
||||||
for i in range(0, month - 1):
|
for i in range(0, month - 1):
|
||||||
spi_month_data.append("1")
|
spi_month_data.append("1")
|
||||||
spei_month_data.append("1;1")
|
spei_month_data.append("1;1")
|
||||||
|
print(newdata.iloc[index])
|
||||||
spi_month_data.append(str(newdata.iloc[index].rain))
|
spi_month_data.append(str(newdata.iloc[index].rain))
|
||||||
spei_month_data.append(str(newdata.iloc[index].rain) + ";" + str(newdata.iloc[index].temp))
|
spei_month_data.append(str(newdata.iloc[index].rain) + ";" + str(newdata.iloc[index].temp))
|
||||||
|
index += 1
|
||||||
|
|
||||||
forecast_spi = forecast_by_exe(path, 1, spi_month_data, 'spi') # spi
|
forecast_spi = forecast_by_exe(path, 1, spi_month_data, 'spi') # spi
|
||||||
forecast_spei = forecast_by_exe(path, 1, spei_month_data, 'spei') # spei
|
forecast_spei = forecast_by_exe(path, 1, spei_month_data, 'spei') # spei
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
[hidden] {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.leaflet-control-attribution.leaflet-control a {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#map {
|
||||||
|
width: 100%;
|
||||||
|
height: 800px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.result-container {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.result-container p {
|
||||||
|
margin: 20px 0 5px 0;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.result-container > div {
|
||||||
|
background: #efefef;
|
||||||
|
padding: 10px 20px;
|
||||||
|
margin: 10px 0 20px 0;
|
||||||
|
border-left: 6px solid #ccc;
|
||||||
|
min-height: 40px;
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
var CONFIG = {
|
||||||
|
ajaxBase: 'http://baoji.eanbo.cn',
|
||||||
|
styles: {
|
||||||
|
blue: {
|
||||||
|
color: '#3385ff',
|
||||||
|
weight: 2
|
||||||
|
},
|
||||||
|
red: {
|
||||||
|
color: '#ff0000',
|
||||||
|
weight: 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,32 @@
|
||||||
|
$(function () {
|
||||||
|
|
||||||
|
var FileInput = $({});
|
||||||
|
|
||||||
|
var fileBtn;
|
||||||
|
var fileInput;
|
||||||
|
|
||||||
|
function _init() {
|
||||||
|
fileBtn = $('[file-button]');
|
||||||
|
fileInput = $('[file-input]');
|
||||||
|
|
||||||
|
fileBtn.bind('click', function () {
|
||||||
|
fileInput.trigger('click');
|
||||||
|
});
|
||||||
|
|
||||||
|
fileInput.bind('change', function (e) {
|
||||||
|
var files = e.target.files;
|
||||||
|
if (files && files.length) {
|
||||||
|
fileBtn.text(files[0].name);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function isValid() {
|
||||||
|
return !!fileInput.val();
|
||||||
|
}
|
||||||
|
|
||||||
|
_init();
|
||||||
|
FileInput.isValid = isValid;
|
||||||
|
|
||||||
|
window.FileInput = FileInput;
|
||||||
|
});
|
|
@ -0,0 +1,65 @@
|
||||||
|
function initPage() {
|
||||||
|
initOverlay();
|
||||||
|
initForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
function initOverlay() {
|
||||||
|
$.getJSON(CONFIG.ajaxBase + '/disaster/prevent_hailstones')
|
||||||
|
.then(function (response) {
|
||||||
|
var layer = L.geoJSON(JSON.parse(response), {
|
||||||
|
style: function () {
|
||||||
|
return {
|
||||||
|
strokeColor: '#ff0000',
|
||||||
|
weight: 4
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
MapBase.addOverlay(layer, '防雹点');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function initForm() {
|
||||||
|
|
||||||
|
var $resultContainer = $('#js-disaster-result-container');
|
||||||
|
var $resultContent = $('#js-disaster-result-content');
|
||||||
|
var $form = $('#js-disaster-form');
|
||||||
|
|
||||||
|
$form.submit(function (evt) {
|
||||||
|
evt.preventDefault();
|
||||||
|
|
||||||
|
if (!FileInput.isValid()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
MapBase.clear();
|
||||||
|
$resultContainer.hide();
|
||||||
|
$resultContent.empty();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: CONFIG.ajaxBase + '/disaster/' + (MapBase.hasActiveLayer() ? 'hailstones/' : 'calc_hailstones_impact/'),
|
||||||
|
data: new FormData(this),
|
||||||
|
method: 'post',
|
||||||
|
contentType: false,
|
||||||
|
processData: false,
|
||||||
|
success: function (response) {
|
||||||
|
if (response && !response.geo) {
|
||||||
|
MapBase.show(JSON.parse(response), CONFIG.styles.red);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MapBase.show(JSON.parse(response.geo), CONFIG.styles.blue);
|
||||||
|
|
||||||
|
if (!response.agg) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$resultContent.text(JSON.stringify(response.agg, null, 4));
|
||||||
|
$resultContainer.show();
|
||||||
|
},
|
||||||
|
error: function (error) {
|
||||||
|
console.info(error)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
function initPage() {
|
||||||
|
initForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
function initForm() {
|
||||||
|
|
||||||
|
var $resultContainer = $('#js-disaster-result-container');
|
||||||
|
var $resultContent = $('#js-disaster-result-content');
|
||||||
|
var $form = $('#js-disaster-form');
|
||||||
|
|
||||||
|
$form.submit(function (evt) {
|
||||||
|
evt.preventDefault();
|
||||||
|
|
||||||
|
if (!FileInput.isValid()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
MapBase.clear();
|
||||||
|
$resultContainer.hide();
|
||||||
|
$resultContent.empty();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: CONFIG.ajaxBase + '/disaster/'+ (MapBase.hasActiveLayer() ? 'get_spi_region/' : 'calc_spi_diaster/'),
|
||||||
|
data: new FormData(this),
|
||||||
|
method: 'post',
|
||||||
|
contentType: false,
|
||||||
|
processData: false,
|
||||||
|
success: function (response) {
|
||||||
|
if (response && !response.geo) {
|
||||||
|
MapBase.show(JSON.parse(response), CONFIG.styles.blue);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MapBase.show(JSON.parse(response.geo), CONFIG.styles.blue);
|
||||||
|
|
||||||
|
if (!response.agg) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var agg = JSON.parse(response.agg);
|
||||||
|
$resultContent.text(JSON.stringify(agg, null, 4));
|
||||||
|
$resultContainer.show();
|
||||||
|
},
|
||||||
|
error: function (error) {
|
||||||
|
console.info(error)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,88 @@
|
||||||
|
$(function () {
|
||||||
|
|
||||||
|
var MapBase = $({});
|
||||||
|
|
||||||
|
var geoWmsBase = 'http://baoji.eanbo.cn/geoserver/baoji/wms';
|
||||||
|
|
||||||
|
var map;
|
||||||
|
var vector;
|
||||||
|
var layerControl;
|
||||||
|
var activeLayerName = '无';
|
||||||
|
|
||||||
|
function _init() {
|
||||||
|
_initForm();
|
||||||
|
_initMap();
|
||||||
|
_initLayers();
|
||||||
|
}
|
||||||
|
|
||||||
|
function _initForm() {
|
||||||
|
$('[map-base-form-type]').html(
|
||||||
|
['<select name="type" class="sel" id="spi-hidden-type" hidden>',
|
||||||
|
'<option value="" rel-data="无">无</option>',
|
||||||
|
'<option value="cotton" rel-data="棉花">棉花</option>',
|
||||||
|
'<option value="corn" rel-data="玉米">玉米</option>',
|
||||||
|
'<option value="wheat" rel-data="小麦">小麦</option>',
|
||||||
|
'<option value="population" rel-data="人口">人口</option>',
|
||||||
|
'<option value="gdp" rel-data="GDP">GDP</option>',
|
||||||
|
'</select>'].join('')
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function _initMap() {
|
||||||
|
map = L.map('map', {
|
||||||
|
center: [34.3632, 107.2377],
|
||||||
|
zoom: 9,
|
||||||
|
tileLayer: false,
|
||||||
|
layers: [
|
||||||
|
L.tileLayer.chinaProvider('TianDiTu.Satellite.Map', {maxZoom: 18, minZoom: 5})
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
vector = L.vectorLayer({map: map});
|
||||||
|
}
|
||||||
|
|
||||||
|
function _initLayers() {
|
||||||
|
var baseLayers = {
|
||||||
|
'无': L.tileLayer(''),
|
||||||
|
'棉花': L.WMS.source(geoWmsBase).getLayer('baoji:cotton_3857'),
|
||||||
|
'玉米': L.WMS.source(geoWmsBase).getLayer('baoji:cron'),
|
||||||
|
'小麦': L.WMS.source(geoWmsBase).getLayer('baoji:wheat_3857'),
|
||||||
|
'人口': L.WMS.source(geoWmsBase).getLayer('baoji:population'),
|
||||||
|
'GDP': L.WMS.source(geoWmsBase).getLayer('baoji:gdp')
|
||||||
|
};
|
||||||
|
layerControl = L.control.layers(baseLayers, {}).addTo(map);
|
||||||
|
|
||||||
|
map.on('baselayerchange', function (e) {
|
||||||
|
activeLayerName = e.name;
|
||||||
|
$('#spi-hidden-type').val($('option[rel-data="'+ e.name +'"]').val());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function _addOverlay(layer, name) {
|
||||||
|
layerControl.addOverlay(layer, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _hasActiveLayer() {
|
||||||
|
return activeLayerName === '无';
|
||||||
|
}
|
||||||
|
|
||||||
|
function _show(geojson, style) {
|
||||||
|
L.geoJSON(geojson, {
|
||||||
|
style: style || CONFIG.styles.blue
|
||||||
|
}).addTo(vector);
|
||||||
|
map.fitBounds(vector.getBounds());
|
||||||
|
}
|
||||||
|
|
||||||
|
function _clear() {
|
||||||
|
vector.clearLayers();
|
||||||
|
}
|
||||||
|
|
||||||
|
_init();
|
||||||
|
MapBase.show = _show;
|
||||||
|
MapBase.clear = _clear;
|
||||||
|
MapBase.hasActiveLayer = _hasActiveLayer;
|
||||||
|
MapBase.addOverlay = _addOverlay;
|
||||||
|
|
||||||
|
window.MapBase = MapBase;
|
||||||
|
|
||||||
|
});
|
|
@ -0,0 +1,97 @@
|
||||||
|
{% extends 'dashboard/base.html' %}
|
||||||
|
{% load bootstrap3 %}
|
||||||
|
{% block add_css %}
|
||||||
|
{% load static %}
|
||||||
|
<link href="{% static 'disaster/css/base.css' %}" rel="stylesheet" />
|
||||||
|
{% endblock %}
|
||||||
|
{% block page_head %}冰雹风险预测{% endblock %}
|
||||||
|
{% block breadcrumb %}
|
||||||
|
<li>
|
||||||
|
<a href="{% url 'dashboard-index' %}">首页</a>
|
||||||
|
</li>
|
||||||
|
<li class="active">
|
||||||
|
冰雹风险预测
|
||||||
|
</li>
|
||||||
|
{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<div class="ibox">
|
||||||
|
<div class="ibox-title">
|
||||||
|
<h5>冰雹风险预测</h5>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="ibox-content">
|
||||||
|
|
||||||
|
<div class="well">
|
||||||
|
<ul style="margin-bottom: 0;">
|
||||||
|
<li><span style="font-weight: bolder">名称:</span>冰雹风险预测</li>
|
||||||
|
<li><span style="font-weight: bolder">要素:</span>县域、DEM</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row m-b-sm m-t-sm">
|
||||||
|
|
||||||
|
|
||||||
|
<div class="col-md-12">
|
||||||
|
<form enctype="application/x-www-form-urlencoded" method="post" id="js-disaster-form">
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
|
||||||
|
<label for="county">划分县域</label>
|
||||||
|
<select name="county" class="sel" id="county">
|
||||||
|
<option value="1">是</option>
|
||||||
|
<option value="0">否</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<label for="dem">DEM</label>
|
||||||
|
<select name="dem" class="sel" id="dem">
|
||||||
|
<option value="1">是</option>
|
||||||
|
<option value="0">否</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
<label for="file-path">数据文件</label>
|
||||||
|
<button file-button type="button">选择文件</button>
|
||||||
|
<input file-input hidden name="file_path" class="sel" id="file-path" type="file" onchange="" />
|
||||||
|
|
||||||
|
<div hidden map-base-form-type></div>
|
||||||
|
|
||||||
|
<button type="submit" class="btn btn-default sel pull-right">计算</button>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="result-container" id="js-disaster-result-container">
|
||||||
|
<p>计算结果:</p>
|
||||||
|
<div id="js-disaster-result-content"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div id="map""></div>
|
||||||
|
</div>
|
||||||
|
{% if is_paginated %}
|
||||||
|
<div class="col-md-12">
|
||||||
|
{% bootstrap_pagination page_obj size='small' extra=request.GET.urlencode %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
{% block add_js %}
|
||||||
|
<script type="text/javascript" src="{% static 'disaster/js/map.js' %}"></script>
|
||||||
|
<script type="text/javascript" src="{% static 'graphic/js/leaflet.ChineseTmsProviders.js' %}"></script>
|
||||||
|
<script type="text/javascript" src="{% static 'disaster/js/config.js' %}"></script>
|
||||||
|
<script type="text/javascript" src="{% static 'disaster/js/mapBase.js' %}"></script>
|
||||||
|
<script type="text/javascript" src="{% static 'disaster/js/fileInput.js' %}"></script>
|
||||||
|
<script type="text/javascript" src="{% static 'disaster/js/hail.js' %}"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(function () {
|
||||||
|
initPage();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
|
@ -0,0 +1,104 @@
|
||||||
|
{% extends 'dashboard/base.html' %}
|
||||||
|
{% load bootstrap3 %}
|
||||||
|
{% block add_css %}
|
||||||
|
{% load static %}
|
||||||
|
<link href="{% static 'disaster/css/base.css' %}" rel="stylesheet" />
|
||||||
|
{% endblock %}
|
||||||
|
{% block page_head %}干旱预测{% endblock %}
|
||||||
|
{% block breadcrumb %}
|
||||||
|
<li>
|
||||||
|
<a href="{% url 'dashboard-index' %}">首页</a>
|
||||||
|
</li>
|
||||||
|
<li class="active">
|
||||||
|
干旱预测
|
||||||
|
</li>
|
||||||
|
{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<div class="ibox">
|
||||||
|
<div class="ibox-title">
|
||||||
|
<h5>干旱预测</h5>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="ibox-content">
|
||||||
|
|
||||||
|
<div class="well">
|
||||||
|
<ul style="margin-bottom: 0;">
|
||||||
|
<li><span style="font-weight: bolder">名称:</span>干旱预测</li>
|
||||||
|
<li><span style="font-weight: bolder">要素:</span>模型、月份、县域</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row m-b-sm m-t-sm">
|
||||||
|
|
||||||
|
|
||||||
|
<div class="col-md-12">
|
||||||
|
<form enctype="application/x-www-form-urlencoded" method="post" id="js-disaster-form">
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="spi-type">模型</label>
|
||||||
|
<select name="spi_type" class="sel" id="spi-type">
|
||||||
|
<option value="spi">SPI</option>
|
||||||
|
<option value="spei">SPEI</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<label for="month">月份</label>
|
||||||
|
<select name="month" class="sel" id="month">
|
||||||
|
{% for month in months %}
|
||||||
|
<option value="{{ month }}"
|
||||||
|
{% if month == year|stringformat:"i" %}selected{% endif %}>{{ month }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<label for="county">划分县域</label>
|
||||||
|
<select name="county" class="sel" id="county">
|
||||||
|
<option value="1">是</option>
|
||||||
|
<option value="0">否</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
<label for="file-path">数据文件</label>
|
||||||
|
<button file-button type="button">选择文件</button>
|
||||||
|
<input file-input hidden name="file_path" class="sel" id="file-path" type="file" onchange="" />
|
||||||
|
|
||||||
|
<div hidden map-base-form-type></div>
|
||||||
|
|
||||||
|
<button type="submit" class="btn btn-default sel pull-right">计算</button>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="result-container" id="js-disaster-result-container">
|
||||||
|
<p>计算结果:</p>
|
||||||
|
<div id="js-disaster-result-content"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div id="map"></div>
|
||||||
|
</div>
|
||||||
|
{% if is_paginated %}
|
||||||
|
<div class="col-md-12">
|
||||||
|
{% bootstrap_pagination page_obj size='small' extra=request.GET.urlencode %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
{% block add_js %}
|
||||||
|
<script type="text/javascript" src="{% static 'disaster/js/map.js' %}"></script>
|
||||||
|
<script type="text/javascript" src="{% static 'graphic/js/leaflet.ChineseTmsProviders.js' %}"></script>
|
||||||
|
<script type="text/javascript" src="{% static 'disaster/js/config.js' %}"></script>
|
||||||
|
<script type="text/javascript" src="{% static 'disaster/js/mapBase.js' %}"></script>
|
||||||
|
<script type="text/javascript" src="{% static 'disaster/js/fileInput.js' %}"></script>
|
||||||
|
<script type="text/javascript" src="{% static 'disaster/js/index.js' %}"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(function () {
|
||||||
|
initPage();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
|
@ -5,11 +5,12 @@ from graphic.models import Address, Station, Grid
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
path('', views.index, name='disaster-index'),
|
||||||
|
path('hail', views.hail, name='disaster-hail'),
|
||||||
path('hailstones/', views.hailstones, name='disater-hailstones'),
|
path('hailstones/', views.hailstones, name='disater-hailstones'),
|
||||||
path('calc_hailstones_impact/', views.calc_hailstones_impact, name='disater-calc_hailstones_impact'),
|
path('calc_hailstones_impact/', views.calc_hailstones_impact, name='disater-calc_hailstones_impact'),
|
||||||
path('prevent_hailstones/', views.prevent_hailstones, name='disater-prevent_hailstones'),
|
path('prevent_hailstones/', views.prevent_hailstones, name='disater-prevent_hailstones'),
|
||||||
path('calc_prevent_impact/', views.calc_hailstones_impact, name='disater-calc_prevent_impact'),
|
path('calc_prevent_impact/', views.calc_prevent_impact, name='disater-calc_prevent_impact'),
|
||||||
path('get_spi_region/', views.get_spi_region, name='disater-get_spi_region'),
|
path('get_spi_region/', views.get_spi_region, name='disater-get_spi_region'),
|
||||||
path('calc_spi_diaster/', views.calc_spi_diaster, name='disater-calc_spi_diaster'),
|
path('calc_spi_diaster/', views.calc_spi_diaster, name='disater-calc_spi_diaster')
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -6,7 +6,7 @@ import rasterio.mask
|
||||||
from rasterio.warp import reproject, Resampling
|
from rasterio.warp import reproject, Resampling
|
||||||
|
|
||||||
DATA_BASE_PATH = '/home/g214/data_from_chenhao/data_analyse/'
|
DATA_BASE_PATH = '/home/g214/data_from_chenhao/data_analyse/'
|
||||||
# DATA_BASE_PATH = r'D:\7. business\7.baoji\code\drought_analyse\data\\'
|
# DATA_BASE_PATH = r"D:\7. business\7.baoji\code\drought_analyse\data/"
|
||||||
|
|
||||||
def get_buffer_data(gdf, crs={'init': 'epsg:4326', 'no_defs': True}, dis=1):
|
def get_buffer_data(gdf, crs={'init': 'epsg:4326', 'no_defs': True}, dis=1):
|
||||||
data = gdf
|
data = gdf
|
||||||
|
@ -24,20 +24,25 @@ def get_buffer_data(gdf, crs={'init': 'epsg:4326', 'no_defs': True}, dis=1):
|
||||||
|
|
||||||
def read_xzqh(path):
|
def read_xzqh(path):
|
||||||
shp_bjqh = GeoDataFrame.from_file(path)
|
shp_bjqh = GeoDataFrame.from_file(path)
|
||||||
shp_bjqh = shp_bjqh[['geometry', '县名称']]
|
shp_bjqh = shp_bjqh[['geometry', 'county']]
|
||||||
shp_bjqh.rename(columns={'县名称': 'county'}, inplace=True)
|
# shp_bjqh.rename(columns={'县名称': 'county'}, inplace=True)
|
||||||
shp_bjqh.to_crs(epsg=4326, inplace=True)
|
shp_bjqh.to_crs(epsg=4326, inplace=True)
|
||||||
return shp_bjqh
|
return shp_bjqh
|
||||||
|
|
||||||
|
|
||||||
def intersection(gdf1, gdf2):
|
def intersection(gdf1, gdf2):
|
||||||
data = geopandas.overlay(gdf1, gdf2, how='intersection')
|
try:
|
||||||
|
from geopandas.tools import overlay
|
||||||
|
data = overlay(gdf1, gdf2, how='intersection', use_sindex=False)
|
||||||
data.crs = gdf1.crs
|
data.crs = gdf1.crs
|
||||||
return data
|
return data
|
||||||
|
except Exception as e:
|
||||||
|
print(str(e))
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def intersection_xzqh(gdf):
|
def intersection_xzqh(gdf):
|
||||||
bjqh = read_xzqh(DATA_BASE_PATH + 'boundary/bjxx.shp')
|
bjqh = read_xzqh(DATA_BASE_PATH + 'boundary/bj.shp')
|
||||||
intersection_data = intersection(gdf, bjqh)
|
intersection_data = intersection(gdf, bjqh)
|
||||||
return intersection_data
|
return intersection_data
|
||||||
|
|
||||||
|
@ -59,6 +64,7 @@ def agg_raster_by_gdf_value(path, gdf):
|
||||||
res = np.nansum(np.where(out_image == src.nodata, np.nan, out_image))
|
res = np.nansum(np.where(out_image == src.nodata, np.nan, out_image))
|
||||||
if 'county' in gdf:
|
if 'county' in gdf:
|
||||||
county = gdf.iloc[i].county
|
county = gdf.iloc[i].county
|
||||||
|
print(county)
|
||||||
if county in sum.keys():
|
if county in sum.keys():
|
||||||
sum[county] = sum.get(county) + res
|
sum[county] = sum.get(county) + res
|
||||||
else:
|
else:
|
||||||
|
@ -106,13 +112,36 @@ def agg_raster_by_gdf_area(path, gdf):
|
||||||
return sum
|
return sum
|
||||||
|
|
||||||
|
|
||||||
|
def agg_prevent_disater_by_gdf_area(path, gdf):
|
||||||
|
# crs = '+proj=aea +lat_1=25 +lat_2=47 +lat_0=0 +lon_0=105 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs'
|
||||||
|
with rio.open(path) as src:
|
||||||
|
gdf = gdf.to_crs(epsg=3857)
|
||||||
|
sum = {}
|
||||||
|
for i in range(0, len(gdf)):
|
||||||
|
geo = gdf.iloc[i].geometry
|
||||||
|
try:
|
||||||
|
feature = [GeoSeries(geo).__geo_interface__['features'][0]['geometry']]
|
||||||
|
out_image, out_transform = rio.mask.mask(src, feature, crop=True, nodata=src.nodata)
|
||||||
|
out_image = np.where(out_image == 1, 1, np.nan)
|
||||||
|
print(out_image)
|
||||||
|
res = np.nansum(out_image) * src.width * src.height
|
||||||
|
name = str(gdf.iloc[i].name)
|
||||||
|
if name in sum.keys():
|
||||||
|
sum[name] = sum.get(name) + res
|
||||||
|
else:
|
||||||
|
sum[name] = res
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return sum
|
||||||
|
|
||||||
|
|
||||||
def agg_gdf_by_gdf_area(gdf1, gdf2):
|
def agg_gdf_by_gdf_area(gdf1, gdf2):
|
||||||
intersection_data = intersection(gdf1, gdf2)
|
intersection_data = intersection(gdf1, gdf2)
|
||||||
area = intersection_data.to_crs(epsg=3857).area
|
area = intersection_data.to_crs(epsg=3857).area
|
||||||
intersection_data['area'] = area
|
intersection_data['area'] = area
|
||||||
intersection_data = intersection_data[['name', 'area']]
|
intersection_data = intersection_data[['name', 'area']]
|
||||||
# print(intersection_data.head())
|
# print(intersection_data.head())
|
||||||
return intersection_data.groupby('name').sum()
|
return intersection_data.groupby('name')['area'].sum()
|
||||||
|
|
||||||
|
|
||||||
def agg_raster_by_gdf_area_and_aspect_slope(path, path_aspect, path_slope, gdf):
|
def agg_raster_by_gdf_area_and_aspect_slope(path, path_aspect, path_slope, gdf):
|
||||||
|
|
|
@ -10,9 +10,22 @@ from django.views.decorators.csrf import csrf_exempt
|
||||||
from .util.utils import *
|
from .util.utils import *
|
||||||
from .radar.process import *
|
from .radar.process import *
|
||||||
from .spi.process import *
|
from .spi.process import *
|
||||||
|
from dashboard.models import Spi
|
||||||
|
|
||||||
PROXY_FORMAT = 'http://%s:%d%s' % ('210.77.68.250', 8080, '%s')
|
PROXY_FORMAT = 'http://%s:%d%s' % ('210.77.68.250', 8080, '%s')
|
||||||
|
|
||||||
|
|
||||||
|
def index(request):
|
||||||
|
month = request.GET.get('month', '1')
|
||||||
|
months = range(1, 13)
|
||||||
|
spis = Spi.objects.filter(month=month)
|
||||||
|
return render(request, 'disaster/index.html', {'month': month, 'months': months, 'spis': spis})
|
||||||
|
|
||||||
|
|
||||||
|
def hail(request):
|
||||||
|
return render(request, 'disaster/hail.html')
|
||||||
|
|
||||||
|
|
||||||
## 冰雹相关
|
## 冰雹相关
|
||||||
'''取出冰雹范围'''
|
'''取出冰雹范围'''
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
|
@ -47,21 +60,21 @@ def get_type_path(type):
|
||||||
'''计算冰雹的影响'''
|
'''计算冰雹的影响'''
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def calc_hailstones_impact(request):
|
def calc_hailstones_impact(request):
|
||||||
type = request.GET['type']
|
type = request.POST['type']
|
||||||
county = request.GET['county'] # 是否划分县域 1 or 0
|
county = request.POST.get('county', '0') # 是否划分县域 1 or 0
|
||||||
calc_dem = request.GET['dem'] # 是否计算dem 1 or 0
|
calc_dem = request.POST.get('dem', '0') # 是否计算dem 1 or 0
|
||||||
csv_path = handle_uploaded_file(request.FILES['file_path']) # 冰雹雷达数据
|
csv_path = handle_uploaded_file(request.FILES['file_path']) # 冰雹雷达数据
|
||||||
|
|
||||||
hailstones_data = get_hailstones(csv_path)
|
hailstones_data = get_hailstones(csv_path)
|
||||||
if county == 1:
|
if county == "1":
|
||||||
hailstones_data = intersection_xzqh(hailstones_data)
|
hailstones_data = intersection_xzqh(hailstones_data)
|
||||||
|
|
||||||
tif_path = get_type_path(type)
|
tif_path = get_type_path(type)
|
||||||
if calc_dem == 0:
|
if calc_dem == "0":
|
||||||
sum = agg_raster_by_gdf_value(tif_path, hailstones_data)
|
sum = agg_raster_by_gdf_value(tif_path, hailstones_data)
|
||||||
else:
|
else:
|
||||||
sum = agg_raster_by_gdf_area_and_aspect_slope(tif_path, get_type_path('aspect'), get_type_path('slope'),
|
sum = agg_raster_by_gdf_area_and_aspect_slope(tif_path, get_type_path('aspect'), get_type_path('slope'),
|
||||||
hailstones_data)
|
hailstones_data) # 最后的结果是平地 30 大于30的三种结果
|
||||||
res = {}
|
res = {}
|
||||||
res['agg'] = sum
|
res['agg'] = sum
|
||||||
res['geo'] = hailstones_data.to_json()
|
res['geo'] = hailstones_data.to_json()
|
||||||
|
@ -84,18 +97,30 @@ def prevent_hailstones(request):
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def calc_prevent_impact(request):
|
def calc_prevent_impact(request):
|
||||||
csv_path = handle_uploaded_file(request.FILES['file_path']) # 冰雹雷达数据
|
csv_path = handle_uploaded_file(request.FILES['file_path']) # 冰雹雷达数据
|
||||||
|
type = request.POST.get('type') # 此处type可以为空
|
||||||
|
|
||||||
prevent_data = prevent_hailstones_data()
|
prevent_data_inter = prevent_hailstones_data()
|
||||||
|
|
||||||
hailstones_data = get_hailstones(csv_path)
|
hailstones_data_inter = get_hailstones(csv_path)
|
||||||
prevent_intersection_disater_data = intersection(prevent_data, hailstones_data)
|
|
||||||
print(prevent_intersection_disater_data)
|
prevent_intersection_disater_data = intersection(hailstones_data_inter, prevent_data_inter)
|
||||||
agg = agg_gdf_by_gdf_area(prevent_data, prevent_intersection_disater_data)
|
# print(prevent_intersection_disater_data.head())
|
||||||
|
if prevent_intersection_disater_data.empty:
|
||||||
|
return JsonResponse('{"res": "EMPTY"}', safe=False)
|
||||||
|
if type:
|
||||||
|
agg = agg_prevent_disater_by_gdf_area(get_type_path(type), prevent_intersection_disater_data)
|
||||||
|
sum = 0
|
||||||
|
for key in agg.keys():
|
||||||
|
sum = sum + agg.get(key)
|
||||||
|
else:
|
||||||
|
agg = agg_gdf_by_gdf_area(prevent_data_inter, prevent_intersection_disater_data)
|
||||||
|
sum = agg.sum()
|
||||||
# print(res) # 单个点的面积
|
# print(res) # 单个点的面积
|
||||||
# print(res.sum()) # 总面积
|
# print(res.sum()) # 总面积
|
||||||
res = {}
|
res = {}
|
||||||
res['agg'] = agg
|
|
||||||
res['sum'] = agg.sum()
|
res['agg'] = json.dumps(agg)
|
||||||
|
res['sum'] = sum
|
||||||
res['geo'] = prevent_intersection_disater_data.to_json()
|
res['geo'] = prevent_intersection_disater_data.to_json()
|
||||||
return JsonResponse(res, safe=False)
|
return JsonResponse(res, safe=False)
|
||||||
|
|
||||||
|
@ -104,11 +129,11 @@ def calc_prevent_impact(request):
|
||||||
'''获取SPI或者SPEI分布情况'''
|
'''获取SPI或者SPEI分布情况'''
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def get_spi_region(request):
|
def get_spi_region(request):
|
||||||
spi_type = request.GET['spi_type'] # spi.spei
|
spi_type = request.POST['spi_type'] # spi.spei
|
||||||
month = request.GET['month'] # 几月
|
month = request.POST['month'] # 几月
|
||||||
file_path = handle_uploaded_file(request.FILES['file_path']) # 上传文件, name, rain, temp
|
file_path = handle_uploaded_file(request.FILES['file_path']) # 上传文件, name, rain, temp
|
||||||
station_buffer = get_station_polygon()
|
station_buffer = get_station_polygon()
|
||||||
spi_gdf = get_spi_dataframe(station_buffer, file_path, month)
|
spi_gdf = get_spi_dataframe(station_buffer, file_path, int(month))
|
||||||
spi_disaster = get_disaster_gdf(spi_gdf, spi_type)
|
spi_disaster = get_disaster_gdf(spi_gdf, spi_type)
|
||||||
return JsonResponse(spi_disaster.to_json(), safe=False)
|
return JsonResponse(spi_disaster.to_json(), safe=False)
|
||||||
|
|
||||||
|
@ -116,35 +141,37 @@ def get_spi_region(request):
|
||||||
'''计算spi或spei对各种因素的影响'''
|
'''计算spi或spei对各种因素的影响'''
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def calc_spi_diaster(request):
|
def calc_spi_diaster(request):
|
||||||
spi_type = request.GET['spi_type'] # spi.spei
|
spi_type = request.POST['spi_type'] # spi.spei
|
||||||
county = request.GET['county'] # 是否划分县域 1 or 0
|
county = request.POST['county'] # 是否划分县域 1 or 0
|
||||||
type = request.GET['type'] # 栅格种类
|
type = request.POST['type'] # 栅格种类
|
||||||
month = request.GET['month'] # 几月
|
month = request.POST['month'] # 几月
|
||||||
file_path = handle_uploaded_file(request.FILES['file_path']) # name, rain, temp
|
file_path = handle_uploaded_file(request.FILES['file_path']) # name, rain, temp
|
||||||
|
|
||||||
station_buffer = get_station_polygon()
|
station_buffer = get_station_polygon()
|
||||||
spi_gdf = get_spi_dataframe(station_buffer, file_path, month)
|
spi_gdf = get_spi_dataframe(station_buffer, file_path, int(month))
|
||||||
|
|
||||||
spi_disaster = get_disaster_gdf(spi_gdf, spi_type)
|
spi_disaster = get_disaster_gdf(spi_gdf, spi_type)
|
||||||
|
|
||||||
if county:
|
if county == "1":
|
||||||
spi_disaster = intersection_xzqh(spi_disaster)
|
spi_disaster = intersection_xzqh(spi_disaster)
|
||||||
|
|
||||||
res_spi = agg_raster_by_gdf_value(get_type_path(type), spi_disaster)
|
res_spi = agg_raster_by_gdf_value(get_type_path(type), spi_disaster)
|
||||||
res = {}
|
res = {}
|
||||||
res['geo'] = spi_disaster.to_json()
|
res['geo'] = spi_disaster.to_json()
|
||||||
res['agg'] = res_spi
|
res['agg'] = json.dumps(res_spi)
|
||||||
return JsonResponse(res, safe=False)
|
return JsonResponse(res, safe=False)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def handle_uploaded_file(f):
|
def handle_uploaded_file(f):
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
file_name = f.name
|
file_name = f.name
|
||||||
# _, ext = os.path.splitext(file_name)
|
# _, ext = os.path.splitext(file_name)
|
||||||
# id = str(uuid.uuid4())
|
# id = str(uuid.uuid4())
|
||||||
media_root = settings.MEDIA_ROOT
|
media_root = settings.MEDIA_ROOT
|
||||||
path = '%s\%s' % (media_root, file_name)
|
if not os.path.exists(media_root):
|
||||||
|
os.mkdir(media_root)
|
||||||
|
|
||||||
|
path = '%s/%s' % (media_root, file_name)
|
||||||
print(path)
|
print(path)
|
||||||
with open(path, 'wb+') as destination:
|
with open(path, 'wb+') as destination:
|
||||||
for chunk in f.chunks():
|
for chunk in f.chunks():
|
||||||
|
|
|
@ -44,6 +44,7 @@ INSTALLED_APPS = [
|
||||||
'graphic',
|
'graphic',
|
||||||
'policy',
|
'policy',
|
||||||
'predict',
|
'predict',
|
||||||
|
'disaster'
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
@ -138,8 +139,38 @@ STATICFILES_DIRS = [
|
||||||
STATIC_ROOT = '/var/www/p3/drought/shared/static'
|
STATIC_ROOT = '/var/www/p3/drought/shared/static'
|
||||||
MEDIA_ROOT = '/var/www/p3/drought/shared/static/media/'
|
MEDIA_ROOT = '/var/www/p3/drought/shared/static/media/'
|
||||||
|
|
||||||
CORS_URLS_REGEX = r'^//disaster/.*$'
|
# CORS_URLS_REGEX = r'^//disaster/.*$'
|
||||||
|
|
||||||
|
#跨域增加忽略
|
||||||
|
CORS_ALLOW_CREDENTIALS = True
|
||||||
|
CORS_ORIGIN_ALLOW_ALL = True
|
||||||
|
CORS_ORIGIN_WHITELIST = (
|
||||||
|
'*'
|
||||||
|
)
|
||||||
|
|
||||||
|
CORS_ALLOW_METHODS = (
|
||||||
|
'DELETE',
|
||||||
|
'GET',
|
||||||
|
'OPTIONS',
|
||||||
|
'PATCH',
|
||||||
|
'POST',
|
||||||
|
'PUT',
|
||||||
|
'VIEW',
|
||||||
|
)
|
||||||
|
|
||||||
|
CORS_ALLOW_HEADERS = (
|
||||||
|
'XMLHttpRequest',
|
||||||
|
'X_FILENAME',
|
||||||
|
'accept-encoding',
|
||||||
|
'authorization',
|
||||||
|
'content-type',
|
||||||
|
'dnt',
|
||||||
|
'origin',
|
||||||
|
'user-agent',
|
||||||
|
'x-csrftoken',
|
||||||
|
'x-requested-with',
|
||||||
|
'Pragma',
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from .local_settings import *
|
from .local_settings import *
|
||||||
|
|
|
@ -25,6 +25,6 @@ urlpatterns = [
|
||||||
path('graphic/', include('graphic.urls')),
|
path('graphic/', include('graphic.urls')),
|
||||||
path('policy/', include('policy.urls')),
|
path('policy/', include('policy.urls')),
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
path('predict/',include('predict.urls')),
|
path('predict/', include('predict.urls')),
|
||||||
path('disaster/',include('disaster.urls')),
|
path('disaster/', include('disaster.urls'))
|
||||||
]
|
]
|
||||||
|
|
|
@ -14,7 +14,8 @@ $(function () {
|
||||||
layers: 'baoji:bj_eco',
|
layers: 'baoji:bj_eco',
|
||||||
transparent: true,
|
transparent: true,
|
||||||
format: 'image/png',
|
format: 'image/png',
|
||||||
styles: 'baoji:gdp'
|
styles: 'baoji:gdp',
|
||||||
|
tiled:false,
|
||||||
});
|
});
|
||||||
map.addLayer(countyLayer);
|
map.addLayer(countyLayer);
|
||||||
|
|
||||||
|
|
|
@ -85,14 +85,6 @@ function initChart(element, code, year_from, year_to) {
|
||||||
name: '气温',
|
name: '气温',
|
||||||
type: 'line',
|
type: 'line',
|
||||||
animation: false,
|
animation: false,
|
||||||
areaStyle: {
|
|
||||||
normal: {}
|
|
||||||
},
|
|
||||||
lineStyle: {
|
|
||||||
normal: {
|
|
||||||
width: 1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
data: temperatureData
|
data: temperatureData
|
||||||
},
|
},
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -27,13 +27,13 @@ $(function () {
|
||||||
styles:'baoji:county_boundary'
|
styles:'baoji:county_boundary'
|
||||||
});
|
});
|
||||||
map.addLayer(baojiLayer);
|
map.addLayer(baojiLayer);
|
||||||
var countyLayer = L.tileLayer.wms('http://210.77.68.250:8080/geoserver/baoji/wms', {
|
var spiLayer = L.tileLayer.wms('http://210.77.68.250:8080/geoserver/baoji/wms', {
|
||||||
layers: 'baoji:1979-1-spi',
|
layers: 'baoji:1979-1-spi',
|
||||||
transparent: true,
|
transparent: true,
|
||||||
format: 'image/png',
|
format: 'image/png',
|
||||||
styles: 'baoji:spi'
|
styles: 'baoji:spi'
|
||||||
});
|
});
|
||||||
map.addLayer(countyLayer);
|
map.addLayer(spiLayer);
|
||||||
var handle = $("#custom-handle");
|
var handle = $("#custom-handle");
|
||||||
|
|
||||||
function slideLayer() {
|
function slideLayer() {
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
var results = [];
|
||||||
|
var count = 0;
|
||||||
|
for (var y = 1979; y < 2016; y++) {
|
||||||
|
for (var m = 1; m < 13; m++) {
|
||||||
|
var year = y.toString();
|
||||||
|
var month = m.toString();
|
||||||
|
var result = month.length < 2 ? year + '-' + month + '-spei' : year + month + '-spei';
|
||||||
|
results.push(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$(function () {
|
||||||
|
|
||||||
|
var map = L.map('map', {
|
||||||
|
center: [34.3632, 107.2377],
|
||||||
|
zoom: 9
|
||||||
|
});
|
||||||
|
|
||||||
|
L.tileLayer.chinaProvider('TianDiTu.Satellite.Map', {maxZoom: 18, minZoom: 5}).addTo(map);
|
||||||
|
L.tileLayer.chinaProvider('TianDiTu.Satellite.Annotion', {maxZoom: 18, minZoom: 5}).addTo(map);
|
||||||
|
|
||||||
|
var currentLayer = undefined;
|
||||||
|
var baojiLayer = L.tileLayer.wms('http://210.77.68.250:8080/geoserver/baoji/wms', {
|
||||||
|
layers: 'baoji:bj_county_boundary',
|
||||||
|
transparent: true,
|
||||||
|
format: 'image/png',
|
||||||
|
styles:'baoji:county_boundary'
|
||||||
|
});
|
||||||
|
map.addLayer(baojiLayer);
|
||||||
|
var speiLayer = L.tileLayer.wms('http://210.77.68.250:8080/geoserver/baoji/wms', {
|
||||||
|
layers: 'baoji:1979-1-spei',
|
||||||
|
transparent: true,
|
||||||
|
format: 'image/png',
|
||||||
|
styles: 'baoji:spei'
|
||||||
|
});
|
||||||
|
map.addLayer(speiLayer);
|
||||||
|
var handle = $("#custom-handle");
|
||||||
|
|
||||||
|
function slideLayer() {
|
||||||
|
function removeLayer(currentLayer, o) {
|
||||||
|
var old = currentLayer;
|
||||||
|
setTimeout(function () {
|
||||||
|
map.removeLayer(old);
|
||||||
|
}, 500)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentLayer) {
|
||||||
|
removeLayer(currentLayer, 1);
|
||||||
|
}
|
||||||
|
currentLayer = L.tileLayer.wms('http://210.77.68.250:8080/geoserver/baoji/wms', {
|
||||||
|
layers: 'baoji:' + results[count],
|
||||||
|
transparent: true,
|
||||||
|
format: 'image/png',
|
||||||
|
styles: 'baoji:spei'
|
||||||
|
});
|
||||||
|
map.addLayer(currentLayer);
|
||||||
|
count += 1;
|
||||||
|
if (count > results.length) count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
baojiLayer.bringToFront();
|
||||||
|
slideLayer();
|
||||||
|
|
||||||
|
setInterval(slideLayer, 1000);
|
||||||
|
});
|
||||||
|
|
|
@ -22,9 +22,9 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="ibox-content" style="padding: 0;">
|
<div class="ibox-content" style="padding: 0;">
|
||||||
<div id="map" style="width: 100%;height: 800px;">
|
<div id="map" style="width: 100%;height: 800px;">
|
||||||
<div class="legend">
|
{# <div class="legend">#}
|
||||||
<img src="http://210.77.68.250:8080/geoserver/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=40&HEIGHT=30&LAYER=baoji:bj_boundary_and_station_group&STYLES=baoji:county_boundary,baoji:county_boundary,baoji:station_point,grid">
|
{# <img src="http://210.77.68.250:8080/geoserver/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=40&HEIGHT=30&LAYER=baoji:bj_boundary_and_station_group&STYLES=baoji:county_boundary,baoji:county_boundary,baoji:station_point,grid">#}
|
||||||
</div>
|
{# </div>#}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
<link href="{% static 'graphic/css/jquery-ui.css' %}" rel="stylesheet">
|
<link href="{% static 'graphic/css/jquery-ui.css' %}" rel="stylesheet">
|
||||||
<link href="{% static 'graphic/css/leaflet.timedimension.control.min.css' %}" rel="stylesheet">
|
<link href="{% static 'graphic/css/leaflet.timedimension.control.min.css' %}" rel="stylesheet">
|
||||||
<link href="{% static 'graphic/css/timeline2.css' %}" rel="stylesheet">
|
<link href="{% static 'graphic/css/timeline2.css' %}" rel="stylesheet">
|
||||||
|
<link href="{% static 'dashboard/css/legend.css' %}" rel="stylesheet">
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block page_head %}降水量动态空间变化{% endblock %}
|
{% block page_head %}降水量动态空间变化{% endblock %}
|
||||||
{% block breadcrumb %}
|
{% block breadcrumb %}
|
||||||
|
@ -23,6 +25,9 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="ibox-content" style="padding: 0; position: relative;">
|
<div class="ibox-content" style="padding: 0; position: relative;">
|
||||||
<div id="map" style="width: 100%;height: 800px;">
|
<div id="map" style="width: 100%;height: 800px;">
|
||||||
|
<div class="legend">
|
||||||
|
<img src="http://210.77.68.250:8080/geoserver/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=30&HEIGHT=30&LAYER=baoji:1979-1-rain&STYLE=baoji:rain">
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
<link href="{% static 'graphic/css/jquery-ui.css' %}" rel="stylesheet">
|
<link href="{% static 'graphic/css/jquery-ui.css' %}" rel="stylesheet">
|
||||||
<link href="{% static 'graphic/css/leaflet.timedimension.control.min.css' %}" rel="stylesheet">
|
<link href="{% static 'graphic/css/leaflet.timedimension.control.min.css' %}" rel="stylesheet">
|
||||||
<link href="{% static 'graphic/css/timeline2.css' %}" rel="stylesheet">
|
<link href="{% static 'graphic/css/timeline2.css' %}" rel="stylesheet">
|
||||||
|
<link href="{% static 'dashboard/css/legend.css' %}" rel="stylesheet">
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block page_head %}气温动态空间变化{% endblock %}
|
{% block page_head %}气温动态空间变化{% endblock %}
|
||||||
{% block breadcrumb %}
|
{% block breadcrumb %}
|
||||||
|
@ -23,6 +25,9 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="ibox-content" style="padding: 0; position: relative;">
|
<div class="ibox-content" style="padding: 0; position: relative;">
|
||||||
<div id="map" style="width: 100%;height: 800px;">
|
<div id="map" style="width: 100%;height: 800px;">
|
||||||
|
<div class="legend">
|
||||||
|
<img src="http://210.77.68.250:8080/geoserver/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=40&HEIGHT=10&LAYER=baoji:1979-1-temp&STYLE=baoji:temp">
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
{% extends 'dashboard/base.html' %}
|
||||||
|
{% load static %}
|
||||||
|
|
||||||
|
{% block add_css %}
|
||||||
|
<link href="{% static 'graphic/css/leaflet.css' %}" rel="stylesheet">
|
||||||
|
<link href="{% static 'graphic/css/jquery-ui.css' %}" rel="stylesheet">
|
||||||
|
<link href="{% static 'graphic/css/leaflet.timedimension.control.min.css' %}" rel="stylesheet">
|
||||||
|
<link href="{% static 'graphic/css/timeline2.css' %}" rel="stylesheet">
|
||||||
|
<link href="{% static 'dashboard/css/legend.css' %}" rel="stylesheet">
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
{% block page_head %}干旱指数动态空间变化{% endblock %}
|
||||||
|
{% block breadcrumb %}
|
||||||
|
<li>
|
||||||
|
<a href="{% url 'dashboard-index' %}">首页</a>
|
||||||
|
</li>
|
||||||
|
<li class="active">
|
||||||
|
干旱指数动态空间变化
|
||||||
|
</li>
|
||||||
|
{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<div class="ibox">
|
||||||
|
<div class="ibox-title">
|
||||||
|
<h5>干旱指数动态空间变化</h5>
|
||||||
|
</div>
|
||||||
|
<div class="ibox-content" style="padding: 0; position: relative;">
|
||||||
|
<div id="map" style="width: 100%;height: 800px;">
|
||||||
|
<div class="legend">
|
||||||
|
<img src="http://210.77.68.250:8080/geoserver/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=30&HEIGHT=30&LAYER=baoji:1979-1-spei&STYLE=baoji:spei">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block add_js %}
|
||||||
|
<script type="text/javascript" src="{% static 'graphic/js/jquery-ui.js' %}"></script>
|
||||||
|
<script type="text/javascript" src="{% static 'graphic/js/leaflet.js' %}"></script>
|
||||||
|
<script type="text/javascript" src="{% static 'graphic/js/iso8601.min.js' %}"></script>
|
||||||
|
<script type="text/javascript" src="{% static 'graphic/js/leaflet.ChineseTmsProviders.js' %}"></script>
|
||||||
|
<script type="text/javascript" src="{% static 'graphic/js/leaflet.timedimension.min.js' %}"></script>
|
||||||
|
<script type="text/javascript" src="{% static 'graphic/js/timeline5.js' %}"></script>
|
||||||
|
{% endblock %}
|
|
@ -1,34 +0,0 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
import csv
|
|
||||||
import uuid
|
|
||||||
import os
|
|
||||||
import psycopg2
|
|
||||||
import sqlite3
|
|
||||||
from pip._vendor import chardet
|
|
||||||
|
|
||||||
G2 = 'host=210.77.68.250 port=5432 dbname=drought user=drought password=g214G214'
|
|
||||||
|
|
||||||
|
|
||||||
def insert_administrative(code1, longitude, latitude, year, month, mean_precipitation, mean_temperature):
|
|
||||||
with psycopg2.connect(G2) as connection:
|
|
||||||
with connection.cursor() as cursor:
|
|
||||||
id = uuid.uuid4()
|
|
||||||
cursor.execute(
|
|
||||||
'insert into dashboard_spi (id, code,longitude,latitude,year,month,mean_precipitation,mean_temperature,added,updated) values (%s, %s, %s, %s, %s,%s,%s,%s,now(),now() )',
|
|
||||||
(str(id), code1, longitude, latitude, year, month, mean_precipitation, mean_temperature))
|
|
||||||
connection.commit()
|
|
||||||
return id
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
files = [os.path.join(dp, f) for dp, dn, fn in os.walk(os.path.expanduser("D:/2018/baoji10年数据")) for f in fn]
|
|
||||||
for f in files:
|
|
||||||
if f.endswith('.txt'):
|
|
||||||
with open(f) as csvfile:
|
|
||||||
for line in csvfile.readlines():
|
|
||||||
longitude, latitude, year, month, mean_precipitation, mean_temperature = line.split()
|
|
||||||
code, _ = os.path.splitext(f)
|
|
||||||
code = os.path.basename(code)
|
|
||||||
code1 = 'V7' + code
|
|
||||||
print(code1, longitude, latitude, year, month, mean_precipitation, mean_temperature)
|
|
||||||
insert_administrative(code1, longitude, latitude, year, month, mean_precipitation, mean_temperature)
|
|
|
@ -1,33 +0,0 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
import csv
|
|
||||||
import uuid
|
|
||||||
import os
|
|
||||||
import psycopg2
|
|
||||||
|
|
||||||
from pip._vendor import chardet
|
|
||||||
|
|
||||||
# G1 = 'host=210.77.68.250 port=5432 dbname=g214_test user=g214 password=g214G214'
|
|
||||||
G2 = 'host=210.77.68.250 port=5432 dbname=drought user=drought password=g214G214'
|
|
||||||
|
|
||||||
|
|
||||||
def insert_administrative(name,average_water_level, average_flow_rate):
|
|
||||||
with psycopg2.connect(G2) as connection:
|
|
||||||
with connection.cursor() as cursor:
|
|
||||||
id = uuid.uuid4()
|
|
||||||
cursor.execute(
|
|
||||||
'insert into dashboard_hydro (id, name,date,average_water_level, average_flow_rate,precipitation,added,updated) values (%s, %s, 2016,%s, %s, 0,now(),now() )',
|
|
||||||
(str(id), name,average_water_level, average_flow_rate))
|
|
||||||
connection.commit()
|
|
||||||
return id
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
|
||||||
with open('D:/2018/水位流量.csv') as csvfile:
|
|
||||||
for line in csvfile.readlines():
|
|
||||||
name = '千河千阳湖'
|
|
||||||
average_water_level = line[0:6]
|
|
||||||
average_flow_rate = line[7:11]
|
|
||||||
print(average_flow_rate)
|
|
||||||
|
|
||||||
insert_administrative(name,average_water_level, average_flow_rate)
|
|
|
@ -1,35 +0,0 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
import csv
|
|
||||||
import uuid
|
|
||||||
import os
|
|
||||||
import psycopg2
|
|
||||||
|
|
||||||
from pip._vendor import chardet
|
|
||||||
|
|
||||||
# G1 = 'host=210.77.68.250 port=5432 dbname=g214_test user=g214 password=g214G214'
|
|
||||||
G2 = 'host=210.77.68.250 port=5432 dbname=drought user=drought password=g214G214'
|
|
||||||
|
|
||||||
|
|
||||||
def insert_administrative(name, cultivated_land_area, irrigated_land, eatch_land, eatch_Irrigated_land):
|
|
||||||
with psycopg2.connect(G2) as connection:
|
|
||||||
with connection.cursor() as cursor:
|
|
||||||
id = uuid.uuid4()
|
|
||||||
cursor.execute(
|
|
||||||
'insert into dashboard_landuse(id, name ,date,cultivated_land_area, irrigated_land, eatch_land,eatch_Irrigated_land,added, updated) values (%s, %s, 2016, %s, %s, %s, %s,now(),now() )',
|
|
||||||
(str(id), name, cultivated_land_area, irrigated_land, eatch_land, eatch_Irrigated_land))
|
|
||||||
connection.commit()
|
|
||||||
return id
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
with open('D:/2018/02.csv') as csvfile:
|
|
||||||
reader = csv.reader(csvfile)
|
|
||||||
i = 0
|
|
||||||
for r in reader:
|
|
||||||
name = r[0]
|
|
||||||
cultivated_land_area = r[1]
|
|
||||||
irrigated_land = r[2]
|
|
||||||
eatch_land = r[3]
|
|
||||||
eatch_Irrigated_land = r[4]
|
|
||||||
print(r[0])
|
|
||||||
insert_administrative(name, cultivated_land_area, irrigated_land, eatch_land, eatch_Irrigated_land)
|
|
|
@ -1,40 +0,0 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
import csv
|
|
||||||
import uuid
|
|
||||||
import os
|
|
||||||
import psycopg2
|
|
||||||
|
|
||||||
from pip._vendor import chardet
|
|
||||||
|
|
||||||
# G1 = 'host=210.77.68.250 port=5432 dbname=g214_test user=g214 password=g214G214'
|
|
||||||
G2 = 'host=210.77.68.250 port=5432 dbname=drought user=drought password=g214G214'
|
|
||||||
|
|
||||||
|
|
||||||
def insert_administrative(name,inhabitant, households, registered_population, man,women,natality,fatalities,population_growth,demographic_urbanization):
|
|
||||||
with psycopg2.connect(G2) as connection:
|
|
||||||
with connection.cursor() as cursor:
|
|
||||||
id = uuid.uuid4()
|
|
||||||
cursor.execute(
|
|
||||||
'insert into dashboard_population (id,name,date,inhabitant, households, registered_population, man,women,natality,fatalities,population_growth,demographic_urbanization,added,updated) values (%s, %s, 2016, %s, %s, %s, %s, %s, %s, %s, %s, %s,now(),now() )',
|
|
||||||
(str(id), name,inhabitant, households, registered_population, man,women,natality,fatalities,population_growth,demographic_urbanization))
|
|
||||||
connection.commit()
|
|
||||||
return id
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
with open('D:/2018/04.csv') as csvfile:
|
|
||||||
reader = csv.reader(csvfile)
|
|
||||||
i = 0
|
|
||||||
for r in reader:
|
|
||||||
name = r[0]
|
|
||||||
inhabitant = r[1]
|
|
||||||
households = r[2]
|
|
||||||
registered_population = r[3]
|
|
||||||
man = r[4]
|
|
||||||
women = r[5]
|
|
||||||
natality = r[6]
|
|
||||||
fatalities = r[7]
|
|
||||||
population_growth = r[8]
|
|
||||||
demographic_urbanization = r[9]
|
|
||||||
print(r)
|
|
||||||
insert_administrative(name,inhabitant, households, registered_population, man,women,natality,fatalities,population_growth,demographic_urbanization)
|
|
|
@ -1,53 +0,0 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
import csv
|
|
||||||
import uuid
|
|
||||||
import os
|
|
||||||
import psycopg2
|
|
||||||
|
|
||||||
from pip._vendor import chardet
|
|
||||||
|
|
||||||
# G1 = 'host=210.77.68.250 port=5432 dbname=g214_test user=g214 password=g214G214'
|
|
||||||
G2 = 'host=210.77.68.250 port=5432 dbname=drought user=drought password=g214G214'
|
|
||||||
|
|
||||||
|
|
||||||
def insert_administrative( index, city, municipal_level, city_level, gaoxinqu, district_and_county, taibaixian,
|
|
||||||
chencangqu, fengxiangxian, qishanxian, linyouxian, longxian, qianyangxian, fengxian,
|
|
||||||
fufengxian, meixian, jintaiqu, weibinqu):
|
|
||||||
with psycopg2.connect(G2) as connection:
|
|
||||||
with connection.cursor() as cursor:
|
|
||||||
id = uuid.uuid4()
|
|
||||||
cursor.execute(
|
|
||||||
'insert into dashboard_revenue (id, index,data,city, municipal_level, city_level, gaoxinqu,district_and_county,taibaixian,chencangqu,fengxiangxian,qishanxian,linyouxian,longxian,qianyangxian,fengxian,fufengxian,meixian,jintaiqu,weibinqu,added,updated) values (%s, %s, 2016, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,now(),now() )',
|
|
||||||
(str(id), index, city, municipal_level, city_level, gaoxinqu, district_and_county, taibaixian,
|
|
||||||
chencangqu, fengxiangxian, qishanxian, linyouxian, longxian, qianyangxian, fengxian, fufengxian,
|
|
||||||
meixian, jintaiqu, weibinqu))
|
|
||||||
connection.commit()
|
|
||||||
return id
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
with open('D:/2018/03.csv') as csvfile:
|
|
||||||
reader = csv.reader(csvfile)
|
|
||||||
i = 0
|
|
||||||
for r in reader:
|
|
||||||
index = r[0]
|
|
||||||
city = r[1]
|
|
||||||
municipal_level = r[2]
|
|
||||||
city_level = r[3]
|
|
||||||
gaoxinqu = r[4]
|
|
||||||
district_and_county = r[5]
|
|
||||||
taibaixian = r[6]
|
|
||||||
chencangqu = r[7]
|
|
||||||
fengxiangxian = r[8]
|
|
||||||
qishanxian = r[9]
|
|
||||||
linyouxian = r[10]
|
|
||||||
longxian = r[11]
|
|
||||||
qianyangxian = r[12]
|
|
||||||
fengxian = r[13]
|
|
||||||
fufengxian = r[14]
|
|
||||||
meixian = r[15]
|
|
||||||
jintaiqu = r[16]
|
|
||||||
weibinqu = r[17]
|
|
||||||
|
|
||||||
print(r)
|
|
||||||
insert_administrative( index,city, municipal_level, city_level, gaoxinqu,district_and_county,taibaixian,chencangqu,fengxiangxian,qishanxian,linyouxian,longxian,qianyangxian,fengxian,fufengxian,meixian,jintaiqu,weibinqu)
|
|
|
@ -1,34 +0,0 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
import csv
|
|
||||||
import uuid
|
|
||||||
import os
|
|
||||||
import psycopg2
|
|
||||||
import sqlite3
|
|
||||||
from pip._vendor import chardet
|
|
||||||
|
|
||||||
G2 = 'host=210.77.68.250 port=5432 dbname=drought user=drought password=g214G214'
|
|
||||||
|
|
||||||
|
|
||||||
def insert_administrative(code1, year, month, value):
|
|
||||||
with psycopg2.connect(G2) as connection:
|
|
||||||
with connection.cursor() as cursor:
|
|
||||||
id = uuid.uuid4()
|
|
||||||
cursor.execute(
|
|
||||||
'insert into policy_droughtspi (id, code,year,month, value,added,updated) values (%s, %s, %s, %s, %s,now(),now() )',
|
|
||||||
(str(id), code1, year, month, value))
|
|
||||||
connection.commit()
|
|
||||||
return id
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
files = [os.path.join(dp, f) for dp, dn, fn in os.walk(os.path.expanduser("D:/2018/spi/spi")) for f in fn]
|
|
||||||
for f in files:
|
|
||||||
if f.endswith('.txt'):
|
|
||||||
with open(f) as csvfile:
|
|
||||||
for line in csvfile.readlines()[1:]:
|
|
||||||
year, month, value = line.split()
|
|
||||||
code, _ = os.path.splitext(f)
|
|
||||||
code = os.path.basename(code)
|
|
||||||
code1 = 'V7' + code
|
|
||||||
print(code1,value,year,month)
|
|
||||||
insert_administrative(code1, year, month, value)
|
|
|
@ -9,5 +9,6 @@ urlpatterns = [
|
||||||
path('drought/spi/chart/', views.drought_spi_chart, name='policy-drought-spi-chart'),
|
path('drought/spi/chart/', views.drought_spi_chart, name='policy-drought-spi-chart'),
|
||||||
path('drought/spi.json', views.drought_spi_json, name='policy-drought-spi-json'),
|
path('drought/spi.json', views.drought_spi_json, name='policy-drought-spi-json'),
|
||||||
path('timeline4/', views.timeline4, name='policy-timeline4'),
|
path('timeline4/', views.timeline4, name='policy-timeline4'),
|
||||||
|
path('timeline5/', views.timeline5, name='policy-timeline5'),
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -42,6 +42,10 @@ def drought_spi_chart(request):
|
||||||
def timeline4(request):
|
def timeline4(request):
|
||||||
return render(request, 'graphic/timeline4.html')
|
return render(request, 'graphic/timeline4.html')
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def timeline5(request):
|
||||||
|
return render(request, 'graphic/timeline5.html')
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def drought_spi_json(request):
|
def drought_spi_json(request):
|
||||||
code = request.GET.get('code')
|
code = request.GET.get('code')
|
||||||
|
|
|
@ -3,4 +3,4 @@ from django.shortcuts import render
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
return render(request, 'portal/base.html')
|
return render(request, 'dashboard/index.html')
|
|
@ -11,3 +11,4 @@ pandas
|
||||||
geopandas
|
geopandas
|
||||||
rasterio
|
rasterio
|
||||||
django-cors-headers
|
django-cors-headers
|
||||||
|
xlrd
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue