1
1
import pandas as pd
2
2
from suncalc import get_times
3
+ from shapely .geometry import MultiPolygon
4
+ import transbigdata as tbd
5
+ import geopandas as gpd
3
6
from .pybdshadow import (
4
7
bdshadow_sunlight ,
5
8
)
6
9
from .preprocess import bd_preprocess
7
- # 生成时间表
8
- def get_timetable (lon , lat , dates = ['2022-01-01' ], gap = 3600 , padding = 1800 ):
9
10
11
+
12
+ def get_timetable (lon , lat , dates = ['2022-01-01' ], gap = 3600 , padding = 1800 ):
13
+ # generate timetable
10
14
def get_timeSeries (day , lon , lat , gap = 3600 , padding = 1800 ):
11
15
date = pd .to_datetime (day + ' 12:45:33.959797119' )
12
16
times = get_times (date , lon , lat )
@@ -27,6 +31,33 @@ def get_timeSeries(day, lon, lat, gap=3600, padding=1800):
27
31
28
32
def cal_sunshadows (buildings , cityname = 'somecity' , dates = ['2022-01-01' ], gap = 3600 ,
29
33
roof = True , include_building = True ,save_shadows = False ,printlog = False ):
34
+ '''
35
+ Calculate the sunlight shadow in different date with given time gap.
36
+
37
+ **Parameters**
38
+
39
+ buildings : GeoDataFrame
40
+ Buildings. coordinate system should be WGS84
41
+ cityname : string
42
+ Cityname. If save_shadows, this function will create `result/cityname` folder to save the shadows
43
+ dates : list
44
+ list of dates
45
+ gap : number
46
+ time gap(s)
47
+ roof : bool
48
+ whether to calculate roof shadow.
49
+ include_building : bool
50
+ whether the shadow include building outline
51
+ save_shadows : bool
52
+ whether to save calculated shadows
53
+ printlog : bool
54
+ whether to print log
55
+
56
+ **Return**
57
+
58
+ allshadow : GeoDataFrame
59
+ All building shadows calculated
60
+ '''
30
61
# 获取城市位置
31
62
lon , lat = buildings ['geometry' ].iloc [0 ].bounds [:2 ]
32
63
timetable = get_timetable (lon , lat , dates , gap )
@@ -61,10 +92,30 @@ def cal_sunshadows(buildings, cityname='somecity', dates=['2022-01-01'], gap=360
61
92
allshadow = pd .concat (allshadow )
62
93
return allshadow
63
94
64
- from shapely .geometry import MultiPolygon
65
- import transbigdata as tbd
66
- import geopandas as gpd
67
- def cal_shadowduration (shadows_input ,buildings ,roof = True ,gap = 3600 ,accuracy = 1 ):
95
+
96
+ def cal_shadowcoverage (shadows_input ,buildings ,roof = True ,gap = 3600 ,accuracy = 1 ):
97
+ '''
98
+ Calculate the sunlight shadow coverage time for given area.
99
+
100
+ **Parameters**
101
+
102
+ shadows_input : GeoDataFrame
103
+ All building shadows calculated
104
+ buildings : GeoDataFrame
105
+ Buildings. coordinate system should be WGS84
106
+ roof : bool
107
+ If true roof shadow, false then ground shadow
108
+ gap : number
109
+ time gap(s), which is for calculation of coverage time
110
+ accuracy : number
111
+ size of grids.
112
+
113
+ **Return**
114
+
115
+ bdgrids : GeoDataFrame
116
+ grids generated by TransBigData in study area, each grids have a `time` column store the shadow coverage time
117
+
118
+ '''
68
119
shadows = bd_preprocess (shadows_input )
69
120
if roof :
70
121
ground_shadows = shadows [shadows ['type' ]== 'roof' ].groupby (['date' ])['geometry' ].apply (
0 commit comments