Skip to content

Instantly share code, notes, and snippets.

@thanasi
Last active April 2, 2017 14:13
Show Gist options
  • Save thanasi/1d82060894c7961b296b69fe06cc7822 to your computer and use it in GitHub Desktop.
Save thanasi/1d82060894c7961b296b69fe06cc7822 to your computer and use it in GitHub Desktop.
Basic Map Neighborhoods geopandas
import pandas as pd
import geopandas as gpd
import numpy as np
from geopandas.tools import sjoin
import folium
from folium.plugins import MarkerCluster
from folium import IFrame
import shapely
from shapely.geometry import Point
import unicodedata
import pysal as ps
# define the input shapefile
cambridge_shapefile = 'BOUNDARY_CDDNeighborhoods.shp'
# read the neighborhoods
neighborhoods = gpd.read_file(cambridge_shapefile)
# construct the folium map object on Cambridge
cambridge_map = folium.Map([42.3736158, -71.1097335], zoom_start = 13)
# convert the neighborhood data to the right coordinates via to_crs()
# then convert the output to a json string via to_json()
geo_str = neighborhoods.to_crs({'init': 'epsg:4326'}).to_json()
# add the neighborhoods as a layer to the map
cambridge_map.choropleth(geo_str=geo_str)
# display the map (if in a jupyter notebook)
cambridge_map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment