File size: 14,975 Bytes
f173585 999f99a f173585 0b35952 f173585 1a35a48 f173585 1a35a48 f173585 ad169c2 3f31f39 f173585 ad169c2 1a35a48 c71f31b f44a7e7 1a35a48 f44a7e7 1a35a48 f173585 | 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 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | #!/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
@st.cache
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)
|