2018-11-11 14:22:57 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
import mplleaflet
|
|
|
|
import fetch
|
2018-11-11 17:31:27 +01:00
|
|
|
from tqdm import tqdm
|
|
|
|
import time
|
|
|
|
import math
|
|
|
|
def circlepolygon(radius, center, resolution=20):
|
|
|
|
points=[[center[0] + math.cos(((2*math.pi)/resolution)*i)*radius*1.15, center[1] + math.sin(((2*math.pi)/resolution)*i)*radius] for i in range(resolution)]
|
|
|
|
return points
|
2018-11-11 18:20:58 +01:00
|
|
|
def genplot(diclist, resolution=150):
|
2018-11-11 17:31:27 +01:00
|
|
|
for area in tqdm(diclist, ncols=50):
|
2018-11-11 14:22:57 +01:00
|
|
|
for figure in area['zone']:
|
|
|
|
if figure[0] == 'cercle' :
|
2018-11-11 17:31:27 +01:00
|
|
|
xcoords,ycoords=[],[]
|
2018-11-11 18:20:58 +01:00
|
|
|
for xaxis,yaxis in circlepolygon(figure[1]/100000, figure[2::], resolution=resolution):
|
2018-11-11 17:31:27 +01:00
|
|
|
xcoords.append(xaxis)
|
|
|
|
ycoords.append(yaxis)
|
|
|
|
xcoords.append(xcoords[0])
|
|
|
|
ycoords.append(ycoords[0])
|
|
|
|
plt.plot(xcoords,ycoords,'b')
|
|
|
|
plt.plot(figure[2],figure[3],'rs')
|
|
|
|
plt.fill(xcoords,ycoords,'g')
|
2018-11-11 14:22:57 +01:00
|
|
|
else:
|
|
|
|
xcoords,ycoords=[],[]
|
|
|
|
for xaxis,yaxis in figure:
|
|
|
|
xcoords.append(xaxis)
|
|
|
|
ycoords.append(yaxis)
|
|
|
|
xcoords.append(xcoords[0])
|
|
|
|
ycoords.append(ycoords[0])
|
|
|
|
plt.plot(xcoords,ycoords,'b')
|
2018-11-11 18:20:58 +01:00
|
|
|
plt.plot(sum(xcoords)/len(xcoords),sum(ycoords)/len(ycoords),'rs')
|
2018-11-11 14:22:57 +01:00
|
|
|
plt.fill(xcoords,ycoords,'g')
|
|
|
|
return plt
|
2018-11-11 17:31:27 +01:00
|
|
|
|
2018-11-11 14:22:57 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2018-11-11 17:31:27 +01:00
|
|
|
genplot(fetch.fetch())
|
2018-11-11 14:22:57 +01:00
|
|
|
mplleaflet.show()
|