Skip to content

Instantly share code, notes, and snippets.

@khun84
Created March 18, 2019 01:55
Show Gist options
  • Save khun84/793bb44a950f767d072d02f82ebdf8fb to your computer and use it in GitHub Desktop.
Save khun84/793bb44a950f767d072d02f82ebdf8fb to your computer and use it in GitHub Desktop.
service_area_map_exploration
import pandas as pd
import folium
# edit this section to project the polygon that you want
pj_geojson = {"type":"Polygon","coordinates":[[[101.6637271,3.070996],[101.6637271,3.204971],[101.5526301,3.204971],[101.5526301,3.070996],[101.6637271,3.070996]]]}
subang_jaya = {"type":"Polygon","coordinates":[[[101.6210431,3.085025],[101.6210431,2.975538],[101.5493918,2.975538],[101.5493918,3.085025],[101.6210431,3.085025]]]}
langat = {"type":"Polygon","coordinates":[[[101.6828061,2.643176],[101.6828061,2.9793898],[101.2863841,2.9793898],[101.2863841,2.643176],[101.6828061,2.643176]]]}
boundary = pj_geojson['coordinates'][0]
boundary2 = subang_jaya['coordinates'][0]
langat = langat['coordinates'][0]
boundary = list(map(lambda x: [x[1], x[0]], boundary))
boundary2 = list(map(lambda x: [x[1], x[0]], boundary2))
langat = list(map(lambda x: [x[1], x[0]], langat))
location = [2.7407400895560183, 101.36083960533142]
# initialize the map object with viewport center set to location
m = folium.Map(location=location)
# project a marker for the location
folium.Marker(
location=location,
popup=','.join(map(lambda x: str(x), location)),
icon=folium.Icon(icon='cloud')
).add_to(m)
# project polygon for service areas/groups
folium.Polygon(boundary, fill=True, opacity=0.6).add_to(m)
folium.Polygon(boundary2, fill=True, opacity=0.6).add_to(m)
folium.Polygon(langat, fill=True, opacity=0.6).add_to(m)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment