代码拉取完成,页面将自动刷新
import pandas as pd
import json
from pyproj import Proj
from math import ceil, sqrt
# 建筑工地CSV通过json模板转为json形式
def wgs84toutm(lon, lat):
'''
:param lon:
:param lat:
:return:UTM投影带号和相应UTM坐标,及相对距离坐标
'''
zone = ceil((lon + 180) / 6.0000001)
utm_pj = Proj("+proj=utm +zone=" + str(zone) + ", +ellps=WGS84 +datum=WGS84 +units=m +no_defs")
utm_x, utm_y = utm_pj(lon, lat, inverse=False) # 从经纬度转平面坐标
return zone, utm_x, utm_y
def wgs84toutm_reverse(zone, utm_x, utm_y):
'''
:param lon:
:param lat:
:return:UTM投影带号和相应UTM坐标,及相对距离坐标
'''
# zone = ceil((lon + 180) / 6.0000001)
utm_pj = Proj("+proj=utm +zone=" + str(zone) + ", +ellps=WGS84 +datum=WGS84 +units=m +no_defs")
lon, lat = utm_pj(utm_x, utm_y, inverse=True) # 从经纬度转平面坐标
return lon, lat
def get_locationX_locationY(lon_center, lat_center, area):
'''
求正方形建组工地的经纬度范围
:param lon_center: 中心经度
:param lat_center: 中心纬度
:param area: 面积
:return: 经纬度范围列表
'''
# 1.求中心经纬度对应的x和y
zone, utm_x, utm_y = wgs84toutm(lon_center, lat_center)
# 2.求四个角的x和y
print(utm_x, utm_y)
# 将建筑工地看似一个正方形
side_length = sqrt(area)
utm_x1 = utm_x - side_length / 2
utm_x2 = utm_x - side_length / 2
utm_x3 = utm_x + side_length / 2
utm_x4 = utm_x + side_length / 2
utm_y1 = utm_y - side_length / 2
utm_y2 = utm_y + side_length / 2
utm_y3 = utm_y + side_length / 2
utm_y4 = utm_y - side_length / 2
# 3.求四个角的经纬度
lon1, lat1 = wgs84toutm_reverse(zone, utm_x1, utm_y1)
lon2, lat2 = wgs84toutm_reverse(zone, utm_x2, utm_y2)
lon3, lat3 = wgs84toutm_reverse(zone, utm_x3, utm_y3)
lon4, lat4 = wgs84toutm_reverse(zone, utm_x4, utm_y4)
# 4.整理结果返回
locationx = [lon1, lon2, lon3, lon4, lon1]
locationy = [lat1, lat2, lat3, lat4, lat1]
for i in range(len(locationx)):
locationx[i] = round(locationx[i], 6)
locationy[i] = round(locationy[i], 6)
return locationx, locationy
# 建筑工地面源csv转json
def csv_to_json(csv_path, json_path, json_back_path, relhgt, szinit):
'''
由确定好字段的建筑工地json模板,生成有具体建筑工地信息的json
:param csv_path: 建筑工地信息的csv
:param json_path: 生成有具体建筑工地信息的json的路径
:param json_back_path: 确定好字段的建筑工地json模板的路径
relhgt # 排放离地高度 m
szinit # 面源烟羽的初始垂直尺度 m
:return:
'''
with open(json_back_path, 'r', encoding='utf-8') as f:
d = json.loads(f.read())
print(d['project_data']['basedata']['sources'])
print(d['project_data']['basedata']['emissionCase'][0]['select_Source'])
print(d['project_data']['basedata']['emissionCase'][0]['select_Source_ID'])
sources = []
select_Source = []
select_Source_ID = []
df = pd.read_csv(csv_path)
for i in range(df.shape[0]):
print(df.iloc[i, :])
sr = df.iloc[i, :]
source = {}
project_name = sr['项目名称']
lon_center = sr['中心经度']
lat_center = sr['中心纬度']
area = sr['建筑施工面积(平方米)']
tsp = sr['排放强度 kg/h']
locationX, locationY = get_locationX_locationY(lon_center, lat_center, area)
source['name'] = project_name
source['ID'] = i + 1
source["type"] = "AREAPOLY"
source['locationY'] = locationY
source['locationX'] = locationX
source["pollutant_unit"] = "kg/h"
pollutants = {}
pollutants['TSP'] = round(tsp, 7)
source["pollutants"] = pollutants
source["Relhgt"] = relhgt
source["Szinit"] = szinit
sources.append(source)
select_Source.append(project_name)
select_Source_ID.append(i + 1)
d['project_data']['basedata']['sources'] = sources
d['project_data']['basedata']['emissionCase'][0]['select_Source'] = select_Source
d['project_data']['basedata']['emissionCase'][0]['select_Source_ID'] = select_Source_ID
with open(json_path, 'w', encoding='utf-8') as f:
f.write(json.dumps(d, ensure_ascii=False))
# 工业点源csv转json
def csv_to_json_point(csv_path, json_path, json_back_path, stkvel, stkdia, stktmp, stkhat):
with open(json_back_path, 'r', encoding='utf-8') as f:
d = json.loads(f.read())
print(d['project_data']['basedata']['sources'])
print(d['project_data']['basedata']['emissionCase'][0]['select_Source'])
print(d['project_data']['basedata']['emissionCase'][0]['select_Source_ID'])
sources = []
select_Source = []
select_Source_ID = []
df = pd.read_csv(csv_path)
for i in range(df.shape[0]):
print(df.iloc[i, :])
sr = df.iloc[i, :]
source = {}
project_name = sr['企业']
lon_center = round(sr['经度'], 7)
lat_center = round(sr['纬度'], 7)
tsp = sr['小时排放量(kg/h)']
source['name'] = project_name
source['ID'] = i + 1
source['Stkvel'] = stkvel
source['Stkdia'] = stkdia
source["type"] = "POINT"
source['heat_loss'] = ""
source['emiss_units'] = "---------- 要求单位是 kg/h ,与onesky 一致"
pollutants = {}
pollutants['SO2'] = round(tsp, 7)
source["pollutants"] = pollutants
source["totle_heat_release"] = ""
source["emission_condition"] = "normal"
source["emission_hours_num"] = 8760
source["Stktmp"] = stktmp
source["location"] = [lon_center, lat_center]
source["Stkhat"] = stkhat
sources.append(source)
select_Source.append(project_name)
select_Source_ID.append(i + 1)
d['project_data']['basedata']['sources'] = sources
d['project_data']['basedata']['emissionCase'][0]['select_Source'] = select_Source
d['project_data']['basedata']['emissionCase'][0]['select_Source_ID'] = select_Source_ID
with open(json_path, 'w', encoding='utf-8') as f:
f.write(json.dumps(d, ensure_ascii=False))
if __name__ == '__main__':
# # 建筑工地面源
# relhgt = 2.0 # 排放离地高度 m
# szinit = 4.0 # 面源烟羽的初始垂直尺度 m
# csv_path = r'D:\PycharmProjects\aermod\real_time\aermod_stastic\datong\大同建筑工地清单-规整2.csv'
# json_path = r'D:\PycharmProjects\aermod\real_time\aermod_stastic\datong\datong_jianzhu.json'
# json_back_path = r'D:\PycharmProjects\aermod\real_time\aermod_stastic\datong\datong_jianzhu_back.json'
# csv_to_json(csv_path, json_path, json_back_path, relhgt, szinit)
# # get_locationY_locationX(104.132, 30.7273, 251794)
# print(get_locationX_locationY(114.835208, 34.798364, 400000000))
# 工业点源
stkvel, stkdia, stktmp, stkhat = 10, 6, 100, 80.0
csv_path = r'D:\PycharmProjects\aermod\real_time\aermod_stastic\datong\大同主要工业企业排放-30km以内-top50.csv'
json_path = r'D:\PycharmProjects\aermod\real_time\aermod_stastic\datong\datong_point.json'
json_back_path = r'D:\PycharmProjects\aermod\real_time\aermod_stastic\datong\datong_gongye_back.json'
csv_to_json_point(csv_path, json_path, json_back_path, stkvel, stkdia, stktmp, stkhat)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。