| #!/usr/bin/env python | |
| # coding: utf-8 | |
| # In[1]: | |
| import streamlit as st | |
| import pandas as pd | |
| import gspread | |
| from math import log | |
| from math import sqrt | |
| import re | |
| import numpy as np | |
| import osmnx as os | |
| from osmnx.geocoder import geocode | |
| from osmnx.distance import euclidean_dist_vec | |
| from osmnx import geocode_to_gdf | |
| import geocoder | |
| import shapely as sh | |
| import datetime | |
| import pickle | |
| import geopandas | |
| from shapely.geometry import Point | |
| from shapely.ops import unary_union | |
| from shapely.ops import transform | |
| import folium | |
| from streamlit_folium import folium_static | |
| import pyproj | |
| def import_data(): | |
| Service = pd.read_excel('Service.xlsx') | |
| Food = pd.read_excel('Restaurants_and_canteens.xlsx') | |
| col2 = np.array(list(map(float, Food['Latitude_WGS84'].values[1:]))) | |
| col1 = np.array(list(map(float, Food['Longitude_WGS84'].values[1:]))) | |
| col2_S = np.array(list(map(float, Service['Latitude_WGS84'].values[1:]))) | |
| col1_S = np.array(list(map(float, Service['Longitude_WGS84'].values[1:]))) | |
| # col_S = np.column_stack([col2_S, col1_S]) | |
| # col = np.column_stack([col2, col1]) | |
| Data1 = geopandas.GeoDataFrame(pd.read_pickle('districts_moc.pickle')).sort_values('name') | |
| Subway = os.geometries_from_place('Moscow', tags = {'railways':'station', 'station':'subway'}) | |
| Highways = os.geometries_from_place('Moscow', tags = {'highway':['motorway','trunk','primary']}) | |
| For = os.geometries_from_place('Moscow', tags = { 'natural':'wood', | |
| 'landuse':'forest'}) | |
| Schools = os.geometries_from_place('Moscow', tags = { 'amenity':'school'}) | |
| Railway = os.geometries_from_place('Moscow', tags = { 'railway':['rail','disused']}) | |
| locations_gpd = geopandas.GeoDataFrame(geometry=geopandas.points_from_xy(col1, col2), | |
| crs='epsg:4326') | |
| Eda = locations_gpd.to_crs("EPSG:25837") | |
| locations_gpd1 = geopandas.GeoDataFrame(geometry=geopandas.points_from_xy(col1_S, col2_S), | |
| crs='epsg:4326') | |
| Uslugi = locations_gpd1.to_crs("EPSG:25837") | |
| locations_gpd_m = geopandas.GeoDataFrame(Subway.geometry, | |
| crs='epsg:4326') | |
| Metro = locations_gpd_m.to_crs("EPSG:25837") | |
| locations_gpd_H = geopandas.GeoDataFrame(Highways.geometry, | |
| crs='epsg:4326') | |
| Shosse = locations_gpd_H.to_crs("EPSG:25837") | |
| Lesa = For.to_crs("EPSG:25837") | |
| locations_gpd_Sc = geopandas.GeoDataFrame(Schools.geometry, | |
| crs='epsg:4326') | |
| Shkoly = locations_gpd_Sc.to_crs("EPSG:25837") | |
| locations_gpd_R = geopandas.GeoDataFrame(Railway.geometry, | |
| crs='epsg:4326') | |
| Zhd = locations_gpd_R.to_crs("EPSG:25837") | |
| # zhk = pd.read_pickle('coordsnovostroy') | |
| # col2_Z = zhk['b'] | |
| # col1_Z = zhk['a'] | |
| zhk = pd.read_pickle('final_part_domrf') | |
| zhk = zhk.reset_index(drop=True) | |
| # ZHK = pd.read_pickle('zhks_w_coords_v2.pickle') | |
| # col2_Z = ZHK['Lat'] | |
| # col1_Z = ZHK['Long'] | |
| A = pd.read_pickle('matrix_coords1') | |
| # A = geopandas.GeoDataFrame(geometry=geopandas.points_from_xy(col1_Z, col2_Z), | |
| # crs='epsg:4326') | |
| return Data1, Eda, Uslugi, Metro, Shosse, Lesa, Shkoly, Zhd, zhk, A | |
| Data1, Eda, Uslugi, Metro, Shosse, Lesa, Shkoly, Zhd, zhk, A = import_data() | |
| st.write(""" | |
| #Простая интерактивная карта v0.2 (Alfa) | |
| """) | |
| st.sidebar.header('User Input Parameters') | |
| def user_input_features(): | |
| serv = st.sidebar.slider('Distance from services (не больше)', 50, 5000, 500) | |
| food = st.sidebar.slider('Distance from food markets (не больше)', 50, 5000, 200) | |
| metro = st.sidebar.slider('Distance from metro (не больше)', 50, 5000, 1000) | |
| highway = st.sidebar.slider('Distance from highway (не меньше)', 50, 5000, 100) | |
| area_forest = st.sidebar.slider('Forest area (не меньше)', 1000, 20000, 1000) | |
| forest = st.sidebar.slider('Distance from forest (не больше)', 50, 5000, 1000) | |
| school = st.sidebar.slider('Distance from schools (не больше)', 50, 5000, 500) | |
| railway = st.sidebar.slider('Distance from railway (не меньше)', 50, 5000, 100) | |
| data = {'serv': serv, | |
| 'food': food, | |
| 'metro': metro, | |
| 'highway': highway, | |
| 'area_forest': area_forest, | |
| 'forest': forest, | |
| 'school': school, | |
| 'railway': railway} | |
| features = pd.DataFrame(data, index=[0]) | |
| return features | |
| df = user_input_features() | |
| st.subheader('User Input parameters') | |
| st.write(df) | |
| # In[17]: | |
| # def PLOT(serv,food,metro,highway,area_forest,forest, school,railway): | |
| # m = folium.Map(location=[55.87890, 37.71943], zoom_start=10, tiles='CartoDB positron') | |
| # locations_gpd = geopandas.GeoDataFrame(Eda.geometry) | |
| # locations_gpd.geometry = locations_gpd.geometry.buffer(serv,resolution=2) | |
| # K = locations_gpd.geometry.unary_union | |
| # locations_gpd1 = geopandas.GeoDataFrame(Uslugi.geometry) | |
| # locations_gpd1.geometry = locations_gpd1.geometry.buffer(food,resolution=2) | |
| # T = locations_gpd1.geometry.unary_union | |
| # locations_gpd_m = geopandas.GeoDataFrame(Metro.geometry) | |
| # locations_gpd_m.geometry = locations_gpd_m.geometry.buffer(metro,resolution=2) | |
| # M = locations_gpd_m.geometry.unary_union | |
| # locations_gpd_H = geopandas.GeoDataFrame(Shosse.geometry) | |
| # locations_gpd_H.geometry = locations_gpd_H.geometry.buffer(highway,resolution=2) | |
| # H = locations_gpd_H.geometry.unary_union | |
| # Forests = geopandas.GeoDataFrame(Lesa.geometry) | |
| # Forests = Forests[Forests.geometry.area > area_forest] | |
| # Forests.geometry = Forests.geometry.buffer(forest,resolution=2) | |
| # F = Forests.geometry.unary_union | |
| # locations_gpd_Sc = geopandas.GeoDataFrame(Shkoly.geometry) | |
| # locations_gpd_Sc.geometry = locations_gpd_Sc.geometry.buffer(school,resolution=2) | |
| # Sc = locations_gpd_Sc.geometry.unary_union | |
| # locations_gpd_R = geopandas.GeoDataFrame(Zhd.geometry) | |
| # locations_gpd_R.geometry = locations_gpd_R.geometry.buffer(railway,resolution=2) | |
| # Ra = locations_gpd_R.geometry.unary_union | |
| # url = "https://cdn-icons-png.flaticon.com/512/746/746859.png{}".format | |
| # beerGlass_img = url("") | |
| # custom_icon = folium.CustomIcon(beerGlass_img, icon_size=(35, 35), popup_anchor=(0, -22)) | |
| # insta_post = 'https://www.instagram.com/p/CjcvNysq8om/' | |
| # website = 'vk.com' | |
| # name = 'bebra' | |
| # directions = 'https://yandex.ru/maps/213/moscow/stops/2057340510/?ll=37.593517%2C55.775694&tab=overview&z=12.32' | |
| # realty_html = folium.Html(f"""<p style="text-align: center;"><span style="font-family: Didot, serif; font-size: 21px;">{name}</span></p> | |
| # <p style="text-align: center;"><iframe src={insta_post}embed width="240" height="290" frameborder="0" scrolling="auto" allowtransparency="true"></iframe> | |
| # <p style="text-align: center;"><a href={website} target="_blank" title="{name} Website"><span style="font-family: Didot, serif; font-size: 17px;">{name} Website</span></a></p> | |
| # <p style="text-align: center;"><a href={directions} target="_blank" title="Directions to {name}"><span style="font-family: Didot, serif; font-size: 17px;">Directions to {name}</span></a></p> | |
| # """, script=True) | |
| # popup = folium.Popup(realty_html, max_width=700) | |
| # custom_marker = folium.Marker(location=[55.87890,37.71943], icon=custom_icon, tooltip=name, popup=popup) | |
| # R = K.intersection(T) | |
| # R = R.intersection(M) | |
| # R= R.difference(H) | |
| # R = R.intersection(F) | |
| # R = R.intersection(Sc) | |
| # R= R.difference(Ra) | |
| # wgs84 = pyproj.CRS('EPSG:25837') | |
| # utm = pyproj.CRS('EPSG:4326') | |
| # project = pyproj.Transformer.from_crs(wgs84, utm, always_xy=True).transform | |
| # utm_point = transform(project, R) | |
| # R = folium.GeoJson(data=utm_point, style_function=lambda x: {'fillColor': 'orange'}) | |
| # b = folium.GeoJson(data=M, style_function=lambda x: {'fillColor': '#00000000', 'color': '#00000000'}) | |
| # AH = folium.GeoJson(data=(Data1), style_function=lambda x: {'fillColor': '#00000000', 'color': 'black'}) | |
| # fg1 = folium.map.FeatureGroup(name='Metro').add_to(m) | |
| # fg2 = folium.map.FeatureGroup(name='Plot').add_to(m) | |
| # fg3 = folium.map.FeatureGroup(name='Districts').add_to(m) | |
| # fg4 = folium.map.FeatureGroup(name='rightzhk').add_to(m) | |
| # fg5 = folium.map.FeatureGroup(name='badzhk').add_to(m) | |
| # R.add_child(folium.Popup('Plot')) | |
| # b.add_child(folium.Popup('Метро')) | |
| # AH.add_child(folium.Popup('Районы')) | |
| # custom_marker.add_to(fg2) | |
| # fg1.add_child(b) | |
| # fg2.add_child(R) | |
| # fg3.add_child(AH) | |
| # G = np.array(A.intersects(utm_point)) | |
| # zhk['G']=G | |
| # zhk_1 = zhk.query('G == True').copy() | |
| # zhk_2 = zhk.query('G == False').copy() | |
| # del(zhk['G']) | |
| # for i,row in zhk_1.iterrows(): | |
| # iframe = folium.IFrame('ЖК:' + str(row[2])) | |
| # popup = folium.Popup(iframe, min_width=100, max_width=100) | |
| # Z=folium.Marker(location=[row[1],row[0]], | |
| # popup = popup, icon=folium.Icon(color='red', icon='')) | |
| # fg4.add_child(Z) | |
| # for i,row in zhk_2.iterrows(): | |
| # iframe = folium.IFrame('ЖК:' + str(row[2])) | |
| # popup = folium.Popup(iframe, min_width=100, max_width=100) | |
| # Z=folium.Marker(location=[row[1],row[0]], | |
| # popup = popup, icon=folium.Icon(color='gray', icon='')) | |
| # fg4.add_child(Z) | |
| # del(zhk_1) | |
| # del(zhk_2) | |
| # folium.LayerControl().add_to(m) | |
| # folium_static(m) | |
| # In[ ]: | |
| st.subheader('Интерактивная карта') | |
| # PLOT(df['serv'][0],df['food'][0],df['metro'][0],df['highway'][0],df['area_forest'][0],df['forest'][0],df['school'][0],df['railway'][0]) | |
| m = folium.Map(location=[55.87890, 37.71943], zoom_start=10, tiles='CartoDB positron') | |
| # locations_gpd = geopandas.GeoDataFrame(Eda.geometry) | |
| # locations_gpd.geometry = locations_gpd.geometry.buffer(df['serv'][0],resolution=2) | |
| # K = locations_gpd.geometry.unary_union | |
| # locations_gpd1 = geopandas.GeoDataFrame(Uslugi.geometry) | |
| # locations_gpd1.geometry = locations_gpd1.geometry.buffer(df['food'][0],resolution=2) | |
| # T = locations_gpd1.geometry.unary_union | |
| # locations_gpd_m = geopandas.GeoDataFrame(Metro.geometry) | |
| # locations_gpd_m.geometry = locations_gpd_m.geometry.buffer(df['metro'][0],resolution=2) | |
| # M = locations_gpd_m.geometry.unary_union | |
| # locations_gpd_H = geopandas.GeoDataFrame(Shosse.geometry) | |
| # locations_gpd_H.geometry = locations_gpd_H.geometry.buffer(df['highway'][0],resolution=2) | |
| # H = locations_gpd_H.geometry.unary_union | |
| # Forests = geopandas.GeoDataFrame(Lesa.geometry) | |
| # Forests = Forests[Forests.geometry.area > df['area_forest'][0]] | |
| # Forests.geometry = Forests.geometry.buffer(df['forest'][0],resolution=2) | |
| # F = Forests.geometry.unary_union | |
| # locations_gpd_Sc = geopandas.GeoDataFrame(Shkoly.geometry) | |
| # locations_gpd_Sc.geometry = locations_gpd_Sc.geometry.buffer(df['school'][0],resolution=2) | |
| # Sc = locations_gpd_Sc.geometry.unary_union | |
| # locations_gpd_R = geopandas.GeoDataFrame(Zhd.geometry) | |
| # locations_gpd_R.geometry = locations_gpd_R.geometry.buffer(df['railway'][0],resolution=2) | |
| # Ra = locations_gpd_R.geometry.unary_union | |
| # url = "https://cdn-icons-png.flaticon.com/512/746/746859.png{}".format | |
| # beerGlass_img = url("") | |
| # custom_icon = folium.CustomIcon(beerGlass_img, icon_size=(35, 35), popup_anchor=(0, -22)) | |
| # insta_post = 'https://www.instagram.com/p/CjcvNysq8om/' | |
| # website = 'vk.com' | |
| # name = 'bebra' | |
| # directions = 'https://yandex.ru/maps/213/moscow/stops/2057340510/?ll=37.593517%2C55.775694&tab=overview&z=12.32' | |
| # realty_html = folium.Html(f"""<p style="text-align: center;"><span style="font-family: Didot, serif; font-size: 21px;">{name}</span></p> | |
| # <p style="text-align: center;"><iframe src={insta_post}embed width="240" height="290" frameborder="0" scrolling="auto" allowtransparency="true"></iframe> | |
| # <p style="text-align: center;"><a href={website} target="_blank" title="{name} Website"><span style="font-family: Didot, serif; font-size: 17px;">{name} Website</span></a></p> | |
| # <p style="text-align: center;"><a href={directions} target="_blank" title="Directions to {name}"><span style="font-family: Didot, serif; font-size: 17px;">Directions to {name}</span></a></p> | |
| # # """, script=True) | |
| # popup = folium.Popup(realty_html, max_width=700) | |
| # custom_marker = folium.Marker(location=[55.87890,37.71943], icon=custom_icon, tooltip=name, popup=popup) | |
| # R = K.intersection(T) | |
| # R = R.intersection(M) | |
| # R= R.difference(H) | |
| # R = R.intersection(F) | |
| # R = R.intersection(Sc) | |
| # R= R.difference(Ra) | |
| # wgs84 = pyproj.CRS('EPSG:25837') | |
| # utm = pyproj.CRS('EPSG:4326') | |
| # project = pyproj.Transformer.from_crs(wgs84, utm, always_xy=True).transform | |
| # utm_point = transform(project, R) | |
| # R = folium.GeoJson(data=utm_point, style_function=lambda x: {'fillColor': 'orange'}) | |
| # b = folium.GeoJson(data=M, style_function=lambda x: {'fillColor': '#00000000', 'color': '#00000000'}) | |
| # AH = folium.GeoJson(data=(Data1), style_function=lambda x: {'fillColor': '#00000000', 'color': 'black'}) | |
| # fg1 = folium.map.FeatureGroup(name='Metro').add_to(m) | |
| # fg2 = folium.map.FeatureGroup(name='Plot').add_to(m) | |
| # fg3 = folium.map.FeatureGroup(name='Districts').add_to(m) | |
| fg4 = folium.map.FeatureGroup(name='rightzhk').add_to(m) | |
| # fg5 = folium.map.FeatureGroup(name='badzhk').add_to(m) | |
| # R.add_child(folium.Popup('Plot')) | |
| # b.add_child(folium.Popup('Метро')) | |
| # AH.add_child(folium.Popup('Районы')) | |
| # custom_marker.add_to(fg2) | |
| # fg1.add_child(b) | |
| # fg2.add_child(R) | |
| # fg3.add_child(AH) | |
| MATRIX = A | |
| MATRIX = MATRIX.loc[(MATRIX.Food<df['food'][0])& (MATRIX.Service<df['serv'][0])&(MATRIX.Metro<df['metro'][0])& (MATRIX.Forest<df['forest'][0])& (MATRIX.Schools<df['school'][0])& (MATRIX.Railway>df['railway'][0])& (MATRIX.Highway>df['highway'][0])] | |
| for i,row in MATRIX.iterrows(): | |
| iframe = folium.IFrame('ЖК:' + str(row[3])) | |
| popup = folium.Popup(iframe, min_width=100, max_width=100) | |
| Z=folium.Marker(location=[row[11],row[12]], | |
| popup = popup, icon=folium.Icon(color='red', icon='')) | |
| fg4.add_child(Z) | |
| # G = np.array(A.intersects(utm_point)) | |
| # for i,row in zhk.iterrows(): | |
| # iframe = folium.IFrame('ЖК:' + str(row[3])) | |
| # popup = folium.Popup(iframe, min_width=100, max_width=100) | |
| # # if (G[i]): | |
| # Z=folium.Marker(location=[row[11],row[12]], | |
| # popup = popup, icon=folium.Icon(color='red', icon='')) | |
| # fg4.add_child(Z) | |
| # # else: | |
| # # Z=folium.Marker(location=[row[11],row[12]], | |
| # # popup = popup, icon=folium.Icon(color='gray', icon='')) | |
| # # fg5.add_child(Z) | |
| # folium.LayerControl().add_to(m) | |
| folium_static(m) | |