import geopandas as gp import folium from shapely.geometry import Point from geopy.geocoders import GoogleV3 from IPython.display import HTML # help(folium.Map) geolocator=GoogleV3() place,(latitude,longitude)=geolocator.geocode('Washington DC') print place, latitude, longitude #Function that shows the map def showmap(map_in,pth): map_in.create_map(path=pth) return HTML('') #Function that resets the map def resetmap(): return folium.Map(location=[40, -99], zoom_start=4) dcmap=folium.Map(location=[latitude,longitude],tiles='Stamen Toner') dcmap.create_map(path='index.html') showmap(dcmap,'index.html') #Establish working directory workdir='/home/choct155/ORA/misc/' #Read in camera shp camera=gp.GeoDataFrame.from_file(workdir+'TrafficCamera.shp') print camera camera.head() camera_ll=camera.to_crs(crs={'proj':'longlat', 'datum':'WGS84'}).rename(columns={'geometry':'geo_temp'}) camera_ll.head() #Swap lat-long coords in Point objects camera_ll['geometry']=[Point(x.y,x.x) for x in camera_ll['geo_temp'].values] #Keep relevant columns camera_ll2=camera_ll[['CAMERAID','CAMERATYPE','FACILITYID','OWNER','POLEID','STREETJUNC','STREETSEGI','geometry']] camera_ll2.head() #Open file for writing f=open(workdir+'camera_ll2.json','w') #Write the GeoJSON info to disk f.write(camera_ll2.to_json()) #Close file f.close() dcmap.geo_json(geo_path=workdir+'camera_ll2.json') showmap(dcmap,'index.html') # dcmap.simple_marker(location=[38.8733401431466348,-76.9702918311025286],popup='Aesthetic Test - Camera 333') # showmap(dcmap,'dcmap.html') dcmap.polygon_marker(location=[38.8733401431466348,-76.9702918311025286],popup='Test - Camera #333', fill_color='#B80000',num_sides=4,radius=6) showmap(dcmap,'index.html') print camera_ll2['geometry'].values[0].x print camera_ll2['geometry'].values[0].y print camera_ll2['CAMERAID'].values[0] #For every camera in the GDF... for i in range(len(camera_ll2['geometry'])): #...extract the coordinates... lat=camera_ll2['geometry'].values[i].x lon=camera_ll2['geometry'].values[i].y #...and the pop up text... text=str(camera_ll2['CAMERAID'].values[i]) #...and create a marker dcmap.polygon_marker(location=[lat,lon],popup=text, fill_color='#B80000',num_sides=4,radius=6) showmap(dcmap,'index.html')