-
Notifications
You must be signed in to change notification settings - Fork 9
/
map_solar_panel_v20180712.py
172 lines (141 loc) · 5.33 KB
/
map_solar_panel_v20180712.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#! /usr/bin/env python
import datetime
import os
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as pltcol
import pandas as pd
Fread= True #False
Mapprov=True
Mapall= False
Mapcluster = False
if Fread:
opath='/home/bigdata07/DeepSol/fig/'
ipath= '/home/bigdata07/DeepSol/data/'
fadd= 'bag-adressen-v20180610.csv' #'inspireadressen.csv'
df_add= pd.read_csv(os.path.join(ipath,fadd),sep=';')
fpir='solarpanels.csv'
df_pir= pd.read_csv(os.path.join(ipath,fpir),sep=',', header=None, names=['postcode','huisnummer','Idate'])
df_pir['huisletter'] = df_pir.huisnummer.str.split('-').str.get(1)
df_pir['huisnummer'] = df_pir.huisnummer.str.split('-').str.get(0)
df_pir['huisnummer'] = df_pir.huisnummer.str.split(' ').str.get(0)
df_pir['huisnummer'] = df_pir['huisnummer'].astype(np.int64)
df_pir['Idate']= pd.to_datetime(df_pir['Idate'],format='%Y%m%d', errors='coerce')
#endif
df_PV = df_pir.merge(df_add, how='inner', on=['postcode', 'huisnummer','huisletter'] )
if Mapcluster:
import folium
from folium.plugins import MarkerCluster
from folium.plugins import FeatureGroupSubGroup
from folium.features import CustomIcon
from folium.plugins import BoatMarker
print(folium.__version__)
def coldef(iyear):
coldict = {2010:'red', 2011:'blue',
2012:'cadet blue',2013:'darkred',
2014:'lightred',2015:'orange',
2016:'lightgreen',2017:'darkblue',
2018:'lightblue',2019:'purple',
2020:'darkpurple'}
try:
colval = coldict[iyear]
except:
colval = 'lightgray'
return colval
colormap = bcm.linear.Set3.scale(2010,2020)
macarte = folium.Map(location=[51.437,5.478], zoom_start=8)
mc = MarkerCluster()
#creating sub-group for each year
for iyear in np.unique(df_PV['Idate'].dt.year):
eval('g'+iyear+' = FeatureGroupSubGroup(mcg, '+str(iyear)+')')
#creating a Marker for each point in df_sample. Each point will get a popup with their zip
for index,row in df_PV[df_PV['Idate'].dt.year==iyear].iterrows():
mc.add_child(folium.CircleMarker(
location =[row['lat'], row['lon']],
radius=5,
color= colormap(int(row['Idate'].year)),
fill=True,fill_color=colormap(int(row['Idate'].year)),
fill_opacity=0.7,
popup=str(row['Idate'])))
macarte.add_child(mc)
htmlname = '../html/macarte_clusters.html'
macarte.save(htmlname)
if Mapall:
# the amout of PV is too high to render correctly so
#for all NL plot data aggreagted per gemeente of year of installation.
import folium
import branca.colormap as bcm
import matplotlib.mlab as mlab
from mpl_toolkits.basemap import Basemap
import geopandas
coldict = df_PV.groupby('gemeente').count().huisnummer
colormap=bcm.linear.Set3.scale(coldict.min(),coldict.max())
def coldef(GM_NAAM):
try:
colval = colormap(coldict.loc[GM_NAAM])
except:
print ('no solar panels in:',GM_NAAM )
colval = 'lightgrey'
# ok
return colval
gem_shp = geopandas.read_file('/home/bigdata07/DataMatch/gem_2017.shp' )
gem_shp.crs
gem_shp.index = gem_shp.GM_NAAM
gem_shp = gem_shp[['GM_NAAM','geometry']]
gem_ll = gem_shp.to_crs(epsg=4326)
gem_json = gem_ll.to_json(na='drop')
macarte = folium.Map(location=[gem_shp.crs['lat_0'],gem_shp.crs['lon_0']], zoom_start=8)
folium.GeoJson(
gem_json,
style_function=lambda feature: {
'fillColor': coldef(feature['id']),
'color': 'black',
'weight': 1,
'dashArray': '5, 5',
'fillOpacity': 0.9,
}
).add_to(macarte)
colormap.caption = 'aantal PV'
macarte.add_child(colormap)
macarte.save('macarte_nederland.html')
#shafile location=> \\cbsp.nl\Productie\Secundair\GEODATA\Output\Cartografie check for provincie shapefile.
#endif
if Mapprov:
import folium
import branca.colormap as bcm
from folium.plugins import MarkerCluster
import geopandas
import os.path
print(folium.__version__)
opath ='/home/bigdata07/DeepSol/html/'
ipath ='/home/bigdata07/shpfile/'
fname='pv_2018.shp'
pv_shp = geopandas.read_file(os.path.join(ipath,fname))
pv_shp.crs
pv_shp.index = pv_shp.PV_NAAM
pv_ll = pv_shp.to_crs(epsg=4326)
map_loc = pv_ll.centroid
colormap = bcm.linear.Set3.scale(2010,2020)
for iprov in np.unique(df_PV.provincie):
temp = df_PV[df_PV.provincie == iprov]
macarte = folium.Map(location=[map_loc[iprov].coords[0][1],map_loc[iprov].coords[0][0]], zoom_start=10)
mc = MarkerCluster()
# mark each station as a point
for index, row in temp.iterrows():
try:
mc.add_child(folium.CircleMarker([row['lat'], row['lon']],
radius=5,
color= colormap(int(row['Idate'].year)),
fill=True,fill_color=colormap(int(row['Idate'].year)),
fill_opacity=0.7,
popup=str(row['Idate'])))
except:
print('Got an exception')
print (row)
macarte.add_child(mc)
colormap.caption = 'Installation Date'
macarte.add_child(colormap)
htmlname = 'macarte_'+ iprov+ '.html'
macarte.save(os.path.join(opath,htmlname))
#iprov
#eof