


Our social networks
Facebook: https://www.facebook.com/Safe-food-100587511688183
Twitter: https://twitter.com/safefood9?s=09



| importrandom | |
| fromMapCreator.MapFuncsimportgenerate_map | |
| #Random' coordinates near the central point. | |
| defrandom_acot_point(point, n): | |
| points= [(point[0]+random.randrange(1, 2*n)/10, point[1]+random.randrange(1, 2*n)/10) for_inrange(n)] | |
| points=tuple(set(points)) | |
| returnpoints | |
| #Sequential and random node connection. | |
| defaleatore_nodes(points, n): | |
| nodes= [*zip(points, (points[-1],)+points[:-1])] | |
| for_inrange(n): | |
| nodes.append((*random.choices(points), *random.choices(points))) | |
| returntuple(nodes) | |
| if__name__=='__main__': | |
| #Central test point. | |
| punto= (41.257160, -95.995102) | |
| points=random_acot_point(punto, 15) | |
| nodes=aleatore_nodes(points, 1) | |
| #test | |
| generate_map(punto, points, nodes, 'Test') |

| classMapSafeFood: | |
| MAP_TYPE=folium.Map | |
| ZOOM=10 | |
| TILES='Stamen Terrain' | |
| POINT_ICON='cloud' | |
| POINT_COLOR='red' | |
| ICON_CONFIG= {'icon': POINT_ICON, | |
| 'color': POINT_COLOR} | |
| POPUP_TEXT='Non Data' | |
| TOOLTIP_TEXT='Information' | |
| LINES_COLOR='darkblue' | |
| N_ARROWS=3 | |
| ARROWS_COLOR='black' | |
| ARROWS_FILL_COLOR='darkred' | |
| ARROWS_SIDES=3 | |
| ARROWS_SIZE=10 | |
| def__init__(self, location:tuple, zoom_start:int=ZOOM, tiles:str=TILES, **options) ->None: | |
| #We locate the map, and give them an initial design and zoom. | |
| self.__mapp=folium.Map(location=location, zoom_start=zoom_start, tiles=tiles, **options) | |
| defadd_points(self, points:list , popup:str=POPUP_TEXT, tooltip:str=TOOLTIP_TEXT, | |
| icon_config:dict=ICON_CONFIG, **options) ->None: | |
| #Points, icon, message on mouse over, and click. | |
| forpointinpoints: | |
| folium.Marker(point, | |
| popup=popup, | |
| tooltip=tooltip, | |
| icon=folium.Icon(**icon_config), | |
| **options).add_to(self.__mapp) | |
| defadd_lines(self, line:tuple, color:str=LINES_COLOR, **options) ->None: | |
| folium.PolyLine(line, color=color, **options).add_to(self.__mapp) | |
| #Ajustar la rotación. | |
| defadd_arrows(self, line:tuple, n_arrows:int=N_ARROWS, color:str=ARROWS_COLOR, | |
| fill_color:str=ARROWS_FILL_COLOR, number_of_sides:int=ARROWS_SIDES, | |
| radius:int=ARROWS_SIZE, **options) ->None: | |
| #n number of halfway arrows, (x, y) | |
| loc_arrows=zip(np.linspace(line[0][0], line[1][0], n_arrows+2)[1:n_arrows+1], | |
| np.linspace(line[0][1], line[1][1], n_arrows+2)[1:n_arrows+1]) | |
| #The rotated arrow following the direction of the origin line. | |
| rotation=self.concordant_rotation(line[0], line[1]) -90 | |
| #We plot the triangles/arrows | |
| forloc_arrowinloc_arrows: | |
| folium.RegularPolygonMarker(location=loc_arrow, color=color, fill_color=fill_color, | |
| number_of_sides=number_of_sides, radius=radius, rotation=rotation, **options | |
| ).add_to(self.__mapp) | |
| #The options in this case is a dictionary with the options of lines and arrows | |
| defadd_arrows_lines(self, lines:tuple, **options) ->None: | |
| forlineinlines: | |
| self.add_lines(line, **options.get('line', {})) | |
| self.add_arrows(line, **options.get('arrow', {})) | |
| #We saved the map in HTML format | |
| defsave(self, name:str) ->None: | |
| self.__mapp.save(f'{name}.html') | |
| #Getter of the map. | |
| @property | |
| defget_map(self) ->folium.Map: | |
| returnself.__mapp | |
| @staticmethod | |
| defconcordant_rotation(p1, p2): | |
| #Based on https://gist.github.com/jeromer/2005586 | |
| long_diff=np.radians(p2[1] -p1[1]) | |
| lat1=np.radians(p1[0]) | |
| lat2=np.radians(p2[0]) | |
| x=np.sin(long_diff) *np.cos(lat2) | |
| y= (np.cos(lat1) *np.sin(lat2) | |
| - (np.sin(lat1) *np.cos(lat2) | |
| *np.cos(long_diff))) | |
| bearing=np.degrees(np.arctan2(x, y)) | |
| #Adjusting for compass bearing | |
| ifbearing<0: | |
| returnbearing+360 | |
| returnbearing |
| limits= [] | |
| manager=multiprocessing.Manager() | |
| queue=manager.Queue() | |
| thr_rows=threading.Thread(target=limit_max, args=('1000', '0')) #rows | |
| thr_column=threading.Thread(target=limit_max, args=('0', '1000')) #columns | |
| thr_rows.start() | |
| thr_column.start() | |
| matrix_base(15, 50) | |
| thr_rows.join() | |
| thr_column.join() | |
| limits.sort() | |
| pro1=multiprocessing.Process(target=download_set, args=(queue, limits) ) | |
| pro1.start() | |
| pro2=multiprocessing.Process(target=download_set, args=(queue, limits)) | |
| pro2.start() | |
| pro1.join() | |
| pro2.join() | |
| join_mosaic('Total') | |





