Plotting points with folium excel
Production content
- Mapping of points obtained from weather station information
- Special labeling of a particular point
- Data sources
#!/usr/bin/env python # -*- coding: utf-8 -*- # @File : # @Author: huifer # @Date : 2018/6/28 import pandas as pd import math import folium def degree_conversion_decimal(x): """ Convert degree minutes to decimal :param x: float :return: integer float """ integer = int(x) integer = integer + (x - integer) * 1.66666667 return integer def distance(origin, destination): """ Calculate the distance between two points in latitude and longitude :param origin. :param destination. :return. """ lat1, lon1 = origin lat2, lon2 = destination radius = 6371 # km dlat = (lat2 - lat1) dlon = (lon2 - lon1) a = (dlat / 2) * (dlat / 2) + ((lat1)) \ * ((lat2)) * (dlon / 2) * (dlon / 2) c = 2 * math.atan2((a), (1 - a)) d = radius * c return d # Data preparation data = pd.read_excel('SURF_CHN_MUL_HOR_STATION.xlsx') # Modify to decimal and retain one decimal place # data['Longitude'] = data['Longitude'].apply(degree_conversion_decimal) data['Latitude'] = data['Latitude'].apply(degree_conversion_decimal) data['Observation site elevation (meters)'] = data['Observation site elevation (meters)'].apply(lambda x: round(x, 1)) data['Barometric sensor altitude above sea level (meters)'] = data['Barometric sensor altitude above sea level (meters)'].apply(lambda x: round(x, 1)) # Save new documents # data.to_csv('weather station information decimal.csv') data["Distance to Hangzhou(km)"] = (lambda r: distance((r['Latitude'], r['Longitude']), (30.14, 120.1)), axis=1) # print(data[data['Distance to Hangzhou (km)']<100].sort_values('Distance to Hangzhou (km)')) # Select content other than Hangzhou selected_st = data[data['Distance to Hangzhou(km)'] < 100].sort_values('Distance to Hangzhou(km)').iloc[1::] # Display maps # Extract data hzdata = [data['Station name'] == 'Hangzhou', ['Station name', 'Latitude', 'Longitude']] myMap = (location=[[0]['Latitude'], [0]['Longitude']]) icon_hz = dict( prefix='fa', color='red', icon_color='darkred', icon='cny' ) icon = (**icon_hz) ( location=[[0]['Latitude'], [0]['Longitude']], popup="Hangzhou", icon=icon ).add_to(myMap) for i in range(len(selected_st)): name = selected_st.iloc[i]['Station name'] x = selected_st.iloc[i]['Latitude'] y = selected_st.iloc[i]['Longitude'] test = ( '<b>name:{}</b></br> <b>x:{}</b></br> <b>y:{}</b></br>'.format(name, x, y), script=True) popup = (test, max_width=2650) ( location=[x, y], popup=popup, ).add_to(myMap) ("")
Results Showcase
summarize
Above is the entire content of this article, I hope the content of this article for your study or work has a certain reference learning value, thank you for your support. If you want to know more about the content please check the following relevant links