-
Notifications
You must be signed in to change notification settings - Fork 14
Description
import folium
from folium import plugins
import pandas as pd
import plotly.graph_objects as go
from ipywidgets import widgets
from ipywidgets import interact
from functools import partial, update_wrapper
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
#import pandas as pd
from statsmodels.graphics.factorplots import interaction_plot
#import matplotlib.pyplot as plt
import ipywidgets
import os
os.environ.keys()
import json
#from IPython.display import YouTubeVideo
import datetime
the latitude and Longitude coordinates
centretlocation = (55.68146418183893, 12.53407672047615)
map_centret = folium.Map(location = centretlocation, width = "75%", zoom_start = 17) # max zoom: 18
map_centret
shopOutline = r'C:/Users/Bruger/Desktop/Test_1-Project/FrederiskbergCentre/positions/shop1.geojson'
display(folium.GeoJson(shopOutline, name="shop1").add_to(map_centret))
display(map_centret)
testGeoJson = r'C:/Users/Bruger/Desktop/Test_1-Project/FrederiskbergCentre/positions/path/w1.geojson'
def switchPosition(coordinate):
temp = coordinate[0]
coordinate[0] = coordinate[1]
coordinate[1] = temp
return coordinate
with open(testGeoJson) as f:
testWay = json.load(f)
for feature in testWay['features']:
path = feature['geometry']['coordinates']
finalPath = list(map(switchPosition,path))
finalPath
path = 'FrederiskbergCentre/positions/path/w1.geojson'
folium.plugins.AntPath([[55.68128574048729, 12.533844709396362],
[55.68157079259699, 12.533998936414719]]).add_to(map_centret)
map_centret
class navigator:
def init(self):
self.geoResources = {}
self.centretlocation =(55.68128574048729, 12.533844709396362)
self.position = 'w'
self.destination = 'shop1'
for root, dirs, files in os.walk('FrederiskbergCentre/positions'):
for file in files:
self.geoResources[file.split('.')[0]] = root+'/'+file
def changeDestination(self,newDestination):
self.destination = newDestination
self.redrawMap()
def changeStartPoint(self, newStartPoint):
#self.position = newStartPoint #does not work yet
print(f'Selected Start: {newStartPoint}; Selected Target: {self.destination}')
#self.redrawMap()
def drawPathWay(self,centretMap):
def switchPosition(coordinate):
temp = coordinate[0]
coordinate[0] = coordinate[1]
coordinate[1] = temp
return coordinate
searchString = self.position + self.destination.split('shop')[1]
with open(self.geoResources[searchString]) as f:
testWay = json.load(f)
for feature in testWay['features']:
path = feature['geometry']['coordinates']
finalPath = list(map(switchPosition,path))
folium.plugins.AntPath(finalPath).add_to(hospitalMap)
def drawBuilding(self,centretMap):
shopOutline = self.geoResources[self.destination]
folium.GeoJson(shopOutline, name="geojson").add_to(centretMap)
def redrawMap(self):
#print(f'position {self.position}, destination {self.destination}')
centretMap = folium.Map(location = self.centretlocation, width = "75%", zoom_start = 17)
self.drawPathWay(centretMap)
self.drawBuilding(centretMap)
display(centretMap)
myNavigator = navigator()
def displayWay(whereTo):
myNavigator.changeDestination(whereTo)
def changePosition(whereFrom):
myNavigator.changeStartPoint(whereFrom)
Destination Selector
selectshop_widget=ipywidgets.Select(
options=['shop1'],
value='shop1',
description='Target',
disabled=False)
#'shopGD2310',
#'shopGD2010',
#'shopGD2200',
#'shopGD1255'
widget function
def selectshop(way):
if way == 'shop1' :
displayWay('shop1')
#if way == 'shopGD2010':
#displayWay('shopGD2010')
#if way == 'shopGD2200':
#displayWay('shopGD2200')
#if way == 'shopGD1255':
#displayWay('shopGD1255')
Position Selector
selectPosition_widget=ipywidgets.Select(
options=['g-entrance1', 'GDentrance2'],
value='g-entrance1',
description='Start',
disabled=False)
def selectPosition(position):
if position == 'g-entrance1':
changePosition('w')
if position == 'GDentrance2':
changePosition('y')
#if position == 'GDentrance3':
#changePosition('o')
#if position == 'GDentrance4':
#changePosition('f')
#if position == 'GDentrance5':
#changePosition('x')
#Initialization
ipywidgets.interact(selectPosition, position=selectPosition_widget)
ipywidgets.interact(selectshop, way=selectshop_widget)