Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ni1o1 committed Apr 18, 2022
1 parent b3dea1f commit cecf76e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 43 deletions.
22 changes: 14 additions & 8 deletions src/pybdshadow/pybdshadow.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ def bdshadow_sunlight(buildings, date, height='height', roof=False,include_buil
ground_shadow['type'] = 'ground'

if not roof:
if not include_building:
#从地面阴影裁剪建筑轮廓
ground_shadow = gdf_difference(ground_shadow,buildings)
return ground_shadow
else:
def calwall_shadow(walldata, building):
Expand Down Expand Up @@ -204,14 +207,17 @@ def calwall_shadow(walldata, building):
building_roof = building_roof[-building_roof['geometry'].is_empty]

roof_shadows.append(building_roof)

roof_shadow = pd.concat(roof_shadows)[
['height', 'building_id', 'geometry']]
roof_shadow['type'] = 'roof'

#从地面阴影裁剪建筑轮廓
ground_shadow = gdf_difference(ground_shadow,buildings)

if len(roof_shadows) == 0:
roof_shadow = gpd.GeoDataFrame()
else:
roof_shadow = pd.concat(roof_shadows)[
['height', 'building_id', 'geometry']]
roof_shadow['type'] = 'roof'

if not include_building:
#从地面阴影裁剪建筑轮廓
ground_shadow = gdf_difference(ground_shadow,buildings)

shadows = pd.concat([roof_shadow, ground_shadow])
shadows.crs = None
shadows['geometry'] = shadows.buffer(0.000001).buffer(-0.000001)
Expand Down
60 changes: 33 additions & 27 deletions src/pybdshadow/tests/test_pybdshadow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,49 @@

class Testpybdshadow:
def test_bdshadow_sunlight(self):

buildings = gpd.GeoDataFrame({
'height': [42],
'height': [42, 9],
'geometry': [
Polygon([(139.698311, 35.533796),
(139.698311,
35.533642),
(139.699075,
35.533637),
(139.699079,
35.53417),
(139.698891,
35.53417),
(139.698888,
35.533794),
(139.698311, 35.533796)])]})
date = pd.to_datetime('2015-01-01 02:45:33.959797119')
(139.698311,
35.533642),
(139.699075,
35.533637),
(139.699079,
35.53417),
(139.698891,
35.53417),
(139.698888,
35.533794),
(139.698311, 35.533796)]),
Polygon([(139.69799, 35.534175),
(139.697988, 35.53389),
(139.698814, 35.533885),
(139.698816, 35.534171),
(139.69799, 35.534175)])]})
date = pd.to_datetime('2015-01-01 03:45:33.959797119')

buildings = pybdshadow.bd_preprocess(buildings)

buildingshadow = pybdshadow.bdshadow_sunlight(
buildings, date)
buildings, date, roof=True, include_building=False)

area = buildingshadow['geometry'].iloc[0]
area = np.array(area.exterior.coords)
truth = np.array([[139.698311, 35.533796],
[139.69831102, 35.533796],
[139.69831102, 35.533796],
[139.69831239, 35.53429879],
[139.69888939, 35.53429679],
[139.69889239, 35.53467279],
[139.69908039, 35.53467279],
[139.69907902, 35.53417],
[139.69907502, 35.533637],
[139.699075, 35.533637],
[139.699075, 35.533637],
[139.698311, 35.533642],
[139.698311, 35.533796]])
truth = np.array([(139.6983434498457, 35.53388784954066),
(139.698343456533, 35.533887872006716),
(139.6984440527688, 35.53417277873741),
(139.69844406145836, 35.534172800060766),
(139.69844408446318, 35.534172801043766),
(139.69881597541797, 35.534171000119045),
(139.69881599883948, 35.53417099885312),
(139.6988159998281, 35.53417097541834),
(139.69881400017155, 35.533885024533475),
(139.6988139988598, 35.53388500115515),
(139.69881397546646, 35.53388500014851),
(139.69834347324914, 35.53388784822488),
(139.6983434498457, 35.53388784954066)])
assert np.allclose(area, truth)

pybdshadow.show_bdshadow(buildings=buildings,
Expand Down
17 changes: 9 additions & 8 deletions src/test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 81,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -25,7 +25,7 @@
},
{
"cell_type": "code",
"execution_count": 82,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -37,7 +37,7 @@
},
{
"cell_type": "code",
"execution_count": 83,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -65,11 +65,12 @@
"\n",
"#地面阴影\n",
"\n",
"shadows.plot(ax = ax,alpha = 0.7,\n",
"column = 'type', \n",
"categorical=True, \n",
"cmap='Set1_r', \n",
"legend=True)\n",
"shadows.plot(ax = ax,\n",
" alpha = 0.7,\n",
" column = 'type', \n",
" categorical=True, \n",
" cmap='Set1_r', \n",
" legend=True)\n",
"\n",
"plt.show()"
]
Expand Down

0 comments on commit cecf76e

Please sign in to comment.